How To Check Who Owns a File in Linux
If you want to check who owns a file, Linux works very differently from other systems. There’s no option to just right-click a file and go to Properties or Get Info like on Windows or macOS.
Plus, file ownership is different on Linux. Every file has its owner and a group to which the owner belongs. It might be helpful to know this information in many situations, such as troubleshooting permission issues.
There are three common ways to see a file’s owner in Linux. Here’s what they are.
“Is -I” Command
The “Is -I” command is the most convenient way to see a file’s owner. All you have to do is follow these steps.
- Open the terminal.
- Type in “
Is -I filename”.
- Check the third column to see the owner.
Of course, you’ll replace filename with the file’s actual name. So if the name was file123, the command would be:
% ls -l file123
This command will give you lots of other valuable information.
- File type
- Date and time
- Hard links
The result will look something like this:
-rw-r--r-- 2 mark admin 246 Jun 3 08:21 file123
The information is as follows.
- -rw-r–r– : file mode
- 2 – number of links
- mark – Owner name
- admin – Group name
- 246 – file size (number of bytes)
- Jun 3 08:21– month and day when the file was modified, followed by the exact hour and minute
- File123 – File name
People often use the Find command to look for files within a directory. But with the Print function, you can also list the files’ owners.
You can do so with the following command syntax.
# find /dir -printf '%u\n'
You can also use more advanced filtering to only show unique users by adding the -u option:
# find /dir -printf '%u\n' | sort -t: -u
Finally, you can see the group to which the file belongs by adding the %g option:
# find /dir -printf '%u:%g\n' | sort -t: -u
The Stat is another highly useful command you can use to get many details on a file, including the owner. You can input multiple file names and modify the command with many options showing you different information.
The command is very easy to use. All you have to do is type “
You can see the device on which the file is, who has access, when the most recent changes were made, etc.
If you only want to see the file’s owner and group, you can use the %U and %G options. So if we use the file123 example again, the command will be:
stat -c “%U %G” file123
How to Change the Owner of a File in Linux
If you want to change a file’s owner, you can use the chown command. Open the terminal and type in “
chown username filename”. So, for example, if you want Mark to be the owner of file123, you’ll type in “
chown mark file123.”
You can change the file’s group using the same function. If you want to change both the owner and group, type in “
chown username:groupname filename”.
Get the Details You Need
As you can see, it’s not hard to find the file’s owner, group, and other relevant details of a file in Linux. All these commands are easy to use, so you can get the information you need in no time. Plus, you can modify them with different options to fine-tune your search.
Do you have any other tips and tricks for navigating Linux files and checking their ownership? If so, feel free to share them in the comments section below.
Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.