Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the-path-prune command in the Linux find command

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use the path-prune command in the Linux find command". In the daily operation, I believe that many people have doubts about how to use the path-prune command in the Linux find command. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the Linux find command-path-prune command"! Next, please follow the editor to study!

If you look for files in the current directory, and there are many files and directories (multi-tier directories) in the current directory, including dir0, dir1 and dir2. Wait for catalogue and dir00, dir01. .dir10 、 dir11. . . Wait for subdirectories.

1. Find all txt suffix files in the current directory

Find . /-name * .txt

two。 Look for txt suffix files in the dir0 directory and subdirectories under the current directory

Find . /-path'. / dir0*'-name * .txt

3. Look for the txt suffix file under the subdirectory dir00 and its subdirectories under the dir0 directory under the current directory

Find . /-path'* dir00*'-name * .txt

4. Look for txt suffix files in directories other than dir0 and subdirectories

Find . /-path'. / dir0*'-a-prune-o-name * .txt-print

Note:-a should be an abbreviation for and, meaning the logical operator'or'(& &);-o should be an abbreviation for or, meaning the logical operator 'and' (| |), and-not means no.

The command line means that if the directory dir0 exists (that is, true to the left of-a), the value of-prune is evaluated,-prune returns true, and the logical expressions of 'and' are true (that is,-path'). / dir0*'-a-prune is true), the find command will look for txt suffix files in a directory other than this directory and print them out; if the directory dir0 does not exist (that is, the left side of-an is false), it will not evaluate-prune, 'and' logical expressions are false, then look for all txt suffix files in the current directory.

5. Look for txt suffix files in directories other than dir0, dir1, and subdirectories

Find . /\ (- path'. / dir0*'-o-path'. / dir1*'\)-a-prune-o-name * .txt-print

Note: parentheses () indicate the combination of expressions. That is, it instructs shell not to make a special interpretation of the following characters, but leaves it to the find command to explain its meaning. Since parentheses cannot be used directly on the command line, you need to change meaning with a backslash (that is, the'\ 'character makes the command line aware of parentheses). At the same time, note that spaces are required on both sides of the'(','\)'.

6. Look for txt suffix files in dir0, dir1 and subdirectories

Find . /\ (- path'. / dir0*'-o-path'. / dir1*'\)-a-name * .txt-print

+ 1. Look for txt suffix files in all directories named dir_general

Find . /-path'* / dir_general/*'-name * .txt-print

At this point, the study on "how to use the path-prune command in the Linux find command" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report