-1

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?

Alex Gordon
  • 455
  • 3
  • 14
  • 31

2 Answers2

1

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)
Sven
  • 98,649
  • 14
  • 180
  • 226
  • 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 – Alex Gordon Feb 01 '13 at 18:09
  • @АртёмЦарионов I just edited the combination command before receiving your comment :) – Sven Feb 01 '13 at 18:11
  • -bash: getent: command not found – Alex Gordon Feb 01 '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. – Sven Feb 01 '13 at 18:18
  • oh i see! owner = person who created? – Alex Gordon Feb 01 '13 at 18:18
  • Usually, owner = person who created, but this doesn't change if someone else modifies it. The OS doesn' t keep track of this info. – Sven Feb 01 '13 at 18:19
  • whats the diff between owner and modifier\ – Alex Gordon Feb 01 '13 at 18:20
  • modifier doesn't exist as an information in the file system. – Sven Feb 01 '13 at 18:21
  • no kidding! thats interesting. but this is windows! – Alex Gordon Feb 01 '13 at 18:22
  • Doesn't matter. NTFS doesn't track this either. – Sven Feb 01 '13 at 18:23
  • but in windows i am able to right click on a file and get the properties, the properties will say who edited it last – Alex Gordon Feb 01 '13 at 18:24
  • @АртёмЦарионов: No, not in the general case. It might work with some specific file formats the explorer knows or has a plugin for (like MS-Office), but then it will get it out of the metainformations of the file, not from the file system. Test it with a plaintext notepad file. – Sven Feb 01 '13 at 18:35
  • getent isnt working on cygwin! – Alex Gordon Feb 01 '13 at 18:37
0

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.

grassroot
  • 683
  • 5
  • 14