Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know that using "ls -R ." in bash you can recursively list the filenames.

Can I use some similar command to list the contents of each file just the way their names are displayed using the ls command. I mean to a single file or stream like the standard output.

Is there a way I can format the output from such a command? Like say, add something like a few blank lines between the contents of each of the files for better readbility?

share|improve this question
add comment

2 Answers 2

Create a meta-script with find and pipe it to sh.

$ find /home/jaroslav/tmp/su/  2>/dev/null \
    -printf 'echo -e \\\\n\\\\n%p\ncat "%p"\n' |sh

out:

/home/jaroslav/tmp/su/
cat: /home/jaroslav/tmp/su/: Is a directory


/home/jaroslav/tmp/su/diff.tar.gz
J▒▒P▒▒M
6▒M)FR▒▒▒▒▒▒F2▒/9▒e▒▒s]▒N▒h▒▒ޫzr▒▒hD▒▒Z&▒▒X▒▒|*▒o▒▒z▒▒▒▒|x߁▒▒E▒▒▒4▒▒Kऺ▒▒J▒-▒B▒▒▒Z▒▒▒?▒▒▒▒▒
        ▒▒P▒▒鿶▒▒JF▒j▒=Z▒?%▒▒▒▒▒▒▒▒▒▒▒{▒▒▒M▒▒▒▒$▒▒q(

/home/jaroslav/tmp/su/while
while read line; do
    login=$(echo $line | cut -d : -f 1)
        echo $login
done < /etc/passwd
share|improve this answer
add comment
find . -type f | while read file;
do
  # Here you can do whatever you like
  # Like output a few empty lines
  echo
  echo

  # output filename
  echo $file      
  # this prints the contents of the file to STD OUT
  cat $file;

done > targetfile
share|improve this answer
    
But how do you get everything into a single file? When I tried this, it would go into an endless loop, cating the same files all over again. –  slhck Aug 6 '12 at 13:12
    
@slhck - looping? I dont see how –  Nifle Aug 6 '12 at 13:15
    
How do I use this: find . -type f -exec cat {} \; to put it into a single file? –  Arpith Aug 6 '12 at 13:24
    
@Arpith - find . -type f -exec cat {} \; > /path/to/your/outputfile –  Nifle Aug 6 '12 at 13:27
    
@Nifle: I think the command is listing the same files' contents recursively rather than going in depth through the filesystem heirarchy and listing the contents of various files. –  Arpith Aug 6 '12 at 13:34
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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