s there a way to determine the owner of a file by using a script?
Example:
-rw-rw---- 1 xxx01 CGroup 20992 Nov 3 15:42 File001.doc -rw-rw-r-- 1 xxx02 CGroup 19456 Aug 19 2002 File002.doc -rw-rw---- 1 xxx03 CGroup 18432 Jul 13 2005 File003.xls 12345678901234567 I will know the file name, such as File002.doc. What I need to get is the owner xxx02. I could use cut to (ls -l testp | cut -b 17-21) in this example, but that would assume a 5 character owner name. Maybe there is another command that will get the file's owner? Any other ideas on determining the owner of a file by using a script? |
Quote:
Code:
ls -l File002.doc | cut -d' ' -f4 Another way by setting shell arguments: Code:
set -- $(ls -l File002.doc) Code:
stat -c%U File002.doc |
Try using
Code:
ls -l filename | awk '{ print $3 }' |
Wow...Not just one but, 3 great ways to get the job done. Thanks Hko and pljvaldez. stat will work best for my current script, but I see uses for the other options too. Excellent.
|
make that four ;)
Code:
billym.>set `ls -l ~/.profile` |
All times are GMT -5. The time now is 02:38 PM. |