Almost all the desktop platforms provide the facility to search the entire file system for required files and folders with an ease. So, is the Linux platform that allows making use of file manager to accomplish the task of Linux search for file. While in Windows, it features a user interface which displays a series of folders and subfolders and the files stored in it. In Linux, the best way to find files is through the Linux find command. It is nothing but a simple command line utility that shows up the file hierarchy and makes it easier to find files. This can be implemented both on files and directories to search file based on file, folder, name, modification date, creation date, and permissions. It makes use of -exec flag to locate files immediately. Here, let us discuss in detail of the process to accomplish the task of Linux search for file using Linux find command.
The Linux find command lets to search for the required files if you are aware of the approximate file names. It takes a number of paths to search for the intended file or directory in each path. In case, it finds any other directories or files, then it looks for the required file inside it. This process continues until it finishes the search of all items in the path specified. Here is the basic structure of the Linux Find command to search for a file.
Find [paths] [Expressions] [actions]
By default, the Linux find command searches for everything that is stored in the directory. In case, you wish to sort down the choice based on certain criteria then you can specify it in the expressions. Also, there is an option to specify the custom action to display results by the Linux find command. In case you want the list of contents available in the current working directory then just use the period after the find command.
If there are no paths, then the Linux find command assumes that it should work on the current directory. In such a case, you can use just find.
Here is all you need to know about Librem 5, the upcoming Linux phone
In order to find for a particular file by its name, then you need to pass the -name option to find command along with the file name. For instance, if you are trying to find some text file by the name sample. The command should be:
find . -name sample.txt
To find all the .jpg files in a particular folder and sub-directories, the command line should be:
find ./home -name *.jpg
To find for an empty file in the present directory, type in:
find . -type f -empty
Also, there is an option for Linux find file based on the last modified date. To find the files based on modification date, use the command -mtime followed by a number of days. The number specified can be either negative or positive. For instance ‘-1’ displays the results of files modified within the last day. ‘+1’ shows the results of files modified more than one day ago.
Find ./sample -mtime -1
find ./sample -mtime +1
In order to search for a file based on the permission access is given, use -perm option followed by the value. For instance, to search for files in the sample folder or directory. that everyone can read, write and execute, we enter the value 777.
find ./sample -perm 777
As the find command to perform Linux find file task, you can also use “Which” command to display the absolute path of executable.