- Nikhil Bhaskar
- May 3, 2021
How to use find command utilities in the Linux
Introduction
In this blog we learn about find command and what are the uses for the same. Its a tool which is not limited to the files or folders.
With the use of find command utility we can search a specific location and add option to control the behaviour of the search.
Prerequisites:
- User will be accessible to the terminal.
- A user must be have sudo privileges or should be login as root.
Basic syntax of the Find command
find <options> <location> <expression> <action> <name>
1- Location – It means where or which we have to search.
2- Expression – In expression we write what we are looking to search.
3- Action – In this term we wrote an action attributes and have to execute a commands on the search results.
4- Name – It represent the string or text we are searching.
5- Options – This attribute is not mandatory element for find command.
How to use the find command
Find command lists all attributes of the character string which included in search. It also enables you to define search parameters, options, and locations with a high level of accuracy.
Search file according to there location
Searching for files based on their location string can be a simple command such as:
sudo find /home/user filename
Used command searches the user home directory.
If not sure where we want to search just give your directory location where we required to search and which file to search.
sudo find /home filename
Use below command to show the search into current working directory.
sudo find .
If required to search in the whole root directories then will have to use slash /.
sudo find /
Tilde ~ character is used to search the item in the current logged user home directory.
sudo find ~
With the use of Expressions of Find command
In the expression we have to apply the additional parameters to the find command to provide search specification content with the use of -name filed.
sudo find –name settings.txt
The system will search the current directory for any file with the name settings.txt.
The system only displays filenames with an exact match to your search terms. This limitation might cause problems if a filename has capital letters, we use iname for searching the file.
sudo find /home –iname filename
The system searches the /home directory and return anything named filename, FileName.
Use of –type d expression will specify the searching in the file or directory.
sudo find . –type d –name Videos
This command will search the current directory (with the period) for a directory with the name “Videos.”
We can also search files with the based on permissions such as:
sudo find . -perm 0000
Return list of all files owned by specific username:
sudo find . -user username
We can find the files on the basis of modified time of file 00.
sudo find . -mtime 00
Same as above we can also search files as well as the access time of the files.
sudo find . -atime 00
In this search we also define the size of the files.
sudo find . -size +20M
The terminal presents a list of all files that match the size criteria.
Commands referencing the size of the searched items can be used individually to show all files larger than a certain size, smaller than a certain size, or within a defined range.