Different ways to get an owner of a file in Linux ?

In this post, we will look different ways to get owner of a file in linux.

We generally use ls command, however there are different ways available to achieve this.

1. Using ls command

[root@nglinux ~]# ls -l abc1.c 
-rw-r--r--. 1 root root 48 Jul  9  2018 abc1.c

 

2. Using stat command

[root@nglinux ~]# stat -c %U abc1.c 
root

 

3. Using find command.

# Get owner of all files matching the pattern
[root@nglinux ~]# find . -name "abc1*" -printf "%u\n"
root
root
[root@nglinux ~]# 

# Get owner of the specified file
[root@nglinux ~]# find . -name "abc1.c" -printf "%u\n"
root
[root@nglinux ~]# 

 

There could be various other ways to get the file owner in linux, however i have used these methods.

In case of any other way, please feel free to post in comments.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments