echo 'file1 file2' | xargsDemonstrates default behavior which echoes input arguments to stdout.
Builds and runs command lines from standard input — the glue for batch operations and parallel jobs in pipelines.
sudo apt install findutilsecho 'file1 file2' | xargsDemonstrates default behavior which echoes input arguments to stdout.
seq 5 | xargs echoTakes a list of numbers from stdin and prints them as a single line of arguments.
cat files.txt | xargs catReads filenames from a text file and passes them to cat to display content.
xargs -a inputs.txt echoReads arguments directly from a file instead of standard input.
find . -name '*.tmp' | xargs -p rmPrompts the user for confirmation before executing each command.
find . -name '*.log' | xargs -t rmPrints the full command line to stderr before executing it (verbose mode).
find . -name '*.nonexistent' | xargs -r rmPrevents the command from running if standard input is empty.
ls -1 | xargs -L 1 echo 'File:'Forces xargs to treat each line of input as a distinct argument unit.
seq 100 | xargs -E 50 echoStops processing input immediately when the string '50' is encountered.
seq 10 | xargs -n 1 -P 2 sleep 1Runs commands in parallel using up to 2 concurrent processes.
find . -name '*.jpg' -print0 | xargs -0 -n 1 -P 4 convert -resize 50%Batch processes image resizing using 4 parallel threads for performance.
cat urls.txt | xargs -n 1 -P 10 curl -ODownloads files from a list of URLs using 10 concurrent connections.
seq 100 | xargs -P 0 -n 1 echoSpawns as many processes as possible (unlimited) to handle the input.
find /var/log -name '*.log' | xargs tar -cvf logs.tarArchives a list of found log files into a single tarball.
cat files.txt | xargs -I {} cp {} /backup/{}Copies files listed in a text file to a backup directory individually.
ls *.conf | xargs -I {} cp {} {}.backupCreates a backup copy of every configuration file in the current directory.
cat folders.txt | xargs mkdir -pCreates a directory structure based on a list of names.
find . -name '*.sh' | xargs -I {} sh -c 'chmod +x {}; echo Executable: {}'Executes multiple commands per argument by invoking a shell explicitly.
find /var/www/html -type f | xargs sha256sum > baseline_hashes.txtGenerates SHA256 hashes for all web files to create an integrity baseline.
grep -l 'malware_signature' /var/log/* | xargs -I {} cp {} /quarantine/Identifies log files containing a signature and copies them to a quarantine folder.
cat suspicious_ips.txt | xargs -I {} grep {} /var/log/auth.logSearches authentication logs for activity related to a list of suspect IPs.
find . -name '*.txt' -print0 | xargs -0 -I {} sh -c 'cat {} >> combined.log; echo "---EOF---" >> combined.log'Concatenates files safely while injecting a custom separator between content.
find . -name '*.gz' | xargs -n 1 -P 4 gunzipDecompresses all gzip files in the directory using 4 parallel workers.
cat list.txt | xargs -d '\n' -n 1 echoExplicitly sets newline as delimiter to handle items containing spaces correctly without null termination.
cat buckets.txt | xargs -I {} echo 'aws s3 ls s3://{}'Constructs AWS CLI commands to list contents of multiple S3 buckets.
kubectl get pods -o name | xargs -n 1 kubectl deleteDeletes all pods in the current namespace by passing names to delete command.
seq 1000 | xargs -n 50 -x echoForces exit if the constructed command line exceeds the system size limit.
ls | xargs -n 1 -I {} sh -c 'echo {} | xargs echo nested:'Demonstrates invoking xargs inside a command executed by xargs.
find . -name '*.txt' | xargs -t -n 1 touchupdates timestamps on files while printing the exact command being run for verification.
seq 10 | xargs -P 2 -n 1 --process-slot-var=SLOT sh -c 'echo Running on slot $SLOT'Exposes the parallel process slot ID as an environment variable to the child process.
cat raw_data.txt | tr ' ' '\n' | xargs -n 1 echoPreprocesses space-separated data into newlines before passing to xargs.
ls *.jpg | xargs -n 1 -I {} bash -c 'mv "$1" "${1%.jpg}.png"' _ {}Uses bash parameter expansion inside xargs to rename file extensions.
find / -perm -4000 -print0 2>/dev/null | xargs -0 ls -ldLocates and details all SUID executables on the system safely.
cat artifact_list.txt | xargs -I {} tar -rvf collection.tar {}Appends specific files listed in a text file to an existing tar archive.
cat servers.txt | xargs -n 1 -I {} ssh {} 'uptime'Runs the uptime command sequentially on a list of remote servers.
cat servers.txt | xargs -P 5 -n 1 -I {} ssh {} 'uname -a'Runs commands on multiple remote servers in parallel to save time.
cat tables.txt | xargs -I {} echo 'OPTIMIZE TABLE {};' | mysql -u root my_dbConstructs SQL queries for a list of tables and pipes them to the MySQL client.
cat packages.txt | xargs apt-get install -yInstalls a list of software packages from a file in a single transaction.
find src/ -name '*.js' | xargs eslintRuns a linter against all JavaScript files found in the source directory.
echo ' padded ' | xargsTrims leading and trailing whitespace from the input string.
ls | xargs -p -n 1 echo deletingSimulates a delete operation where the user must approve every single file.
find . -maxdepth 1 -type d | xargs -I {} du -sh {}Calculates the disk usage summary for every subdirectory in the current path.
ls *.tar.gz | xargs -n 1 tar -xzvfExtracts multiple tar.gz archives sequentially.
pgrep java | xargs -r kill -SIGTERMSends a graceful termination signal to all Java processes.
find . -name '*.py' -print0 | xargs -0 grep -n 'TODO'Searches for TODO comments inside all Python files and prints line numbers.
ls *.bak | xargs -I {} sh -c 'diff {} ${0%.bak}' {}Compares .bak files against their original counterparts using diff.
cat endpoints.txt | xargs -n 1 -I {} curl -s -o /dev/null -w '%{http_code} %{url_effective}\n' {}Checks the HTTP status code for a list of endpoints.
cat terminated_staff.txt | xargs -I {} sh -c 'userdel {}; rm -rf /home/{}'Removes user accounts and their home directories based on a list.
find . -name '*.conf' -print0 | xargs -0 -I {} cp --parents {} /backup/conf/Copies files preserving their directory structure to a backup location.
find . -name '*.jpg' | xargs -n 1 mogrify -stripRemoves EXIF metadata from all JPG images in batch.
cat modules.txt | xargs -n 1 modprobeLoads a list of kernel modules.
apt list --upgradable 2>/dev/null | cut -d/ -f1 | xargs apt-get install -yExtracts upgradable package names and pipes them to the install command.
find . -type f -size 0 -print0 | xargs -0 rmRemoves all files with zero bytes size safely.
find /var/log -name '*.log' | xargs -I {} mv {} {}.oldRenames all active log files to an archived extension.
find /etc/ssl -name '*.pem' | xargs -I {} openssl x509 -in {} -noout -enddateChecks the expiration date of all SSL certificates found in the directory.
find /tmp -user root -print0 | xargs -0 ls -laInspects files owned by root in temporary directories which may indicate compromise.
find . -name 'important.txt' | xargs chattr +iSets the immutable flag on specific files to prevent deletion or modification.
docker ps -a -f status=exited -q | xargs -r docker rmRemoves only Docker containers that have exited.
docker images -f dangling=true -q | xargs -r docker rmiDeletes dangling Docker images that are not tagged.
cat words.txt | xargs -n 1 | sort | uniqNormalizes a text file into a sorted list of unique words.
ls | xargs | sed 's/ /,/g'Converts a list of files into a comma-separated string suitable for arrays.
seq 1 100 | xargs -I {} touch file_{}.txtRapidly creates 100 dummy files with sequential naming.
seq 5 | xargs -n 1 -I {} sh -c 'sleep 1; echo waited {}'Introduces a delay between the execution of each command.
find /var/www -type d -print0 | xargs -0 chown www-data:www-dataChanges ownership of all directories in a tree safely.
find /bin -type f -ctime -1 | xargs ls -lIdentifies system binaries that have been changed in the last 24 hours.
find /etc/nginx -name '*.conf' | xargs -n 1 nginx -t -cValidates the syntax of individual Nginx configuration files.
cat checksums.sha256 | xargs -n 2 sh -c 'echo "$1 $2" | sha256sum -c -'Verifies file integrity using a list of checksums and filenames.
find . -type l -xtype l -print0 | xargs -0 rmFinds and removes broken symbolic links.
find /var/log -type f | xargs -P 4 grep 'ERROR'Greps through logs in parallel to speed up error finding.
cat blacklisted_ips.txt | xargs -I {} iptables -A INPUT -s {} -j DROPAdds firewall rules to drop traffic from a list of IP addresses.
cat keys.txt | xargs -I {} aws kms schedule-key-deletion --key-id {}Schedules a list of AWS KMS keys for deletion.
cat data.json | jq -r '.[] .id' | xargs echo IDs:Extracts IDs from a JSON file and formats them into a single line.
kubectl get pods -l app=web -o name | xargs -n 1 -P 3 kubectl logsFetches logs from multiple pods matching a label in parallel.
xargs -a params.txt -L 1 commandReads arguments from a file line-by-line without using pipes.
ls | xargs -I {} bash -c 'echo "$1"' -- {}Passes arguments to a subshell securely using positional parameters.
find . -name 'temp*' -print0 | xargs -0 -n 1000 rmDeletes huge numbers of files in batches of 1000 to avoid argument list too long errors.
seq 100 | xargs -P $(nproc) -n 1 echoDynamically sets the number of parallel processes based on available CPU cores.
find . -name '*.db' | xargs -I {} flock {} echo 'Locked {}'Uses flock to ensure exclusive access to files before processing.
find . -maxdepth 1 -name 'xargs_test*' -print0 | xargs -0 -p rmSafely prompts to clean up any test files created during this workflow session.
Searches the directory tree by name, type, size, time, owner or permissions — and runs actions on matches.
Searches text for lines matching a pattern, with regular expressions, recursion and context.
A pattern-scanning language for column-based text: extract fields, compute totals and reformat output.