Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there anyway I can list files by typing a command in the shell which lists all the file names, folder names and their permissions in CentOS?

share|improve this question
    
Hi, thanks for the reply. Yes for example, if I have the following structure: Folder A > File 1, File 2, Folder AA [File AA1, File AA2] etc, so I wish to list all folders and all files inside these folders along with their permissions in a text file. I hope that makes sense? –  user1038814 May 30 '12 at 21:38

3 Answers 3

up vote 6 down vote accepted

Have a look at tree, you may have to install it first. Per default tree does not show permissions, to show permissions next to the filename run

tree -p

which will recursively list all folders and directories within the current directory including permissions.

share|improve this answer
    
Thanks so much! It worked just how I wanted it. –  user1038814 May 30 '12 at 21:58

You want find for this.

find some/dir -ls > output.txt
share|improve this answer

ls -lR lists the contents of directories recursively. The output is hard to process automatically, but for manual browsing it may be good because it's what you're familiar with.

The find command lists files recursively. You can customize its output, for example the following command prints permissions like ls -l does before each file name:

find -printf '%M %p\n'

This output can be processed mechanically if there are no newlines in your file names. If you replace \n (newline) by \000 (null byte), you can process the output with tools that support null-separated records.

Both ls and find only print traditional unix permissions, not access control lists. For a recursive listing of all file permissions including ACL information, run

getfacl -R .

The output can be processed mechanically (special characters are sorted); in particular, it can be fed to setfacl --restore to replicate the permissions to another tree with the same file names.

share|improve this answer

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.