Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the Find command in linux to ignore one or more subdirectories

Shulou Source: shulou.com Published: 2022-06-01 07:00:06 09月22日 Update

This article is about how to use the Find command in linux to ignore one or more subdirectories. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

When you use the find command to find files on a linux system, you sometimes need to ignore certain directories, and you can use the-prune parameter to filter.

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

For example: specify to search 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

To search by file name is:

The code is as follows:

Find / home/zth-path "/ home/zth/astetc"-prune-o-type f-name "cdr_*.conf"-print

What if you want 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 /).

To find the contents of a file, the following statement can solve the problem of directories 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"

Through the above example, you should be able to master the find command to find files, ignore the relevant directory method.

Thank you for reading! On "how to use the Find command in linux to ignore one or more subdirectories" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Tags: Code files directories commands paths parameters search multiple subdirectories subdirectories content more spaces articles good practical two functions examples including content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Xiaomi NVidia MySQL Apple