A
cd ..
Tools

Xargs Command Builder

Build and execute commands from standard input with xargs.

2025-09-30
xargs, pipes, linux

Basic usage

echo "file1 file2 file3" | xargs ls -l

Delete files from list

cat files_to_delete.txt | xargs rm

One argument per command

echo "1 2 3" | xargs -n1 echo "Number:"

Execute command for each line

cat urls.txt | xargs -I {} curl -O {}

Parallel execution

Run 4 commands in parallel:

cat urls.txt | xargs -P 4 -I {} curl -O {}

Find and delete

find . -name "*.tmp" | xargs rm

Safer find and delete (handle spaces)

find . -name "*.tmp" -print0 | xargs -0 rm

Create backup of files

ls *.txt | xargs -I {} cp {} {}.bak

Download multiple files

cat urls.txt | xargs -n 1 -P 5 wget

Convert images

ls *.jpg | xargs -I {} convert {} -resize 50% resized/{}

Grep in multiple files

find . -name "*.log" | xargs grep "ERROR"

Count lines in files

find . -name "*.js" -print0 | xargs -0 wc -l

Compress files

ls *.txt | xargs -I {} gzip {}

Ask for confirmation

find . -name "*.tmp" | xargs -p rm

Specify delimiter

echo "file1,file2,file3" | xargs -d',' ls -l

Create directories

cat folders.txt | xargs mkdir -p

Change permissions

find . -name "*.sh" -print0 | xargs -0 chmod +x

Docker cleanup

docker ps -a -q | xargs docker rm

Git operations

git branch -r | grep -v '\->' | xargs -I {} git branch --track {} origin/{}

Process multiple arguments

echo "dir1 dir2 dir3" | xargs -n1 -I {} sh -c 'cd {} && npm install'

Combine with grep

grep -rl "TODO" . | xargs sed -i 's/TODO/DONE/g'

Show commands before executing

ls *.txt | xargs -t rm

Maximum line length

find . -type f | xargs -s 1000 ls -l

Was this useful?

Share with your team

Browse More