The chown command is used to change the ownership of a file, but it does not provide information on the current ownership. You can use the ls or stat commands to get this information. Here’s how you can do it.
1. First, open your terminal.
2. Then, use the cd command to change to the directory containing the file:
cd /path/to/directory
3. List the file with ls
ls -la filename
4. Replace filename with the name of your file.
4. Here’s an example output:
-rw-r--r-- 1 user group 1024 Mar 6 12:00 filename
1. Run the stat command:
stat filename
2. Interpret the output from stat.
Here’s an example output:
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
Birth: -
getfacl filename
If you need to change the ownership of a file, use the chown command with superuser privileges:
sudo chown newuser:newgroup filename
Replace newuser and newgroup with the desired owner and group.
Using ls -la, stat, or other relevant commands, you can easily find out who owns a file and what permissions it has in Linux. Whether you want to view or change it, these tools are useful for managing files in your system.