- 3 Ways to Find File Owner in Linux
- Understanding the ownership of files in Linux
- Procedure to Find file owner in Linux
- Find file owner with ls command in Linux
- check file owner with stat command in Linux
- get file owner with stat command + two options in Linux
- How to change the owner of a file or folder in Linux?
- Find all files owned by a certain user with Linux Find command
- Linux commands for file owner and permission
- How To Change User Full Name In Linux?
- Show User Full Name
- Change User Full Name with chfn Command
- Change User Full Name with usermod Command
- Change User Full Name via /etc/passwd File
- Change User Full Name via GUI (Gnome)
3 Ways to Find File Owner in Linux
In Linux, every file and folder belongs to a user and a group. This can be very helpful when you need to troubleshoot permissions issues.
In this blog post, we will discuss three different ways to find the owner of a file or folder in Linux. Let’s get started!
The following Linux commands can be used to find file owner.
- ls -l howtouselinux # file owner is on the 3rd column
- stat howtouselinux # file owner is after uid
- stat -c “%U %G” howtouselinux
Understanding the ownership of files in Linux
Linux file ownership is one of the most important concepts to understand when administrating a Linux system. Every file and folder on a Linux system has an owner and a group.
The owner is the user who created the file or folder, and the group is the group to which the owner belongs.
- User Owner (UID): Every file and directory is assigned a user owner, identified by a unique user ID (UID). The UID corresponds to a user account on the system.
- Group Owner (GID): Each file and directory is also associated with a group owner, identified by a unique group ID (GID). The GID corresponds to a group on the system.
File ownership is closely tied to file permissions. The owner, group members, and other users are assigned specific permissions (read, write, execute) for the file, which determine who can access and modify it.
File ownership is important for security. It allows you to control who can access your files.
For example, you can make sure that only you can access your personal files by setting the owner to yourself. You can also make sure that only members of a certain group can access a file by setting the group to that group.
Procedure to Find file owner in Linux
- Open the terminal.
- Type ls -l and press Enter. This will show a list of all the files in the current directory with their permissions, owner, and group.
- Type stat filename and press Enter. This will show detailed information about the file including the owner.
- Type find / -type f -user username and press Enter. This will find all the files on the system that are owned by the specified user.
- Type find / -type f -group groupname and press Enter. This will find all the files on the system that are owned by the specified group.
Find file owner with ls command in Linux
The most simple method to find file owner in Linux is using “ls -l” command. Open the terminal then type ls -l filename in the prompt. The 3rd column is the file owner.
The ls command should be available on any Linux system. It will list the file type, file permission, group, file size etc.
This command will show you all of the following information about a file or folder, including its owner.
- File type
- File permissions
- Hard links
- Ownership
- Group
- Size
- Date and time
To use this method, simply type “ls -l filename”. Replace “filename” with the name of the file or folder you are looking for.
For example, if I want to find the owner of a file called “testfile”, I would type “ls -l testfile”.
In the following example, the owner of testfile is howtouselinux.
% ls -l testfile
-rw-r—r— 1 howtouselinux staff 0 3 3 21:04 testfile
check file owner with stat command in Linux
Another way to find the owner of a file or folder is by using the “stat” command. This command will show you even more information about a file or folder than ls -l.
stat is a command-line utility that displays detailed information about given files. stat command accepts one or more FILEs and it also includes a number of options that control the command behavior.
To use this method, simply type “stat filename”. For example, if I wanted to find the owner of a file called “testfile”, I would type stat testfile.
$ stat testfile
File: `testfile’
Size: 32 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 429064 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 1000/ howtouselinux) Gid: ( 1000/ staff)
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
From the output, we can see that the owner of this file is howtouselinux. The uid of this user is 1000.
get file owner with stat command + two options in Linux
The third way to find the owner of a file or folder is by using the “stat” command with %U %G options. It will only display the owner and group of this file.
The -c option in the stat command allows you to specify a custom format for the output. This option is followed by a format string that defines the desired output format.
stat -c «%U %G» testfile
howtouselinux staff
“%U %G”: The format string enclosed in quotes. It contains two format specifiers:
%U: Represents the user name of the file’s owner.
%G: Represents the group name of the file’s group owner.
The output of the command will be the user name followed by a space and then the group name of the “testfile”.
For example, if the file’s owner is “john” and the group owner is “users”, the command will output:
How to change the owner of a file or folder in Linux?
You can use the chown command to change the owner of a file or folder in Linux.
To use this command, simply type “chown username filename”. Replace “username” with the name of the user you want to be the owner, and replace “filename” with the name of the file or folder you want to change.
For example, if I wanted howtouselinux to be the owner of a file called “testfile”, I would type “chown howtouselinux testfile”.
You can also use chown to change both the owner and group of a file or folder. To do this, simply type “chown username:groupname filename”.
Find all files owned by a certain user with Linux Find command
If you want to find all files owned by a certain user, use the find command.
To do this, simply type “find / -user username”. Replace “username” with the name of the user who owns the file or folder you are looking for.
For example, if I wanted to find the files whose owner is howtouselinux, I would type “find / -user howtouselinux”.
Linux commands for file owner and permission
Here are the Linux commands for file owner.
- You can use the ls command to list the owner of a file. For example, if you want to list the owner of the file foo.txt, you would type: ls -l foo.txt
- You can use the chown command to change the owner of a file. For example, if you want to change the owner of the file foo.txt to the user bar, you would type: chown bar foo.txt
- You can use the ls command to list the group of a file. For example, if you want to list the group of the file foo.txt, you would type: ls -l foo.txt
- You can use the chgrp command to change the group of a file. For example, if you want to change the group of the file foo.txt to the group bar, you would type: chgrp bar foo.txt
Here are the Linux commands for file permission.
- You can use the ls command to list the permissions of a file. For example, if you want to list the permissions of the file foo.txt, you would type: ls -l foo.txt
- You can use the chmod command to change the permissions of a file. For example, if you want to make the file foo.txt readable and writable by everyone, you would type: chmod 666 foo.txt
- You can use the ls command to list the modification time of a file. For example, if you want to list the modification time of the file foo.txt, you would type: ls -l foo.txt
- You can use the touch command to change the modification time of a file. For example, if you want to change the modification time of the file foo.txt to the current time, you would type: touch foo.txt
And that’s it! These are three different ways to find out who owns a file or folder in Linux. Do you have any other tips or tricks? Share them with us in the comments below! And don’t forget to check out our other blog posts for more Linux tips and tricks. Thanks for reading!
David is a Cloud & DevOps Enthusiast. He has years of experience as a Linux engineer. He had working experience in AMD, EMC. He likes Linux, Python, bash, and more. He is a technical blogger and a Software Engineer. He enjoys sharing his learning and contributing to open-source.
howtouselinux.com is dedicated to providing comprehensive information on using Linux.
We hope you find our site helpful and informative.
How To Change User Full Name In Linux?
Linux distributions stores different information about the user accounts. The User Full Name is also stored for the users and located inside the /etc/passwd file. The user’s full name is requested during user account creation. But it can be changed later in different ways. The user’s full name can be changed via a command-line interface or GUI. In this tutorial, we examine command line or GUI methods to change a user’s full name in Linux.
Show User Full Name
The user’s full name is stored inside the /etc/passwd and there are different ways to show the user’s full name. The cat command can be used to print the passwd file which also shows the user’s full name.
Change User Full Name with chfn Command
The native and easiest way to change user’s full name is the chfn command. The chfn command -f option is used to set specified user full name. The username is provided as a parameter to specify the user which full name will be set. In the following example, we set the user ismail name as “İsmail Baydan”.
$ chfn -f "İsmail Baydan" ismail
Change User Full Name with usermod Command
Another command to set or change user full name is the usermod command. The user full name is provided with the -c option and also the username is provided. In the following example, we set the user ismail name as “İsmail Baydan”.
$ usermod -c "İsmail Baydan" ismail
Change User Full Name via /etc/passwd File
The user full name is stored inside the /etc/passwd file. This file can be opened with an text editor and related user full name can be changed and saved as the last step. The /etc/passwd file should be opened with the administrator privileges like root or by using the sudo command.
Change User Full Name via GUI (Gnome)
Another way to change user’s full name is using the GUI which can be GNOME, KDE, XFCE, etc. Just open the Settings tool and navigate to the Users tab from the left pane. Then click on the pen image which edits the user’s full name.
Just edit the user’s full name and click different locations to save the new full name.