×


Search Your Files or Directories With Find Command in Linux Mint

Everything is considered a file in the Linux system. Searching through these files is a simple task that every user has to do. Though there are multiple ways to do this task, searching with the Find command is the most efficient and convenient method to find your target file/directory.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux System queries.

In this context, we shall look into the Find command, its options, and uses that go beyond the basic syntax.


What is Find command syntax?

Find command takes the following format:

$ find [file/directory path] [options] [expression]

How to Browse Files/Directories by Name ?

To search for a specific file by name with the '-name' option, run the following command:

$ find /home -type f -name <filename>.txt

Similarly, You can find the directory by name using the following command:

$ find /home -type d -name <directory name>

Note: '-type' option in the above commands specifies whether we are searching for a file or directory.

Find command search is case-sensitive by default. To search without case sensitivity, use the '-iname' option.

$ find /home -type d -iname pictures


How to Browse Files/Directories by Extension ?

You can narrow down files using their extensions pattern with the following command:

$ find /home -type f -name "*.txt"


How to Browse Files/Directories by File Type and Size ?

To search for a specific type of file, use the '-type' option in your Find command:

$ find /home -type d

You can limit the search of the files by providing a size limit with the '-size' option. The '+' and '-' sign is the format used for "more than" and "less than" operators:

$ find /home -type f -size +5M


How to Browse Files/Directories Using Timestamps ?

You can search files by specifying modification, access, and creation time of the file with the '-mtime', '-atime', and '-ctime' options. Following command searches for files that have modified timestamps of the last two days:

$ find /home -type f -name "*.txt" -mtime -2
$ find /home -type f -name "*.txt" -atime +4
$ find /home -type f -name "*.txt" -ctime -2


How to Browse Files/Directories With Specific Permissions ?

To find files with specific permission, use the '-perm' option. Following command finds files with read-only restriction:

$ find /home -type f -perm /u=r

Similarly, the following command uses the -perm option to find executable files:

$ find /home -type f -perm /a==x

 

How to Browse Files/Directories By User And Groups ?

To search files/directories by their user and user group, run the find command with '-user' and '-group' options:

$ find /home -type f -user mintlinuxapt
$ find /home -type f -group mintlinuxapt


How to Browse For Empty or Hidden Files/Directories ?

You can find all the empty files/directories in your system with the following commands:

$ find /home -type f -empty
$ find /home -type d -empty


How to Search and Delete Files/Directories ?

You can search and delete files simultaneously using the '-delete' or '-exec rm' options in your Find command:

$ find /home -type f -name "*.pdf" -delete
$ find /home -type f -name "*.pdf" -exec rm -f {} \;


Complex Find command examples

Moreover, you can combine the above commands with '-and', '-or' and '-not' options and get more functionality. For Example, the following command searches for a file with two conditions:

$ find /home -user mintlinuxapt -and -size +5M


[Need help in fixing Linux System issues? We can help you. ]


Conclusion

This article covers how you can use the Find command to search and perform different operations efficiently. In fact, the Linux find command is a powerful tool that enables system administrators to locate and manage files and directories based on a wide range of search criteria. It can find directories and files by their name, their type, or extension, size, permissions, etc.