Sometimes, it’s difficult to find a Linux file surrounded by thousands of other files. The Linux Command-Line (CLI) has numerous commands that help perform several tasks effortlessly. Apart from listing all the contents of the present directory using the ls command, creating a new directory using the mkdir command, using rsync command, or creating a new blank file using the touch command. You can use the find command to find the files or directories in Linux.
Find command is the best command to find something on a Linux server. Let’s take a deep look at the find command.
Use of “Find” Command in Linux
Well, the find command can be used to perform several tasks. It can find files, directories, hidden files, hidden directories, and other tasks.
Find hidden files using the “Find” Command
You can follow the below command to find and list all the hidden files on your server.
$ find .
The above command will list all the hidden files starting from the current directory. Moreover, you can use some other attributes to filter your findings.
Use “.” to start from the present working directory. Use“~” to start from the current user home directory. Use“/” to start from the system root directory.
The results will look similar to the ls command. You can add |less at the end to easily scroll through results.
You can narrow your search results using the grep command.
Other than this, you can find the files & directories by adding the keyword after the find command. For example, you can use the below command if you want to find all the files & directories that start with backup.
“Find” Command in Linux
find . -name "backup*"
You can use -iname for case-sensitive search.
To list only files starting with the “backup”, use the below command.
find . -type f -iname "backup*"
Likewise, to list all the directories starting with “backup”, use the below command.
find . -type d -iname "backup*"
Other than this, you can also filter your search results by size. For instance, if you want to filter all the files or directories starting with “backup” as well as more than a specific size such as kilobytes (k), megabytes (m), and gigabytes (g), use the below command.
Filter your search result with -size command
find . -type f -size +1M -iname "backup*"
This will list all the files starting with the backup name and over 1MB in size.
Interestingly, you can use the -perm argument in the find command if you want to find files or directories using their permission code.
“Find” With Permissions Codes
find . -perm 644
The above command will list all the files or directories having 644 permission.
You can also search files with the time attribute. You can list all the files accessed before (-), or after (+) a specific time frame.
Use the below command to list all the accessed files within the last 24 hours.
“Find” Command With time Argument
find . -atime -1
Within 30 minutes
find . -amin 30
List all the files of your present working directory modified over the last 365 days.
find -mtime +365
I hope now you can use the find command easily. However, you can learn basic Linux Commands by visiting our latest article if you’re new to the Linux industry. Moreover, you can contact us on Facebookor Twitterfor any further assistance.