Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to get the username of the person who modified a specific file:

stat -c "%u" somefilename.name

this script returns a number like 544

what does that mean? i was hoping to get the username like myUsername?

share|improve this question

2 Answers 2

You get the numerical userid from this commmand (edit: the userid of the owner, not the user who last modified the file). To get the related username, try getent passwd 544 (I have no idea if that works like this on Cygwin).

You can try to combine these commands:

getent passwd $(stat -c "%u" somefilename.name)
share|improve this answer
    
thanks! i did man getent, but it doesnt have this. would there be a way to do this on one line instead of having to do the stat etc and then getent? i need to do a count of how many files every user modified –  Yuck Feb 1 '13 at 18:09
    
@АртёмЦарионов I just edited the combination command before receiving your comment :) –  SvW Feb 1 '13 at 18:11
    
-bash: getent: command not found –  Yuck Feb 1 '13 at 18:11
    
@АртёмЦарионов: You don't get the information you want this way anyway, as I just realized. It shows the owner of a file, not who last modifed it. –  SvW Feb 1 '13 at 18:18
    
oh i see! owner = person who created? –  Yuck Feb 1 '13 at 18:18

It is the ID of the user. Issue:

awk -F: '{if ($3 == "544") print $1;}' /etc/passwd

to see the account name.

Now, you'll see Administrators, which probably isn't very helpful for you, but that's how Cygwin sees the owner.

See http://cygwin.com/cygwin-ug-net/ntsec.html and especially chapter Example 3.3. /etc/passwd there for more information.

share|improve this answer
    
This is cygwin, on Windows. –  SvW Feb 1 '13 at 18:17
    
interesting! here's what i did $ grep $(stat -c "%u" woodland\ terrace.lnk) /etc/passwd SYSTEM:*:18:544:,S-1-5-18:: LocalService:*:19:544:U-NT AUTHORITY\LocalService,S-1-5-19:: NetworkService:*:20:544:U-NT AUTHORITY\NetworkService,S-1-5-20:: Administrators:*:544:544:,S-1-5-32-544:: –  Yuck Feb 1 '13 at 18:17
    
which one would be the username here? –  Yuck Feb 1 '13 at 18:17
    
Edited my answer. –  grassroot Feb 2 '13 at 6:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.