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

The usage of find Command under Linux

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

Share

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

This article mainly explains "the use of the find command under Linux". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "the use of the find command under Linux" together!

When using the Linux find command, use the-ok option to avoid accidental deletion of files, which asks your permission before removing any files.

A friend recently reminded me of a useful option to run find more discreetly: -ok. It works similar to-exec except for one important difference, which makes the find command request permissions before performing the specified operation.

Here's an example. If you use the find command to find files and delete them, you might use the following command:

$ find . -name runme -exec rm {} \;

Any files named "runme" in the current directory and its subdirectories will be deleted immediately--provided you have permission to delete them, of course. Instead of using the-ok option, you'll see something like this, but the find command will ask for permission before deleting the file. Answering y for "yes" will allow the find command to continue and delete files one by one.

$ find . -name runme -ok rm {} \;

< rm ... ./bin/runme >

?- The execdir command is also an option.

Another option that you can use to modify the behavior of the find command and possibly make it more controllable is-execdir. - Exec runs whatever command is specified, while-execdir runs the specified command from the directory where the file is located, rather than from the directory where the find`command is run. Here are two examples of it:

$ pwd/home/shs$ find . -name runme -execdir pwd \;/home/shs/bin$ find . -name runme -execdir ls \;ls rm runme

So far so good. Keep in mind, however, that-execdir also executes the command in the directory of the matching file. If you run the following command and the directory contains a file named "ls," it will run the file even if it does not have execute permissions. Using-exec or-execdir is similar to running commands through source.

$ find . -name runme -execdir ls \;Running the /home/shs/bin/ls file$ find . -name runme -execdir rm {} \;This is an imposter rm command$ ls -l bintotal 12-r-x---- 1 shs shs 25 Oct 13 18:12 ls-rwxr-x--- 1 shs shs 36 Oct 13 18:29 rm-rw-rw-r-- 1 shs shs 28 Oct 13 18:55 runme$ cat bin/lsecho Running the $0 file$ cat bin/rmecho This is an imposter rm command-okdir option is also qualified

To be more cautious, use the-okdir option. Like-ok, this option requests permission to run the command.

$ find . -name runme -okdir rm {} \;

< rm ... ./bin/runme >

?

You can also be careful to specify the full path of the command you want to use to avoid any problems with fake commands like the one above.

$ find . -name runme -execdir /bin/rm {} \;

The find command has many options besides default printing, some of which can make your file search more precise, but it's always good to be cautious.

Thank you for reading, the above is "Linux under the use of the find command" of the content, after the study of this article, I believe we have a deeper understanding of the use of the Linux find command, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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