The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Owner of file gets 'not owner' error for chgrp brizrobbo SUN Solaris 4 12-18-2007 02:30 PM
change owner of a file CBarraford UNIX for Dummies Questions & Answers 3 03-03-2007 08:37 PM
How to change the owner of the file? redlotus72 UNIX for Dummies Questions & Answers 1 09-21-2006 08:31 PM
determine owner directory permissions from within the directory Sniper Pixie Shell Programming and Scripting 4 03-07-2006 02:06 PM
changing owner & grp of a file Sabari Nath S UNIX for Advanced & Expert Users 1 09-27-2005 09:08 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-26-2008
Registered User
 

Join Date: Jan 2008
Posts: 10
determine owner of a file

Hello,

I am on a mission to determine the user of file. I have used the ls -l command but it displays permission, link, user, group, etc, but I just want to display just the name of user of a specified file.

Many thanks
Reply With Quote
Forum Sponsor
  #2  
Old 01-26-2008
Registered User
 

Join Date: Jul 2007
Location: India
Posts: 14
ls -al |awk ' { print $3 }'
Reply With Quote
  #3  
Old 01-26-2008
Registered User
 

Join Date: Jan 2008
Posts: 10
thanks for that mate.

Can i be stupid to ask is there any other way to do it witout using the awk command
Reply With Quote
  #4  
Old 01-26-2008
Registered User
 

Join Date: Jan 2008
Posts: 9
stat -c %U filename
Reply With Quote
  #5  
Old 01-26-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
Using Perl

Code:
use File::stat;
use User::pwent;

$filename = "$ARGV[0]";
$attrs = stat($filename);
$pwattrs = getpwuid($attrs->uid);

printf "Owner is %s (%d)\n", $pwattrs->name, $attrs->uid;
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0