For a task of mine I need to list all the files in a tree (a directory, all its subdirs, all subdirs of those, etc.).
I'd prefer to see them in Nautilus or Krusader, but a command-line solution is interesting as well (in this case I will need files full names, sizes and modification times to be listed).
tree will be very convenient for you.
using
tree filepath
to list the files.That's probably the simplest method. I'm just hacking out a find script to give you a touch more control.
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.As Oli answered,
find
will allow you to search an entire directory tree: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 throughfind
'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.ls
is the standard command to list files in Ubuntu and other Linux and Unix operating systems.ls
is particularly useful to learn because you will find it installed on every Unix system you ever meet. By default running this displays only the files in the current directory.However the
-R
'flag' is the recursive option (note the capital R, not r) which will show you all the sub-directories as well.You asked for "details" too - for this you want the
-l
flag (that's a lowercase L, not the number one). Be aware this gives you file permissions information as well as file size, time/date info and file name.If you want to also show hidden files/folders (the equivalent of Ctrl+H in Nautilus) then add the
-a
'all' flag.You can merge flags together, to give you something like:
If you run this on any decent sized folder you will find this produces a huge long output that scrolls down your screen very fast. To get around this, you can 'pipe' the output of
ls
through a program calledless
(the name is a parody of the similarmore
which was around first but has more features).This will allow you to use the up/down arrow keys, alongside PageUp/Down to go through the output at a more comfortable speed.
Using Krusader:
This will allow you to process the whole lot by dragging to the other panel, etc.
How about a Nautilus script?
Installation instructions: How can I install a Nautilus script?
I have created a program specially for this - Directory Snapshot.
It recursively iterates through a directory and stores the names and sizes of all the files and folders it encounters in neatly-structured HTML files, which have an organization similar to that of the input directory.
In other words, this can be thought of as a hyperlinked version of the
dir /s
ortree /f
commands.Nautilus
This also works in Nemo.
you can put these in your .bashrc file
Now, you can use get_tree command inside any directory and it will display the entire hierarchy.
Syntax:
Sample Output:
Hope, This Helps !!