How to list all files-content in a directory?

something like ls -la | cat.


Use the following command, recursive :

find /path/to/folder -type f -exec cat {} \;

Non-recursive version (due to popular pression) :

find /path/to/folder -maxdepth 1 -type f -exec cat {} \;

  • 1
    This would recurse into subdirectories too, be careful. – John T Feb 13 '10 at 23:59
  • 1
    Both version are now on ! – Studer Feb 14 '10 at 0:27

The following command:

find ./ -type f -exec cat {} \;

would find only files (-type f) from the current folder (./).

Studer's answer is good, and excluding directories is a good idea because it is an undefined behavior between unices, read grawity's comment. Here are two known behaviors :

  • cat on Linux will throw an error message when trying to cat a directory cat: ./folder: Is a directory).
  • cat on FreeBSD will dump the raw directory, as stored on-disk.

If you need more information about the command or something more about it, please reply and I will annotate more/help you.

Edit: As John T pointed out, this command will go into every sub-directories. If you need only to cat files from the current directory, you would need -maxdepth 1, thus giving:

find ./ -maxdepth 1 -type f -exec cat {} \;

The -maxdepth n option can also be used to limit it to an n amount of sub-directories, 1 being the current directory, 2 being the current directory and its direct descendants, and so on.

  • 1
    edit just for you ;) – Studer Feb 13 '10 at 18:50
  • 1
    In Linux, cat would throw an error message. In FreeBSD, for example, it would type the raw directory as it is stored on disk. (Not very useful.) – grawity Feb 13 '10 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.