LLI Wiki — My Digital Knowledge Base

Get a file's owner and group on Linux

Use ls -l and stat to display a file's owner and group.

Three ways to find the owner and group of a file on Linux.

With ls

ls -l /path/to/file

In the output, the third field is the owner (user) and the fourth is the group.

With stat

stat /path/to/file

Example output:

  File: `py'
  Size: 32              Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d      Inode: 429064      Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1000/  user1)   Gid: ( 1000/  user1)
Access: 2012-07-27 17:49:05.682143441 +0300
Modify: 2012-07-01 03:58:02.848540175 +0300
Change: 2012-08-01 21:12:57.129819212 +0300

The name in the Uid field is the owner and the name in the Gid field is the group.

Only the owner and group

stat -c "%U %G" /path/to/file
Mastodon LLIMastodon SocialFosstodon