How to Find Files in Linux with the Linux Find Command

November 22, 2018

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.

Basic Structure of 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.

linux find commandFind [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.

find .

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.

find

Here is all you need to know about Librem 5, the upcoming Linux phone

Linux Search For File By Name

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

Read Also: How To Bypass And Reset The Password On Windows, MacOS And Linux

Linux Search For File By Modification Date

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

linux find commandIn 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.

Also Read: Best Hacking Tools Of 2018 For Windows, Linux And Mac OS X

No votes yet.
Please wait...

Comments (0)

Your email address will not be published. Required fields are marked