Xargs for linux commands

Source: Internet
Author: User

Linux Command play xargs we can use pipelines to redirect the standard output of one command to the standard output of another command, but some commands
Xargs is used to receive data only in the form of command line parameters, but not through stdin. Xargs should follow the pipeline operator. 1. Convert multiple rows to a single row and convert a single row to multiple rows. [Root @ localhost desktop] # cat show.txt wangHunan Chenzhou123456 zookeeper [root @ localhost desktop] # cat show.txt | xargswang Hunan Chenzhou 123456 li Guangzhou Zhuhai 654321 [root @ localhost desktop] # | xargs-n 4 wang Hunan Chenzhou 123456li Guangzhou Zhuhai 654321 2. -d option [root @ localhost desktop] # cat show.txt | xargs-d "\ n" wang Hunan Chenzhou 123456 li Guangzhou Zhuhai 654321 3. read stdi N. Pass the formatting parameters to the Command (one or more) [root @ localhost desktop] # vi ceshi. sh #! /Bin/bashecho $ * 'OK' [root @ localhost desktop] # chmod + x ceshi. sh [root @ localhost desktop] # cat show.txt | xargs-n 1. /ceshi. sh wangOKHunanOKChenzhouOK123456OKliOKGuangzhouOKZhuhaiOK654321OK [root @ localhost desktop] # cat show.txt | xargs. /ceshi. sh wang Hunan Cheng Zhou 123456 li Guangzhou Zhuhai 654321OK 4. pass complex command parameters (variable or immutable parameters)-I option to replace the character [root @ localhost desktop] # cat show.txt | xargs-I {}. /ceshi. sh-p {}-1-p wang-1OK-p Hu Nan Chenzhou-1OK-p 123456-1OK-p li-1OK-p Guangzhou Zhuhai-1OK-p 654321-1OK 5. use xargs with other commands [root @ localhost desktop] # file * | grep show | cut-d ": "-f1 | xargs wc-l8 show.txt [root @ localhost desktop] $ file * | grep show | cut-d ": "-f1 | xargs-t wc-lwc-l show.txt 8 show.txt-t option, print the command first, then run [root @ localhost desktop] # file * | grep show | cut-d ": "-f1 | xargs vi open the vi editor [root @ localhost desktop] # file * | grep s How | cut-d ":"-f1 | xargs-t-I mv {}{}. bakmv show.txt. modify the bak name [root @ localhost desktop] $ find. -name "*. txt "-type f-print0 | xargs-0 tar-zcvf text.tar.gz search for all txt files and compress them. In fact, xargs can be connected to many commands and you will find them very interesting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.