Abdel
Abdel

Reputation: 6106

ls: how to display directory + filename on each line

I have a directory with a lot of subdirectories, and I want to list all its files with a certain extension on each line, including the (sub)directory they're in. I'm now using:

ls /home/directory -R | grep ".ext" > files.txt

That does not give me the output I'm looking for... Ideally I would like an output that looks something like this:

/home/directory/subdirectory1/file1.ext               4.3Mb
/home/directory/subdirectory1/subsubdir1/file2.ext    3.3Mb
/home/directory/subdirectory2/file3.ext               4.6Mb
/home/directory/subdirectory3/file4.ext               5.2Mb
... etc

Or even better, with the directories and the filenames in separate columns:

/home/directory/subdirectory1/               file1.ext    4.3Mb
/home/directory/subdirectory1/subsubdir1/    file2.ext    3.3Mb
/home/directory/subdirectory2/               file3.ext    4.6Mb
/home/directory/subdirectory3/               file4.ext    5.2Mb
... etc

Any ideas on how to do this? Many thanks!

Upvotes: 2

Views: 659

Answers (1)

MattH
MattH

Reputation: 38247

find putty -type f -name '*.c' -printf "%h\t%f\t%s\n" | column -t

Will produce something like this

putty          sshzlib.c   38615
putty          notiming.c  584
putty/charset  macenc.c    7129
putty/charset  sbcs.c      1190

If you want the entire path, present your directory argument to find as an absolute directory path from root.

Upvotes: 6

Related Questions