How to list all the files in a tree (a directory and its subdirs)?

Solution 1:

tree will be very convenient for you.

sudo apt-get install tree

using tree filepathto list the files.

Solution 2:

ls -alR

That's probably the simplest method. I'm just hacking out a find script to give you a touch more control.

Solution 3:

find /path/ -printf "%TY-%Tm-%Td\t%s\t%p\n"

You can play with the printf formatting as much as you like. This gives you a great opportunity to get things formatted the way you need them, which is invaluable if you're using the output in another application.

More: http://linux.about.com/od/commands/l/blcmdl1_find.htm

For better readability, you can pipe it all through the column command and it will automagically resize things so they line up.

find /path/ -printf "%TY-%Tm-%Td\t%s\t%p\n" | column -t

Solution 4:

As Oli answered, find will allow you to search an entire directory tree:

find /path/ -printf "%TY-%Tm-%Td\t%s\t%p\n"

# Where %TY will display the mod. time year as 4 digits
#       %Tm will display the mod. time month as 2 digits
#       %Td will display the mod. time day as 2 digits
#       %s displays the file size in bytes
#       %p displays the full path name of the file

You may also want to use the -type f option to limit the results to just files. If you want to match a file pattern, you want the -name or -iname options (case sensitive, and case insensitive matching, respectively). Take a read through find's man page - there are a substantial amount of options that you can use to narrow/refine your search.

And just as an aside, if you are expecting to have multiple screenfuls of data get thrown back at you, remember to pipe your results through less.

@Oli : +1 I just learned something new as well - column. Hadn't used that before.