What is the ls option to print out only the author of a file's name?

sysadmin
shell

#1

I have this question where it asks

“What is the ls option that prints the author of a file?”

I have tried ls -l “filename”, and ls --author doesn’t work.

thanks!


#2

the --author option at least on linux only prints the owner of the file twice

$ touch file
$ ls -l file
-rw-rw-rw- 1 alex alex 0 Feb  3 10:13 file
$ ls -l --author file
-rw-rw-rw- 1 alex alex alex 0 Feb  3 10:13 file
$ sudo chown root file
$ ls -l file
-rw-rw-rw- 1 root alex 0 Feb  3 10:13 file
$ ls -l --author file
-rw-rw-rw- 1 root alex root 0 Feb  3 10:13 file

extract only the owner of the file , from long listing

$ ls -l file | awk '{ print $3}'
root

#3

What you are looking for is who owns the file i.e UID and GID. If that is you want try:

$ ls -l /etc/passwd | awk '{ print "Owner: " $3 ", Group: " $4 }'

Another option is stat command:

$ stat /etc/passwd
  File: /etc/passwd
  Size: 2792      	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 15475308    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-02-02 23:45:01.903222846 +0530
Modify: 2018-01-21 23:43:20.435701024 +0530
Change: 2018-01-21 23:43:20.439700934 +0530
 Birth: -

Look for UID and GID field.