I want the terminal to display the user name that created a particular file, so when I traverse all the way to that file and type in the command ls -l filename.docx or even ls -la /path/to/file, it shows the output as:

staff 1344 May 18 11:03 (filename).docx.

So I don't understand why does it display

'staff 1344'

instead of using my actual user name.

How am I supposed to obtain the actual username in this case (provided I logged in from my admin account)?

  • 1
    Can you↑ please clarify what you need to happen and what your looking for May 18 '19 at 8:49
  • 2
    You may want to add the complete output of your ls commands. As for now it does not look like and some information might be missing or could be misunderstood.
    – Thomas
    May 18 '19 at 9:05
  • I wonder if your username (or maybe groupname) somehow got a CR added to it -- try piping ls -l file_or_glob | cat -v and see if that's any better. May 18 '19 at 10:38
  • You output is incomplete. It way be because there is a carriage return character in the user-name. Please add output of who am i. May 18 '19 at 12:01

Your output fragment is incomplete.

In your line

staff 1344 May 18 11:03 (filename).docx

the staff is the group of the file and 1344 is the size.

A complete line should look similar to this:

-rw-r--r-- 1 user  staff 1344 May 18 11:03 (filename).docx

Here user is the user name, staff is the group name and 1344 is the size.

  • So recently me and my friend set up a local network between our laptops and gave each other full read/write access rights, now I guess it's displaying the owner's username when I type in that command but here's another problem: my friend created a file on that shared network and when I type in that command for the file he created, it still shows my username instead of his. Any clue why that might be the case?
    – ddd
    May 18 '19 at 9:55
  • @ddd You have the same UID. Your UID is something like 1000 on your machine, and he has that same UID on his machine. When he looks at the file, he will see his username, even on files that you create.
    – Kusalananda
    May 18 '19 at 10:02
  • @Kusalananda So would that always be the case? We were actually trying to understand the security mechanism underneath a shared network. Would there be a case when his and my UID are different on a shared network?
    – ddd
    May 18 '19 at 10:16
  • @Kusalananda Also how can our laptops have the same UID when are devices are separate machines on a common network?
    – ddd
    May 18 '19 at 10:24
  • @ddd+ UID User ID (and also GID Group ID) is just a number and by default is assigned separately on each system, although systems set up for common admin (like in schools or businesses) sometimes have them coordinated. You may be confusing with GUID Globally Unique ID aka UUID Universally Unique ID which are computed in a way that makes them unique, or tries to. May 18 '19 at 10:41

I don't understand your question really well but if you need to see the owner of the file you can:

$stat -c "%U" filename.docx

Here you can see the information that the stat command gives:

$stat .ssh/known_hosts 


  File: .ssh/known_hosts
  Size: 886             Blocks: 8          IO Block: 4096   regular file
Device: fe05h/65029d    Inode: 527954      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/kristjan)   Gid: ( 1000/kristjan)
Access: 2019-05-18 07:06:48.455714935 +0000
Modify: 2019-05-18 07:06:48.359714937 +0000
Change: 2019-05-18 07:06:48.359714937 +0000
 Birth: -
  • When I type that it displays- 'stat: illegal option -- c'
    – ddd
    May 18 '19 at 9:45
  • @ddd what is the exact command your trying May 18 '19 at 10:03
  • The command I originally used is 'ls -l filename.docx'. I'll be more specific here, me and my friend we set up a shared p2p network between our laptops and my friend created a file in a shared folder of ours but when I type in that command it displays my username as the owner of the file instead of his. I tried your mentioned command as well but then it just displayed 'stat: illegal option -- c'
    – ddd
    May 18 '19 at 10:09
  • @ddd Sorry but you are very hard to understand and what the problem is, I tried, good luck! May 18 '19 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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