14

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?

don_crissti
85.6k31 gold badges233 silver badges262 bronze badges
asked May 30, 2012 at 21:12
1
  • 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? Commented May 30, 2012 at 21:38

5 Answers 5

14

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.

answered May 30, 2012 at 21:48
0
12

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.

answered May 30, 2012 at 23:54
5

You want find for this.

find some/dir -ls > output.txt

From the find man page:

-ls

    True; list current file in ls -dils format on standard output.

From the ls man page:

-l

    use a long listing format

answered May 30, 2012 at 21:46
0

The stat command executed by the find command will give you permissions and a whole lot more:

$ find . -exec stat {} +
 File: '.'
 Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 10306h/66310d Inode: 1326677 Links: 3
Access: (0775/drwxrwxr-x) Uid: ( 1000/ rick) Gid: ( 1000/ rick)
Access: 2020年06月24日 17:00:52.131209006 -0600
Modify: 2020年06月13日 09:21:40.489850096 -0600
Change: 2020年06月13日 09:21:40.489850096 -0600
 Birth: -
 File: './.eyesome-sunset'
 Size: 8 Blocks: 8 IO Block: 4096 regular file
Device: 10306h/66310d Inode: 1323438 Links: 1
Access: (0666/-rw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020年06月23日 04:32:44.808321580 -0600
Modify: 2020年06月02日 16:37:33.282346160 -0600
Change: 2020年06月02日 16:37:33.282346160 -0600
 Birth: -
answered Jun 24, 2020 at 23:48
-1

ls is a command to list computer files in Unix

ls -l list items in directory
ls -R recursively list file

ls -lR
jesse_b
41.5k14 gold badges108 silver badges161 bronze badges
answered Nov 14, 2019 at 16:01
1
  • This was in Gilles answer. Also your explanation of ls -l doesn't explain what the -l is at all. Commented Nov 14, 2019 at 16:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.