up vote 1 down vote favorite
share [g+] share [fb]

How to list all files-content in a directory?

something like ls -la | cat.

link|improve this question

62% accept rate
feedback

2 Answers

up vote 3 down vote accepted

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 {} \;

link|improve this answer
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
feedback

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.

link|improve this answer
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
Thanks Studer, thanks grawity and thanks John T. – samueldr Feb 14 '10 at 0:12
feedback

Your Answer

 
or
required, but never shown

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