Cyberithub

6 Popular Examples to Find Files owned by Group(s) in Linux/Unix

Advertisements

In this article, I will take you through 6 Popular Examples to find Find Files and Directories Owned by Group(s) in Linux/Unix based Systems. In many occasions you might have noticed that you need to find all the files owned by Group to perform some specific task. This can easily be possible by using find command in Linux/Unix based systems. You can even find files based on file name or by using some search pattern based on your requirements. We will understand how this can be done by using various examples.

6 Popular Examples to Find Files owned by Group(s) in Linux/Unix

Unix/Linux Find Files and Directories Owned By Group(s)

Also Read: Unix/Linux Find Files/Directories owned by a Particular User(5 Useful Examples)

Example 1: How to Find a Particular File Owned by Group in Linux/Unix

If you want to find a particular file owned by a particular group then you can use below find command. In this example, we are looking for hello.txt file owned by group centos using find / -group centos -name hello.txt command.

[root@localhost ~]# find / -group centos -name hello.txt
/root/hello.txt

/ : Search all the files under / path.

-group : File is owned by group. More can be checked on Find command Man Page.

-name : Base of file name (the path with the leading directories removed) matches shell pattern pattern.

NOTE:

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.

Example 2: How to Find All the Files and Directories Owned by Group

If you want to find all the files and directories owned by a particular group then you need to simply use below find command. In this example, we are looking for all the files and directories owned by group centos using find / -group centos command.

[root@localhost ~]# find / -group centos
/root/hello
/root/example
/root/example/hello.rs
/root/example/hello
/root/hello.txt
/root/example.txt
/var/db/sudo/lectured/centos
/home/centos
/home/centos/.bash_logout
/home/centos/file
/home/centos/.bash_history
/home/centos/example.txt
/home/centos/.bash_profile
/home/centos/.bashrc
/home/centos/output.txt
/home/centos/CentOS.ISO
/home/centos/.Xauthority

Example 3: How to Only Find the Files Owned by a Particular Group

If you only want to find the files owned by a particular group and not the directories then you need to use -type f option with find command as shown below. In this example, we are only looking for the files owned by group centos using find / -group centos -type f command.

[root@localhost ~]# find / -group centos -type f
/root/example/hello.rs
/root/example/hello
/root/hello.txt
/root/example.txt
/var/db/sudo/lectured/centos
/home/centos/.bash_logout
/home/centos/.bash_history
/home/centos/example.txt
/home/centos/.bash_profile
/home/centos/.bashrc
/home/centos/output.txt
/home/centos/CentOS.ISO
/home/centos/.Xauthority

-type : File is of block, character, regular file, symbolic link etc. More can be checked on Find command Man Page.

There is another way which you can use to find all the files owned by a particular group. In this way, you need to use wildcard character(*) with -name option to search all the files under / partition.

[root@localhost ~]# find / -group centos -type f -name "*"
/root/example/hello.rs
/root/example/hello
/root/hello.txt
/root/example.txt
/var/db/sudo/lectured/centos
/home/centos/.bash_logout
/home/centos/.bash_history
/home/centos/example.txt
/home/centos/.bash_profile
/home/centos/.bashrc
/home/centos/output.txt
/home/centos/CentOS.ISO
/home/centos/.Xauthority
/root/example/hello.rs
/root/example/hello
/root/hello.txt
/root/example.txt
/var/spool/mail/centos
/home/centos/.bash_logout
/home/centos/.bash_history
/home/centos/example.txt
/home/centos/.bash_profile
/home/centos/.bashrc
/home/centos/output.txt
/home/centos/CentOS.ISO
/home/centos/.Xauthority

Example 4: How to Find All .txt Files owned by a Particular Group

If you want to find a certain type of files instead of looking for all the files then you can use below find command in Linux. In this example, we are looking for all .txt files owned by group centos using find / -group centos -name "*.txt" command.

[root@localhost ~]# find / -group centos -name "*.txt"
/root/hello.txt
/root/example.txt
/home/centos/example.txt
/home/centos/output.txt

Example 5: How to Find all the directories owned by a Particular Group

If you want to find all the directories owned by a particular group then there are two ways you can find that. One way is by using below find command where you don't have to specify the -name option to search all the directories by default. In this example we are searching all the directories owned by group centos using find / -group centos -type d command.

[root@localhost ~]# find / -group centos -type d
/root/example
/home/centos
/home/centos/file

The other way you can also use to find all the directories owned by a Specific group using below find command where you can specify star(*) with -name option to search all the directories. Both commands can be used interchangeably.

[root@localhost ~]# find / -group centos -type d -name "*"
/root/example
/home/centos
/home/centos/file

Example 6: How to Find a File Owned by a Particular User and a Particular Group

If you want to find a file owned by a particular user and a particular group then you need to use both -user and -group option with find command as shown below. In this example, we are searching for all the files owned by user root and group centos using find / -user root -group centos -type f command.

[root@localhost ~]# find / -user root -group centos -type f
/var/db/sudo/lectured/centos

 

 

 

 

 

 

 

Popular Recommendations:-

Unix/Linux md5sum Command Examples to Verify Checksum

5 Best Methods to Extract .gz File in Linux using gunzip, gzip and tar tool

12 Popular Unix/Linux uname command examples(How to Get Kernel Version)

How to Transfer Files to AWS EC2 Instance Using WinSCP in 3 Easy Steps

6 Easy Steps to Install Sendmail command in Linux (RHEL/CentOS 7/8)

Easy Steps to Install GCC(C and C++ Compiler) on CentOS 7

C# data types with Best Examples (.NET v4.7)

How to Transfer Files to an AWS EC2 Instance Using WinSCP in 3 Easy Steps

Leave a Comment