I want a script to determine the owner of a particular file and then "sudo -u <thatuserid> <somecomand>". I ran across the --author option of ls but that does not seem to give me anything useful. It prints a short form of the filename without any other information at all. In fact, the output of ls --author is indistinguishable from that of ls by itself:
# ls --author htdocs/* htdocs/hlllogo.png # ls htdocs/* htdocs/hlllogo.png #
Is there a linux command that will return just the userid in a form that can be passed to sudo or do I have to parse ls -l <filename>?
I am digest subscriber so, if you could provide one, the favour of a direct copy of your reply is requested.
Regards, Jim
-- *** e-mail is not a secure channel *** mailto:byrnejb.<token>@harte-lyne.ca James B. Byrne Harte & Lyne Limited vox: +1 905 561 1241 9 Brockley Drive fax: +1 905 561 0757 Hamilton, Ontario <token> = hal Canada L8E 3C3
James B. Byrne wrote:
I want a script to determine the owner of a particular file and then "sudo -u <thatuserid> <somecomand>". I ran across the --author option of ls but that does not seem to give me anything useful. It prints a short form of the filename without any other information at all. In fact, the output of ls --author is indistinguishable from that of ls by itself:
# ls --author htdocs/* htdocs/hlllogo.png # ls htdocs/* htdocs/hlllogo.png #
Is there a linux command that will return just the userid in a form that can be passed to sudo or do I have to parse ls -l <filename>?
I am digest subscriber so, if you could provide one, the favour of a direct copy of your reply is requested.
Regards, Jim
-- *** e-mail is not a secure channel *** mailto:byrnejb.<token>@harte-lyne.ca James B. Byrne Harte & Lyne Limited vox: +1 905 561 1241 9 Brockley Drive fax: +1 905 561 0757 Hamilton, Ontario <token> = hal Canada L8E 3C3
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
ls -l <filename> | awk '{print $3}' will give you the owner of the file.
On Mon, 20 Mar 2006, James B. Byrne wrote:
I want a script to determine the owner of a particular file and then "sudo -u <thatuserid> <somecomand>". I ran across the --author option of ls but that does not seem to give me anything useful. It prints a short form of the filename without any other information at all. In fact, the output of ls --author is indistinguishable from that of ls by itself:
# ls --author htdocs/* htdocs/hlllogo.png # ls htdocs/* htdocs/hlllogo.png #
Is there a linux command that will return just the userid in a form that can be passed to sudo or do I have to parse ls -l <filename>?
stat -c %U filename
The stat(1) man page has format details; it's part of the coreutils rpm.
On 3/20/06, James B. Byrne ByrneJB@harte-lyne.ca wrote:
I ran across the --author option of ls but that does not seem to give me anything useful. [...] In fact, the output of ls --author is indistinguishable from that of ls by itself:
The linux manual pages for "ls" and other GNU coreutils are sometimes deficient. If I were the paranoid type, I'd say it was retaliation for not always calling it "GNU/Linux".
--author List each file's author when producing long format directory listings. In GNU/Hurd, file authors can differ from their owners, but in other operating systems the two are the same.
The centos4 manual page for "ls" neither explains what the "author" is nor mentions that the option only applies to "long format".