Using Find Command Part One

0
232
Using Find Command Part One

Using Find Command Part One

This article is about using find command part one. Find command is used to search for files and directory in the hierarchy tree on the command line. Find command is one of most useful command to search for files from command line. Find command is one of most useful command to search for files from command line.

Basic Syntax of Find command, if more information required about find and options read the man page from one of the following links.
find(1)       find(2)        find(3)         find(4)

 

1. Just one word, Find.

Just the find command will list every single file and directory in the current directory following to the bottom level of the hierarchy.

As we didn’t specify any arguments, such as directory-path the find command takes the current working directory as the directory path and lists the files from the current working directory.

2. Find files in the specific directory path.

The command prints all the files inside the directory Linux/ubuntu, the directory_path_name should start from the present working directory. if the directory path doesn’t start from the current directory, the command may present an error of file not found.

3. Find files using name operation.

The command prints all the path entries which contain the directory manjaro or file manjaro. The Path doesn’t need to start with the name, but it should be in the lower level of the hierarchy from the current working directory to get an output otherwise the command will report us file not found.

4. Find files using inode.

In the Linux File system, every file or directory is given a unique number to identify the file, called the inode number. even if two files named exactly same will have distinct inode numbers. Using this inode number you can find a specific file from the directory hierarchy.

To find the inode number of the file you can use ls command with -li option to list files name with inode numbers or also you can use stat command.

The command will output a huge number followed by normal attributes of files like permissions, links etc. Even you can find inode number using the stat command, syntax of stat command.

The command will provide a huge list of values like size, blocks, device, links, inode etc. Once, you know inode of number, use find command to find the specific file in the entire hierarchy.

The command will find the file with inode number [655442], the file or directory should be in the lower level of the hierarchy from the current working directory.

5. Invert the Match.

If you want to find a list of files excluding some files which you don’t need you can always use the invert operation. Invert operation can be defined either by using -not the option or using ‘!’ character.

The output of this command will be the list of all files in directories and subdirectories excluding the file named filename.

6. The Depth, how deep to search.

Suppose you have some 10 level of hierarchy which contains hundreds of files and have some common files in all the level, but we only need files from the 5th level of hierarchy or till the 4th level of hierarchy or from 2nd level to 6th level. This can be done using the mindepth and maxdepth operations.

mindepth option tells the find command to start searching for the file or directory ubuntu after two levels from the current working directory. In the above command, if we change the value of mindepth to 3, we would not get any value because find is searching for the file ubuntu after three levels from the current working directory. whereas the ubuntu directory is present on the second level of the hierarchy.

maxdepth option tells the find command to stop searching for the file or directory linuxmint after searching three levels from the current working directory. In the above command, if we change the value of maxdepth to 2, we would not get any value because find is searching for the file linuxmint up to two levels from the current working directory. whereas the linuxmint directory is present on the third level of the hierarchy.

This version of command tells the find command to start searching from the second level of the hierarchy and end the search at the third level of the hierarchy.

7. Empty files and directories.

The command will list all the empty files or directories from the current working directory till the lower last level of the hierarchy.

The command has listed the last level of the hierarchy because all other directories have subdirectories.

That’s it, we are at the end of the article using find command part three. Have any question?
Feel free to ask them in the comments below. Stay tuned for more updates.

SHARE
Previous articleTop Free VPNs for Android
Next articleUsing Find Command Part Two
arunvkumr@gmail.com'
Arun is Open Source Enthusiast. He likes to spend most of his time exploring linux distribution, solving puzzles and coding.

LEAVE A REPLY