I am trying to list files with their location (directory), the owner/user of the file and the size of the file in a list format that I could easily filter as I'm using it for monitoring space on one of our servers.
So far the closest I've been able to get is this:
ls -shlR >filelist.txt
But this lists the directory at the top of every group of files rather than alongside the file, making it hard to do standardized reporting off of. Ideally what I would have in the end is something with all the data in 4 columns (user, file name, directory location, and size of file). Is there any way to do what I'm trying here?
Edit: I realized after the first answer I forgot to include a piece, that I would like this to work for the directory and all sub directories.
CodePudding user response:
Use find
:
find /path/to/directory -type f -printf '%u\t%f\t%h\t%s\n'
Columns are separated by tab characters.