Linux Operating System For Files Explained – Complete Process Revealed!

Searching for files on the Linux operating system is not a daunting task if you know each step of the process. But, the command line makes it easy to find a specific file. This is due to one of the functions named “find” of the command line. The “find” function works as a filter for searching files on Linux.

For example, 

find /home/username/ -name “*.err”

In the above example, the “find” function refines the “/home/username/” directory and all the subdirectories to help the users in searching for their *.err files and that’s why linux is more secure.

find command and syntax

The syntax of find command goes as follows-

find options starting/path expression 

The attribute “options” helps in maintaining the optimization process of the find option. On the other hand, the “starting/path” attribute helps to search the main directory in which there are the other files. With the aid of the “expression” attribute, the finding process searches for the directory hierarchy that helps to produce the verdict.

For example, find /home *.jpg

In the above example, the find option looks for all the .jpg files in the home directory and its other subdirectories.

Let us have a glance at some more examples of the linux commands basics so that will help you to clearly understand the topic.

find . -type f -empty

The above example helps you to find an empty file in the current directory.

find /home -user username-mtime 6 -iname “.db”

This find option searches all the .db files which have been modified by a user called “username” in the previous six days. By using “-iname”, you can perform a check without taking into regard the text case of the file. 

Various options and optimizations of the “find” command in Linux

The default setting of the find in Linux commands list helps to ignore the shortcut files. However, if you want to see the symbolic links or the shortcut files, then you can integrate -L option with the command.

Apart from this, the find command enriches its filtering procedure to optimise the performance. This is done by the three stages of optimization in Linux which help to find a file.

The three stages are -01, -02 and -03.  -01 is the default stage which facilitates the find option to search for the filename before conducting any other search process. -02 or the second stage enables the find option to search for the file according to the filename and its type before performing a more complicated search process. -03 or the last stage helps to find the files according to the usage of resources and level of success.

Let us have a glimpse of the top linux command, various options and optimizations of the find command-

  1. -01: This is the default stage which finds the file according to its name.
  2. -02: This level helps to search the file based on the filename and then the file type.
  3. -03: The last level searches for the files according to the expense and success.
  4. -maxdepth x: This option finds the directory and the subdirectories of the level X.
  5. -not: This option looks for the results that do not align with the test case.
  6. -iname: It searches for the file irrespective of their text case.
  7. -type d: This option assesses suitable directories.
  8. -type f: This option analyzes the files.

Locate files which were modified

You can also explore the files which were modified. The “find” command helps in this regard and searches a directory hierarchy.

For example,

find /home/testuser/ -name “*did” -mtime -5

The above example shows how the find command helps the users to search the “testuser” home directory. The command examines the directory to look out for files with names that end with “did” and were changed within the preceding 5 days.

find / -name “*jpg” -mtime 3 

This command facilitates a searching procedure that locates files that end with “jpg” and were modified in the last three days.


Files based on content

With the aid of the find command, the individuals can search for the files based on their filename and type. However, there can be situations when you want to locate a file on the basis of its content. In such cases, a tool named grep comes at your rescue. 

For example-

This command may help you to search for files in the current directory hierarchy and run the command grep “ABC”. The grep command runs only if the file satisfies the conditions. The name of the files is placed in the curly braces.

Processing the files using the find linux commands list

With the aid of the “exec” option, you can run any specific command in the directory in which you find the file. 

For example, 

find . -name “very good” -execdir chmod o+r ‘{}’ \;

This command helps the users to search for every file or directory in the current hierarchy (.). The files with the name “very good” are searched through this option and the command “chmod o+r” helps to change the file permissions of the “find” results. Moreover, you can use “-exec” to locate any file or object that is against the “find” expression.

 It will facilitate quick searching procedures and hence, give more effective results.

These two options named “-exec” and “-execdir” operate without proffering any further prompts. However, if you want to receive the prompts, you can replace the option “exec” with “-ok” and “-execdir” with “-okdir”.

Finding and deleting the files

In order to find files in the Linux operating system and delete them, you can integrate the command “-delete” at the end of an expression to delete all files that align with such an expression.

Be cautious while using this function because all the files that match with your expression will be deleted. For example,

find . -name “*.end” -delete

The above example helps you to search for the files that end with “.end” and hence delete them.

Some individuals even use various graphical file managers to search for files and directories. These file managers entail dolphins in KDE, Thunar in Xfce and Nautilus in Gnome. But, the “find” command is an easy way to complete your search.