Using the find command in Linux to find files How to ignore certain directories

  

When doing Linux command operations, sometimes many directories are searched for, and these directories are not what we need, so we can ignore them. The following small series teaches you how to use the find command to ignore subdirectories.

use the find command on linux find files when the system is sometimes necessary to ignore certain directories, may be used to filter parameters -prune.

However, it must be noted that the path parameter to be ignored must follow the search path, otherwise the parameter will not work.

For example: Specify all files in the /home/zth directory, but ignore the path to /home/zth/astetc:

The code is as follows:

find /home /zth -path “/home/zth/astetc” -prune -o -type f -print

Search by file name:

The code is as follows:

find /home/zth -path “/home/zth/astetc” -prune -o -type f -name “cdr_*.conf” -print

How to ignore more than two paths ?

The code is as follows:

find /home/zth /( -path “/home/zth/astetc” -o -path “/home/zth/etc” /) -prune -o -type f -print

find /home/zth /( -path “/home/zth/astetc” -o -path “/home/zth/etc” /) -prune -o -type f -name “cdr_*.conf” -print

Note: There are spaces before and after /( and /).

Finding a file containing content, the following statement can solve the problem of the directory with spaces:

The code is as follows:

find. /-name “mysql*” -print0 | Xargs -0 grep “SELECT lead_id FROM vicidial_list where vendor_lead_code”

If the directory does not have spaces, you can do this:

The code is as follows:

find . /-name “mysql*” | Xargs grep “ SELECT lead_id FROM vicidial_list where vendor_lead_code”

The above is the way to ignore subdirectories when using the find command to find files in Linux. If you need to use related operations, but also use the find command. If you are not very familiar with it, you may wish to learn more about this article and hope to help you.

Copyright © Windows knowledge All Rights Reserved