find command in Linux & Unix: How to use it?
The 'find' command in Linux/Unix is one of the most significant and often used commands for finding files and directories. It accepts a variety of inputs and settings for finding files and directories.
Even if you can discover files and folders using GUI in Linux, it will be more friendly and easy to use, the tough part of the GUI is that it may take a long time to receive the output if you use a larger size. As a result, most experienced System Administrators solely utilise the command-line search since it is quick, reliable, and powerful.
Syntax for the basic Find command :
The directory is specified using the following symbols:
- (.) - This stands for the current directory name.
- (/) - This is the path to the root directory.
Find Linux Commands with Examples
1. Look for files by their names.
This command looks for all parseJson files in the development directory.
find development -name "parseJson"
This linux find command looks for all files with the name parseJson in the current working directory.
find . -name parseJson
2. Look for a file that is case-insensitive.
This command will search all files in your home directory, regardless of case.
find development -iname ParseJSON
3. Look for a directory.
This command scans all directories in the root folder with a specific name, such as "user".
find / -type d -name user
Here, type d option is used to find a directory.
4. Find and delete a file.
To delete a specific file, use the -delete option. We must exercise extreme caution while utilising this command because there is no way to undo it after it has been executed. Consider the command below.
find . -name usr.txt -delete
usr.txt is the file name.
To remove multiple files:
# find . -type f -name "*.txt" -exec rm -f {} \;
5. Find files by modification time.
The -mtime option is used to discover files that have been modified, followed by the number of days. It is possible for the number of days to be positive or negative.
The negative value will be used for less than one day ago, such as -1, while the positive value will be used for more than one day ago, such as +1. Consider the command below:
find ./directory -mtime -1
6. Find Command to search files/folders based on size.
The following command looks for files/folders in a folder that are more than 10MB in size.
find /tmp -size -10M
7. Find files by permission.
The -perm option is used to locate files that have been granted permission. Pass the needed value to the search command with the '-perm' option.
Consider the command below:
find development/ -perm 777
Conclusion
We've already gone over the find command, which is used to look for files in a directory structure.
However, find utils also includes the locate command, which searches one or more filename databases for matches and displays them, the update db command, which updates the file name database used by the locate command, and the xargs command, which builds and executes command lines using arguments read from standard input.
The most common type of argument is a list of file names generated by find. The current directory (.) is utilised if no files to search are supplied.
Monitor Your Entire Application with Atatus
Atatus provides a set of performance measurement tools to monitor and improve the performance of your frontend, backends, logs and infrastructure applications in real-time. Our platform can capture millions of performance data points from your applications, allowing you to quickly resolve issues and ensure digital customer experiences.
Atatus can be beneficial to your business, which provides a comprehensive view of your application, including how it works, where performance bottlenecks exist, which users are most impacted, and which errors break your code for your frontend, backend, and infrastructure.
#1 Solution for Logs, Traces & Metrics
APM
Kubernetes
Logs
Synthetics
RUM
Serverless
Security
More