Is there a way to get just the file's owner and group, separated by space in unix shell?
I'm trying to write a script to find the owner of all the files in a directory and print it (in a specific format, can't use ls -la
).
User: A user is the one who created the file. By default, whosoever, creates the file becomes the owner of the file. A user can create, delete, or modify the file. Group: A group can contain multiple users.
Run ls with the -l flag to show the owner and group-owner of files and directories in the current directory (or in a specific named directory).
To see the Author property for a document or workbook, click File > Info, and then look for Author under Related People on the right.
ls -l | awk '{print $3, $4 }'
That'll do it
Use the stat
command, if available on your version of UNIX:
$ stat -c "%U %G" /etc/passwd
root root
or, to do this operation for all files in a directory and print the name of each file too:
$ stat -c "%n %U %G" *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With