To find the owner of a file on a Unix or Linux system, you can use the stat
command.
Here is the basic syntax for using the stat
command to find the owner of a file:
stat [options] file
The file
argument is the name of the file whose owner you want to find.
To display the owner of a file, you can use the -c
option with the %U
format specifier.
For example, to find the owner of the file file.txt
, you can use the following command:
stat -c %U file.txt
This will display the username of the owner of file.txt
.
You can also use the -L
option to follow symbolic links and display the owner of the file that the symbolic link points to.
For example:
stat -L -c %U file.txt
This will follow the symbolic link file.txt
and display the username of the owner of the file that the symbolic link points to.
Alternatively, you can use the ls
command with the -l
option to display the owner of a file.
For example:
ls -l file.txt
This will display a long listing of the file, including the owner, permissions, size, and modification time. The owner is displayed in the first column of the output.