In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use pipeline |, xargs and exec in shell. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Command line arguments: the getopt () function is used to parse command line arguments
Standard input: functions such as scanf () / gets () are used to obtain standard input
Pipeline |
Passing the output of the previous command as standard input to subsequent commands will not use any intermediate files or buffers.
Xargs
Pass the output of the previous command as a command line argument to the following command.
> batch create file pi@raspberrypi:~/test $touch {1.. 9} .txtpi @ raspberrypi:~/test $ls1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt > modify pi@raspberrypi:~/test $ls * .txt | xargs-N1-I {} mv {} _ bakpi@raspberrypi:~/test $ls1.txt_bak 2.txt_bak 3.txt_bak 4.txt_bak 5.txt_bak 6.txt_bak 7.txt_bak 8.txt_bak 9.txt_bak
Exec
The-exec parameter in the find command passes the query results to subsequent commands through command-line arguments.
-exec differs from xargs in that-exec passes the results to subsequent commands one by one, and subsequent commands are executed one by one. Xargs passes all the results as a list to the following command, which executes the parameter string at once, and you can view the complete command to be executed through xargs-p ls-l.
Pi@raspberrypi:~/test $find. -name "* txt*" | xargs-p ls-l rm ls-l rm. / 4.txt. / 9.txt. / 1.txt. / 6.txt. / 7.txt. / 8.txt. / 3.txt. / 5.txt?.
At present, the known commands that can only read command line parameters are: ls, rm.
By analyzing the difference between-exec and xargs, we will find that if you use-exec+ls-lrt in find, the list is not sorted. If you want to sort, you can use xargs+ls-lrt, but pay attention to the difference between-exec and xargs.
This is the end of the article on "how to use pipes in shell |, xargs and exec". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.