Skip to content

Commit

Permalink
Create xargs.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lwindolf authored Jan 10, 2024
1 parent 3d399b3 commit e836438
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cheat-sheet/Scripting/xargs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Usage

`xargs` is about converting input lines to parameters

cat pet-names.txt | xargs # All names in a line
cat pet-names.txt | xargs -2 # Only 2 names per line

find . -print0 | xargs -0 # Only safe way to iterate file paths

When processing input xargs removes quotes. To prevent this use `-d$'\n'`

<some command> | xargs -d$'\n' <params>


Use `-I` to define a replace pattern in the command specified where you can
insert the passing value multiple times. For example construct a mv command
that renames files:

find . -print0 | xargs -0 -I{} echo mv {} {}.old

0 comments on commit e836438

Please sign in to comment.