$XARGSコマンド

3097 ワード

xragsの簡単な使用
linuxとunixのコマンドにはパラメータがあり、標準入力stdinを直接パラメータとして使用できるコマンドもあります.次の例です.

#    ck.log    gomyck    
$ cat /usr/share/gomyck/ck.log | grep gomyck

grepコマンドの説明は次のとおりです.
DESCRIPTION
   grep  searches  the  named  input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is
   given as file name) for lines containing a match to the given PATTERN.  By default, grep prints the matching lines.

   In addition, two variant programs egrep and fgrep are available.  egrep is the same as grep -E.  fgrep is  the  same
   as  grep -F.   Direct  invocation  as  either  egrep  or  fgrep  is  deprecated, but is provided to allow historical
   applications that rely on them to run unmodified.

grepは標準入力を受け入れるコマンドであることがわかります
しかし、一部のコマンドは標準入力を受け入れることができず、パイプ文字が機能しなくなり、コマンドラインにパラメータを入力するしかありません.

#   
$ tail -n 10 ck.log | echo

上記コマンドは出力がなく、echoがパラメータとして標準入力を受け入れていないことがわかります
xargsの使用
xargsの役割は標準入力をコマンドラインパラメータに変換することであるため、一般的にxargsは常にパイプシンボル|と組み合わせて使用される.
$ tail -n 10 ck.log | xargs echo

使用方法:xargs[-options][command]
xargsのデフォルトcommandはechoです
$ xargs 
$ hello world 
# ctrl + d
# echo
$ hello world

xargsの説明
DESCRIPTION
     The xargs utility reads space, tab, newline and end-of-file delimited strings from
     the standard input and executes utility with the strings as arguments.

     Any arguments specified on the command line are given to utility upon each invoca-
     tion, followed by some number of the arguments read from the standard input of
     xargs.  The utility is repeatedly executed until standard input is exhausted.

     Spaces, tabs and newlines may be embedded in arguments using single (`` ' '') or
     double (``"'') quotes or backslashes (``\'').  Single quotes escape all non-single
     quote characters, excluding newlines, up to the matching single quote.  Double
     quotes escape all non-double quote characters, excluding newlines, up to the
     matching double quote.  Any single character, including newlines, may be escaped
     by a backslash.

xargsのデフォルトの規則は、指定されたコマンドのパラメータとして使用される文字列をスペースtab改行文字の末尾で区切るか、-dパラメータを使用して区切る文字を指定できます.

$ echo "gomyck1 gomyck2 gomyck3" | xargs mkdir

# echo -e              \t
$ echo -e "gomyck1\tgomyck2\tgomyck3" | xargs -d "\t" mkdir

# xargs -p         ,    y         
$ echo -e "gomyck1\tgomyck2\tgomyck3" | xargs -d -p "\t" mkdir

# xargs -t       ,    
$ echo -e "gomyck1\tgomyck2\tgomyck3" | xargs -d -t "\t" mkdir

# find -print0        null   , xargs -0   null     
$ find / -name etc  -print0 | xargs -0 echo

#     ,       param     , sh -c      
$ echo /usr/share/gomyck/ck.log | xargs -I param sh -c 'echo param; rm -rf param' 

その他の知識点
VMware Workstationでは、デフォルトで3つの仮想スイッチVMnet 0がブリッジに使用され、VMnet 1はホストネットワークのみに使用され、VMnet 8はNATに使用されます.
個人ブログをクリックして