Click here for the video (click the image to go to youtube) [] watch? v = BnwD2rX9kv8)
You can read a list from standard input or a file and pass it as an argument to the command you want to execute! By the way, the reading is generally "X-Agus". Since it is an abbreviation for arguments, it is taken from arguments (probably)
appendix
Prepare two files.
[bitnami@ /tmp/com_xargs]$ ls
aaa.txt bbb.txt
The contents are like this
[bitnami@ /tmp/com_xargs]$ cat aaa.txt bbb.txt
asdf
qwer
34
qweriu
qweuf
werpoi
For example, try typing a command like this.
[bitnami@ /tmp/com_xargs]$ ls | xargs wc
4 3 14 aaa.txt
3 3 20 bbb.txt
7 6 34 total
This is equivalent to typing the wc command on aaa.txt and bbb.txt. That is, "you can pass the result of ls to the wc command"
Let's check what kind of command is being executed with the -p option.
[bitnami@ /tmp/com_xargs]$ ls | xargs -p wc
wc aaa.txt bbb.txt ?...
As you can see, it says "wc aaa.txt bbb.txt? ...". You can see that you can pass the result of ls as an argument of the wc command. If you enter y here and press enter, it will be executed. (The -p option is convenient for debugging, so I definitely want to remember it)
By the way, if you are depressed without using xargs, this will happen.
[bitnami@ /tmp/com_xargs]$ ls | wc
2 2 16
What this means is that you can think of it as passing the following result directly to the wc command (that is, it is easy to think of it as a file written as aaa.txt and bbb.txt).
(By the way, the meaning of the wc command is the number of lines, the number of words, the number of bytes from the left)
[bitnami@ /tmp/com_xargs]$ ls | cat
aaa.txt
bbb.txt
Recommended Posts