Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recursively list all files and directories

Tags:

linux

shell

Using the tcsh shell on Free BSD, is there a way to recursively list all files and directories including the owner, group and relative path to the file?

ls -alR comes close, but it does not show the relative path in front of every file, it shows the path at the top of a grouping i.e.

owner% ls -alR total 0 drwxr-xr-x   3 owner  group  102 Feb  1 10:50 . drwx------+ 27 owner  group  918 Feb  1 10:49 .. drwxr-xr-x   5 owner  group  170 Feb  1 10:50 subfolder  ./subfolder: total 16 drwxr-xr-x  5 owner  group   170 Feb  1 10:50 . drwxr-xr-x  3 owner  group   102 Feb  1 10:50 .. -rw-r--r--  1 owner  group     0 Feb  1 10:50 file1 -rw-r--r--  1 owner  group     0 Feb  1 10:50 file2 

What I would like is output like:

owner group ./relative/path/to/file 

The accepted answer to this question shows the relative path to a file, but does not show the owner and group.

like image 663
Ben Avatar asked Feb 01 '09 18:02

Ben


People also ask

How do I list all directories and subdirectories?

By default, ls lists just one directory. If you name one or more directories on the command line, ls will list each one. The -R (uppercase R) option lists all subdirectories, recursively.

How do I recursively list files in Windows?

For example, when listing files in a Windows command prompt, you can use the dir /s command to recursively list all files in the current directory and any subdirectories.

How do I grep all files in a directory recursively?

Recursive Search To recursively search for a pattern, invoke grep with the -r option (or --recursive ). When this option is used grep will search through all files in the specified directory, skipping the symlinks that are encountered recursively.


2 Answers

How about this:

find . -exec ls -dl \{\} \; | awk '{print $3, $4, $9}' 
like image 135
James Brady Avatar answered Sep 25 '22 00:09

James Brady


Use tree. Few linux distributions install it by default (in these dark days of only GUIs :-), but it's always available in the standard repositories. It should be available for *BSD also, see http://mama.indstate.edu/users/ice/tree/

Use:

tree -p -u -g -f -i 

or

tree -p -u -g -f 

or check the man page for many other useful arguments.

like image 45
Davide Avatar answered Sep 22 '22 00:09

Davide