Need to know who owns a file on your Linux server? Two commands show you: ls and stat.
Both reveal ownership details. ls gives you a quick overview, stat provides comprehensive information.
Open your terminal.
Navigate to the directory containing the file:
cd /path/to/directory
List the file with detailed information:
ls -la filename
Replace filename with your actual file name.
-rw-r--r-- 1 user group 1024 Mar 6 12:00 filename
Breaking this down:
user is the file ownergroup is the group owner1024 is the file sizeWant file sizes in readable format? Use ls -lh instead.
The stat command gives you more detail:
stat filename
File: filename
Size: 1024 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 1234567 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ user) Gid: ( 1000/ group)
Access: 2024-03-06 12:00:00.000000000 +0000
Modify: 2024-03-06 12:00:00.000000000 +0000
Change: 2024-03-06 12:00:00.000000000 +0000
Uid shows the user ID and username of the owner. Gid shows the group ID and name.
You also get access, modification, and change timestamps.
If Access Control Lists are configured, use getfacl for extended permission details:
getfacl filename
Shows additional permission layers beyond standard Unix permissions.
Found the wrong owner? Change file ownership with chown:
sudo chown newuser:newgroup filename
Replace newuser and newgroup with the correct owner and group.
You’ll need superuser privileges. If you’re working as a different user and need to switch users in Linux, do that first.
Checking ownership is often part of broader file management. You might also need to check directory sizes when investigating disk usage or tracking down large files.
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting