Difference between revisions of "Xargs"
From Notes_Wiki
(Created page with "<yambe:breadcrumb>Shell scripting</yambe:breadcrumb> =xargs= '<tt>xargs</tt>' is very useful for running some command using single line from input at a time as parameter. For...") |
m |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Main_Page|Home]] > [[Shell scripting]] > [[Xargs|xargs]] | |||
'<tt>xargs</tt>' is very useful for running some command using single line from input at a time as parameter. For example to compress all files using gzip in a folder one can use: | '<tt>xargs</tt>' is very useful for running some command using single line from input at a time as parameter. For example to compress all files using gzip in a folder one can use: | ||
Line 12: | Line 11: | ||
gzip c.txt | gzip c.txt | ||
</pre> | </pre> | ||
If the argument is not expected at end of command then an input pattern can be specified with -I (such as {}) which can be replaced with filename. For example to move all files that start with digit to a folder temp use: | |||
<pre> | |||
ls -1 | grep '^[0-9].*' | xargs -I {} mv {} temp | |||
</pre> | |||
[[Main_Page|Home]] > [[Shell scripting]] > [[Xargs|xargs]] |
Latest revision as of 13:37, 7 April 2022
Home > Shell scripting > xargs
'xargs' is very useful for running some command using single line from input at a time as parameter. For example to compress all files using gzip in a folder one can use:
ls -1 | xargs gzip
In this case if the folder has three files 'a.txt', 'b.txt' and 'c.txt' then following three commands would run due to xargs command above:
gzip a.txt gzip b.txt gzip c.txt
If the argument is not expected at end of command then an input pattern can be specified with -I (such as {}) which can be replaced with filename. For example to move all files that start with digit to a folder temp use:
ls -1 | grep '^[0-9].*' | xargs -I {} mv {} temp
Home > Shell scripting > xargs