In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about why we should use the Linux find command cautiously. Many people may not understand it very well. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something from this article.
A friend recently reminded me that there is a useful option to run the find command more carefully:-ok. Except for one important difference, it works like-exec, which causes the find command to request permissions before performing a specified operation.
Here's an example. If you use the find command to find files and delete them, you may use the following command:
$find. -name runme-exec rm {}\
Any files named "runme" in the current directory and its subdirectories will be deleted immediately-of course, you must have permission to delete them. Use the-ok option instead, and you'll see something like this, but the find command will request permission before deleting the file. The answer y means "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 can be used to modify the find command behavior and possibly make it more controllable is-execdir. "- exec runs any specified command, while-execdir runs the specified command from the directory where the file is located, not 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 bin
Total 12
-rmurx-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/ls
Echo Running the $0 file
$cat bin/rm
Echo This is an imposter rm command
The-okdir option also requests permission
To be more cautious, you can use the-okdir option. Similar to-ok, this option requests permission to run the command.
$find. -name runme-okdir rm {}\
< rm ... ./bin/runme >?
You can also carefully specify the full path to 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 in addition to default printing, some of which can make your file search more accurate, but it's always good to be careful.
After reading the above, do you have any further understanding of why you should use the Linux find command cautiously? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.