...

/

Advanced Usage of the find Utility

Advanced Usage of the find Utility

Learn advanced features of the find utility.

Adding a file name

There are other ways to search for the documentation file. Let’s suppose that we know its name. Then, we can specify its name together with an assumed path. We’ll get the find call like this:

find / -path */doc/* -name README

Run the commands discussed in this lesson in the terminal below.

Terminal 1
Terminal
Loading...

It is easy to locate the right file there.

We can group the conditions of the find utility using the escaped parentheses, which we’ll explain in a moment. Let’s write the find call that searches README files with path */doc/* or LICENSE files with an arbitrary path. This call looks like this:

find / \( -path */doc/* -name README \) -o -name LICENSE

Why should we apply backslashes to escape brackets here?

The parentheses are part of the Bash syntax. Therefore, Bash treats them like language constructs. When Bash meets parentheses in a command, it performs an expansion. The expansion is the replacement of a part of the command with something else. When we escape parentheses, we force Bash to ignore them. Thus, Bash does not perform the expansion and passes all search conditions to the find utility as it is.

Processing found objects

The find utility can process the found objects. We can specify an action to apply as ...

Access this course and 1400+ top-rated courses and projects.