To get that information for a single file or directory on Linux, you may use the stat
utility with a custom output format:
$ stat -c '%A %U %G %n' ~/.bashrc
-rw-r--r-- myself myself /home/myself/.bashrc
Would you want tab-delimited output, use $'%A\t%U\t%G\t%n'
as the argument to the -c
option (in shells that understand $'...'
as a C-string).
To get the information for everything in the current directory and below, recursively, use find
:
find . -exec stat -c $'%A\t%U\t%G\t%n' {} +
On BSD systems (any of the free ones, and macOS), you will want to use stat -f '%Sp %Su %Sg %N'
instead (each S
indicates "symbolic" output rather than numeric). There, you may also use %t
to insert tabs:
find . -exec stat -f '%Sp%t%Su%t%Sg%t%N' {} +
Example run on macOS:
$ tree
.
├── dir1
│ └── file
└── dir2
└── othername
3 directories, 2 files
$ find . -exec stat -f '%Sp%t%Su%t%Sg%t%N' {} +
drwxr-xr-x myself staff .
drwxr-xr-x myself staff ./dir2
-rw-r--r-- myself staff ./dir2/othername
drwxr-xr-x myself staff ./dir1
-rw-r--r-- myself staff ./dir1/file
diff
's-r
option to do a recursive comparison of files in both directories - e.g.diff -u -r /path/to/dir1 /path/to/dir2
. This will show files/subdirs that only exist in one of the two directories, as well as the differences between files with the same name, if any. – cas Mar 03 '23 at 13:38