{"tool":"xargs","name":"xargs","description":"Builds and runs command lines from standard input — the glue for batch operations and parallel jobs in pipelines.","tags":["pipelines","batch","parallel"],"homepage":"https://www.gnu.org/software/findutils/","docs":"https://man7.org/linux/man-pages/man1/xargs.1.html","install":{"apt":"sudo apt install findutils"},"related":["find","grep","awk"],"total_commands":105,"commands":[{"id":1,"category":"Basic Syntax","command":"echo 'file1 file2' | xargs","example":"echo 'file1 file2' | xargs","explanation":"Demonstrates default behavior which echoes input arguments to stdout."},{"id":2,"category":"Basic Syntax","command":"seq 5 | xargs echo","example":"seq 5 | xargs echo","explanation":"Takes a list of numbers from stdin and prints them as a single line of arguments."},{"id":3,"category":"Basic Syntax","command":"cat files.txt | xargs cat","example":"cat files.txt | xargs cat","explanation":"Reads filenames from a text file and passes them to cat to display content."},{"id":4,"category":"Argument Limiting","command":"seq 10 | xargs -n 1 echo","example":"seq 10 | xargs -n 1 echo","explanation":"Limits execution to one argument per command line invocation."},{"id":5,"category":"Argument Limiting","command":"seq 10 | xargs -n 2 echo","example":"seq 10 | xargs -n 2 echo","explanation":"Groups input into pairs of two arguments per command execution."},{"id":6,"category":"Delimiter Control","command":"echo '1,2,3,4' | xargs -d , echo","example":"echo '1,2,3,4' | xargs -d , echo","explanation":"Uses a comma as a custom delimiter instead of default whitespace."},{"id":7,"category":"Delimiter Control","command":"echo 'user1:user2:user3' | xargs -d : -n 1 echo","example":"echo 'user1:user2:user3' | xargs -d : -n 1 echo","explanation":"Splits input by colon delimiter and processes each item individually."},{"id":8,"category":"Input Management","command":"xargs -a inputs.txt echo","example":"xargs -a inputs.txt echo","explanation":"Reads arguments directly from a file instead of standard input."},{"id":9,"category":"Execution Safety","command":"find . -name '*.tmp' | xargs -p rm","example":"find . -name '*.tmp' | xargs -p rm","explanation":"Prompts the user for confirmation before executing each command."},{"id":10,"category":"Execution Safety","command":"find . -name '*.log' | xargs -t rm","example":"find . -name '*.log' | xargs -t rm","explanation":"Prints the full command line to stderr before executing it (verbose mode)."},{"id":11,"category":"Execution Safety","command":"find . -name '*.nonexistent' | xargs -r rm","example":"find . -name '*.nonexistent' | xargs -r rm","explanation":"Prevents the command from running if standard input is empty."},{"id":12,"category":"Argument Replacement","command":"find . -name '*.txt' | xargs -I {} mv {} {}.bak","example":"find . -name '*.txt' | xargs -I {} mv {} {}.bak","explanation":"Uses {} as a placeholder to insert the argument into specific positions in the command."},{"id":13,"category":"Argument Replacement","command":"seq 5 | xargs -I % echo 'Processing ID: %'","example":"seq 5 | xargs -I % echo 'Processing ID: %'","explanation":"Uses a custom placeholder symbol (%) to format output strings."},{"id":14,"category":"Line Based Processing","command":"ls -1 | xargs -L 1 echo 'File:'","example":"ls -1 | xargs -L 1 echo 'File:'","explanation":"Forces xargs to treat each line of input as a distinct argument unit."},{"id":15,"category":"Null Termination","command":"find . -name '*.png' -print0 | xargs -0 rm","example":"find . -name '*.png' -print0 | xargs -0 rm","explanation":"Handles filenames with spaces or newlines correctly using null character delimiters."},{"id":16,"category":"Null Termination","command":"grep -rZ 'error' . | xargs -0 rm","example":"grep -rZ 'error' . | xargs -0 rm","explanation":"Processes null-terminated output from grep for safe file handling."},{"id":17,"category":"Command Size Limits","command":"seq 1000 | xargs -s 2048 echo","example":"seq 1000 | xargs -s 2048 echo","explanation":"Limits the maximum size of the command line to 2048 characters."},{"id":18,"category":"Command Size Limits","command":"find . -type f | xargs --show-limits","example":"find . -type f | xargs --show-limits","explanation":"Displays the operating system limits on command-line length and buffers."},{"id":19,"category":"Process Control","command":"seq 100 | xargs -E 50 echo","example":"seq 100 | xargs -E 50 echo","explanation":"Stops processing input immediately when the string '50' is encountered."},{"id":20,"category":"Parallel Execution","command":"seq 10 | xargs -n 1 -P 2 sleep 1","example":"seq 10 | xargs -n 1 -P 2 sleep 1","explanation":"Runs commands in parallel using up to 2 concurrent processes."},{"id":21,"category":"Parallel Execution","command":"find . -name '*.jpg' -print0 | xargs -0 -n 1 -P 4 convert -resize 50%","example":"find . -name '*.jpg' -print0 | xargs -0 -n 1 -P 4 convert -resize 50%","explanation":"Batch processes image resizing using 4 parallel threads for performance."},{"id":22,"category":"Parallel Execution","command":"cat urls.txt | xargs -n 1 -P 10 curl -O","example":"cat urls.txt | xargs -n 1 -P 10 curl -O","explanation":"Downloads files from a list of URLs using 10 concurrent connections."},{"id":23,"category":"Parallel Execution","command":"seq 100 | xargs -P 0 -n 1 echo","example":"seq 100 | xargs -P 0 -n 1 echo","explanation":"Spawns as many processes as possible (unlimited) to handle the input."},{"id":24,"category":"File Operations","command":"find /var/log -name '*.log' | xargs tar -cvf logs.tar","example":"find /var/log -name '*.log' | xargs tar -cvf logs.tar","explanation":"Archives a list of found log files into a single tarball."},{"id":25,"category":"File Operations","command":"cat files.txt | xargs -I {} cp {} /backup/{}","example":"cat files.txt | xargs -I {} cp {} /backup/{}","explanation":"Copies files listed in a text file to a backup directory individually."},{"id":26,"category":"File Operations","command":"ls *.conf | xargs -I {} cp {} {}.backup","example":"ls *.conf | xargs -I {} cp {} {}.backup","explanation":"Creates a backup copy of every configuration file in the current directory."},{"id":27,"category":"Directory Operations","command":"cat folders.txt | xargs mkdir -p","example":"cat folders.txt | xargs mkdir -p","explanation":"Creates a directory structure based on a list of names."},{"id":28,"category":"System Administration","command":"find /home -name 'id_rsa' | xargs chmod 600","example":"find /home -name 'id_rsa' | xargs chmod 600","explanation":"Fixes permissions on SSH private keys found in home directories."},{"id":29,"category":"System Administration","command":"cat users.txt | xargs -n 1 useradd","example":"cat users.txt | xargs -n 1 useradd","explanation":"Bulk creates users from a text file list."},{"id":30,"category":"System Administration","command":"cat groups.txt | xargs -I {} groupadd {}","example":"cat groups.txt | xargs -I {} groupadd {}","explanation":"Bulk adds system groups from a file using replacement logic."},{"id":31,"category":"Data Processing","command":"find . -type f -name '*.csv' | xargs cat | wc -l","example":"find . -type f -name '*.csv' | xargs cat | wc -l","explanation":"Counts the total lines across all CSV files in a directory tree."},{"id":32,"category":"Data Processing","command":"ls | xargs -n 1 -I {} sh -c 'echo -n {}; echo -n \" \"; wc -c < {}'","example":"ls | xargs -n 1 -I {} sh -c 'echo -n {}; echo -n \" \"; wc -c < {}'","explanation":"Uses a subshell to print the filename and its byte count on the same line."},{"id":33,"category":"Complex Commands","command":"find . -name '*.sh' | xargs -I {} sh -c 'chmod +x {}; echo Executable: {}'","example":"find . -name '*.sh' | xargs -I {} sh -c 'chmod +x {}; echo Executable: {}'","explanation":"Executes multiple commands per argument by invoking a shell explicitly."},{"id":34,"category":"Integration","command":"docker ps -q | xargs -r docker stop","example":"docker ps -q | xargs -r docker stop","explanation":"Stops all running Docker containers, doing nothing if none are running."},{"id":35,"category":"Integration","command":"docker images -q | xargs -r docker rmi","example":"docker images -q | xargs -r docker rmi","explanation":"Removes all Docker images found on the system."},{"id":36,"category":"Integration","command":"git ls-files | xargs wc -l","example":"git ls-files | xargs wc -l","explanation":"Counts lines of code for all files tracked by git."},{"id":37,"category":"Network Automation","command":"cat hosts.txt | xargs -n 1 -I {} ping -c 1 {}","example":"cat hosts.txt | xargs -n 1 -I {} ping -c 1 {}","explanation":"Pings a list of hosts once each to check reachability."},{"id":38,"category":"Network Automation","command":"cat domains.txt | xargs -n 1 host","example":"cat domains.txt | xargs -n 1 host","explanation":"Performs DNS lookups for a batch list of domains."},{"id":39,"category":"SOC Automation","command":"find /var/www/html -type f | xargs sha256sum > baseline_hashes.txt","example":"find /var/www/html -type f | xargs sha256sum > baseline_hashes.txt","explanation":"Generates SHA256 hashes for all web files to create an integrity baseline."},{"id":40,"category":"SOC Automation","command":"grep -l 'malware_signature' /var/log/* | xargs -I {} cp {} /quarantine/","example":"grep -l 'malware_signature' /var/log/* | xargs -I {} cp {} /quarantine/","explanation":"Identifies log files containing a signature and copies them to a quarantine folder."},{"id":41,"category":"SOC Automation","command":"cat suspicious_ips.txt | xargs -I {} grep {} /var/log/auth.log","example":"cat suspicious_ips.txt | xargs -I {} grep {} /var/log/auth.log","explanation":"Searches authentication logs for activity related to a list of suspect IPs."},{"id":42,"category":"Blue Team Validation","command":"find /etc -type f -perm -o+w | xargs ls -ld","example":"find /etc -type f -perm -o+w | xargs ls -ld","explanation":"Lists details of any files in /etc that are world-writable for audit purposes."},{"id":43,"category":"Blue Team Validation","command":"cat users.txt | xargs -I {} chage -l {}","example":"cat users.txt | xargs -I {} chage -l {}","explanation":"Checks password expiry information for a specific list of users."},{"id":44,"category":"Incident Response","command":"pgrep -u malicious_user | xargs -r kill -9","example":"pgrep -u malicious_user | xargs -r kill -9","explanation":"Force kills all processes owned by a specific malicious user account."},{"id":45,"category":"Incident Response","command":"lsof -t -i :8080 | xargs -r kill","example":"lsof -t -i :8080 | xargs -r kill","explanation":"Terminates any process currently listening on port 8080."},{"id":46,"category":"Advanced Workflow","command":"find . -name '*.txt' -print0 | xargs -0 -I {} sh -c 'cat {} >> combined.log; echo \"---EOF---\" >> combined.log'","example":"find . -name '*.txt' -print0 | xargs -0 -I {} sh -c 'cat {} >> combined.log; echo \"---EOF---\" >> combined.log'","explanation":"Concatenates files safely while injecting a custom separator between content."},{"id":47,"category":"Advanced Workflow","command":"find . -name '*.gz' | xargs -n 1 -P 4 gunzip","example":"find . -name '*.gz' | xargs -n 1 -P 4 gunzip","explanation":"Decompresses all gzip files in the directory using 4 parallel workers."},{"id":48,"category":"Advanced Workflow","command":"cat list.txt | xargs -d '\\n' -n 1 echo","example":"cat list.txt | xargs -d '\\n' -n 1 echo","explanation":"Explicitly sets newline as delimiter to handle items containing spaces correctly without null termination."},{"id":49,"category":"Cleanup","command":"find . -type d -empty -print0 | xargs -0 rmdir","example":"find . -type d -empty -print0 | xargs -0 rmdir","explanation":"Recursively removes empty directories safely using null delimiters."},{"id":50,"category":"Cleanup","command":"find /tmp -mtime +7 -print0 | xargs -0 rm -f","example":"find /tmp -mtime +7 -print0 | xargs -0 rm -f","explanation":"Deletes files in tmp that are older than 7 days using safe handling."},{"id":51,"category":"AWS/Cloud (Simulated)","command":"cat buckets.txt | xargs -I {} echo 'aws s3 ls s3://{}'","example":"cat buckets.txt | xargs -I {} echo 'aws s3 ls s3://{}'","explanation":"Constructs AWS CLI commands to list contents of multiple S3 buckets."},{"id":52,"category":"Kubernetes (Simulated)","command":"kubectl get pods -o name | xargs -n 1 kubectl delete","example":"kubectl get pods -o name | xargs -n 1 kubectl delete","explanation":"Deletes all pods in the current namespace by passing names to delete command."},{"id":53,"category":"Advanced Limits","command":"seq 1000 | xargs -n 50 -x echo","example":"seq 1000 | xargs -n 50 -x echo","explanation":"Forces exit if the constructed command line exceeds the system size limit."},{"id":54,"category":"Nested Xargs","command":"ls | xargs -n 1 -I {} sh -c 'echo {} | xargs echo nested:'","example":"ls | xargs -n 1 -I {} sh -c 'echo {} | xargs echo nested:'","explanation":"Demonstrates invoking xargs inside a command executed by xargs."},{"id":55,"category":"Debugging","command":"find . -name '*.txt' | xargs -t -n 1 touch","example":"find . -name '*.txt' | xargs -t -n 1 touch","explanation":"updates timestamps on files while printing the exact command being run for verification."},{"id":56,"category":"Process Info","command":"seq 10 | xargs -P 2 -n 1 --process-slot-var=SLOT sh -c 'echo Running on slot $SLOT'","example":"seq 10 | xargs -P 2 -n 1 --process-slot-var=SLOT sh -c 'echo Running on slot $SLOT'","explanation":"Exposes the parallel process slot ID as an environment variable to the child process."},{"id":57,"category":"Input Preprocessing","command":"cat raw_data.txt | tr ' ' '\\n' | xargs -n 1 echo","example":"cat raw_data.txt | tr ' ' '\\n' | xargs -n 1 echo","explanation":"Preprocesses space-separated data into newlines before passing to xargs."},{"id":58,"category":"Batch Renaming","command":"ls *.jpg | xargs -n 1 -I {} bash -c 'mv \"$1\" \"${1%.jpg}.png\"' _ {}","example":"ls *.jpg | xargs -n 1 -I {} bash -c 'mv \"$1\" \"${1%.jpg}.png\"' _ {}","explanation":"Uses bash parameter expansion inside xargs to rename file extensions."},{"id":59,"category":"Permissions Auditing","command":"find / -perm -4000 -print0 2>/dev/null | xargs -0 ls -ld","example":"find / -perm -4000 -print0 2>/dev/null | xargs -0 ls -ld","explanation":"Locates and details all SUID executables on the system safely."},{"id":60,"category":"Artifact Collection","command":"cat artifact_list.txt | xargs -I {} tar -rvf collection.tar {}","example":"cat artifact_list.txt | xargs -I {} tar -rvf collection.tar {}","explanation":"Appends specific files listed in a text file to an existing tar archive."},{"id":61,"category":"Remote Execution","command":"cat servers.txt | xargs -n 1 -I {} ssh {} 'uptime'","example":"cat servers.txt | xargs -n 1 -I {} ssh {} 'uptime'","explanation":"Runs the uptime command sequentially on a list of remote servers."},{"id":62,"category":"Remote Execution Parallel","command":"cat servers.txt | xargs -P 5 -n 1 -I {} ssh {} 'uname -a'","example":"cat servers.txt | xargs -P 5 -n 1 -I {} ssh {} 'uname -a'","explanation":"Runs commands on multiple remote servers in parallel to save time."},{"id":63,"category":"Database Maintenance","command":"cat tables.txt | xargs -I {} echo 'OPTIMIZE TABLE {};' | mysql -u root my_db","example":"cat tables.txt | xargs -I {} echo 'OPTIMIZE TABLE {};' | mysql -u root my_db","explanation":"Constructs SQL queries for a list of tables and pipes them to the MySQL client."},{"id":64,"category":"Dependency Management","command":"cat packages.txt | xargs apt-get install -y","example":"cat packages.txt | xargs apt-get install -y","explanation":"Installs a list of software packages from a file in a single transaction."},{"id":65,"category":"Code Quality","command":"find src/ -name '*.js' | xargs eslint","example":"find src/ -name '*.js' | xargs eslint","explanation":"Runs a linter against all JavaScript files found in the source directory."},{"id":66,"category":"String Manipulation","command":"echo '  padded  ' | xargs","example":"echo '  padded  ' | xargs","explanation":"Trims leading and trailing whitespace from the input string."},{"id":67,"category":"Interactive Filtering","command":"ls | xargs -p -n 1 echo deleting","example":"ls | xargs -p -n 1 echo deleting","explanation":"Simulates a delete operation where the user must approve every single file."},{"id":68,"category":"Disk Usage","command":"find . -maxdepth 1 -type d | xargs -I {} du -sh {}","example":"find . -maxdepth 1 -type d | xargs -I {} du -sh {}","explanation":"Calculates the disk usage summary for every subdirectory in the current path."},{"id":69,"category":"Archive Extraction","command":"ls *.tar.gz | xargs -n 1 tar -xzvf","example":"ls *.tar.gz | xargs -n 1 tar -xzvf","explanation":"Extracts multiple tar.gz archives sequentially."},{"id":70,"category":"Process Signals","command":"pgrep java | xargs -r kill -SIGTERM","example":"pgrep java | xargs -r kill -SIGTERM","explanation":"Sends a graceful termination signal to all Java processes."},{"id":71,"category":"File Content Search","command":"find . -name '*.py' -print0 | xargs -0 grep -n 'TODO'","example":"find . -name '*.py' -print0 | xargs -0 grep -n 'TODO'","explanation":"Searches for TODO comments inside all Python files and prints line numbers."},{"id":72,"category":"Batch Comparison","command":"ls *.bak | xargs -I {} sh -c 'diff {} ${0%.bak}' {}","example":"ls *.bak | xargs -I {} sh -c 'diff {} ${0%.bak}' {}","explanation":"Compares .bak files against their original counterparts using diff."},{"id":73,"category":"URL Testing","command":"cat endpoints.txt | xargs -n 1 -I {} curl -s -o /dev/null -w '%{http_code} %{url_effective}\\n' {}","example":"cat endpoints.txt | xargs -n 1 -I {} curl -s -o /dev/null -w '%{http_code} %{url_effective}\\n' {}","explanation":"Checks the HTTP status code for a list of endpoints."},{"id":74,"category":"User Cleanup","command":"cat terminated_staff.txt | xargs -I {} sh -c 'userdel {}; rm -rf /home/{}'","example":"cat terminated_staff.txt | xargs -I {} sh -c 'userdel {}; rm -rf /home/{}'","explanation":"Removes user accounts and their home directories based on a list."},{"id":75,"category":"Bulk Copy","command":"find . -name '*.conf' -print0 | xargs -0 -I {} cp --parents {} /backup/conf/","example":"find . -name '*.conf' -print0 | xargs -0 -I {} cp --parents {} /backup/conf/","explanation":"Copies files preserving their directory structure to a backup location."},{"id":76,"category":"Metadata Stripping","command":"find . -name '*.jpg' | xargs -n 1 mogrify -strip","example":"find . -name '*.jpg' | xargs -n 1 mogrify -strip","explanation":"Removes EXIF metadata from all JPG images in batch."},{"id":77,"category":"Module Management","command":"cat modules.txt | xargs -n 1 modprobe","example":"cat modules.txt | xargs -n 1 modprobe","explanation":"Loads a list of kernel modules."},{"id":78,"category":"System Updates","command":"apt list --upgradable 2>/dev/null | cut -d/ -f1 | xargs apt-get install -y","example":"apt list --upgradable 2>/dev/null | cut -d/ -f1 | xargs apt-get install -y","explanation":"Extracts upgradable package names and pipes them to the install command."},{"id":79,"category":"Empty File Cleanup","command":"find . -type f -size 0 -print0 | xargs -0 rm","example":"find . -type f -size 0 -print0 | xargs -0 rm","explanation":"Removes all files with zero bytes size safely."},{"id":80,"category":"Log Rotation Simulation","command":"find /var/log -name '*.log' | xargs -I {} mv {} {}.old","example":"find /var/log -name '*.log' | xargs -I {} mv {} {}.old","explanation":"Renames all active log files to an archived extension."},{"id":81,"category":"Certificate Auditing","command":"find /etc/ssl -name '*.pem' | xargs -I {} openssl x509 -in {} -noout -enddate","example":"find /etc/ssl -name '*.pem' | xargs -I {} openssl x509 -in {} -noout -enddate","explanation":"Checks the expiration date of all SSL certificates found in the directory."},{"id":82,"category":"Threat Hunting","command":"find /tmp -user root -print0 | xargs -0 ls -la","example":"find /tmp -user root -print0 | xargs -0 ls -la","explanation":"Inspects files owned by root in temporary directories which may indicate compromise."},{"id":83,"category":"Immutable Files","command":"find . -name 'important.txt' | xargs chattr +i","example":"find . -name 'important.txt' | xargs chattr +i","explanation":"Sets the immutable flag on specific files to prevent deletion or modification."},{"id":84,"category":"Container Cleanup","command":"docker ps -a -f status=exited -q | xargs -r docker rm","example":"docker ps -a -f status=exited -q | xargs -r docker rm","explanation":"Removes only Docker containers that have exited."},{"id":85,"category":"Orphaned Images","command":"docker images -f dangling=true -q | xargs -r docker rmi","example":"docker images -f dangling=true -q | xargs -r docker rmi","explanation":"Deletes dangling Docker images that are not tagged."},{"id":86,"category":"Text Transformation","command":"cat words.txt | xargs -n 1 | sort | uniq","example":"cat words.txt | xargs -n 1 | sort | uniq","explanation":"Normalizes a text file into a sorted list of unique words."},{"id":87,"category":"Variable Construction","command":"ls | xargs | sed 's/ /,/g'","example":"ls | xargs | sed 's/ /,/g'","explanation":"Converts a list of files into a comma-separated string suitable for arrays."},{"id":88,"category":"Mass Creation","command":"seq 1 100 | xargs -I {} touch file_{}.txt","example":"seq 1 100 | xargs -I {} touch file_{}.txt","explanation":"Rapidly creates 100 dummy files with sequential naming."},{"id":89,"category":"Wait Handling","command":"seq 5 | xargs -n 1 -I {} sh -c 'sleep 1; echo waited {}'","example":"seq 5 | xargs -n 1 -I {} sh -c 'sleep 1; echo waited {}'","explanation":"Introduces a delay between the execution of each command."},{"id":90,"category":"Recursive Ownership","command":"find /var/www -type d -print0 | xargs -0 chown www-data:www-data","example":"find /var/www -type d -print0 | xargs -0 chown www-data:www-data","explanation":"Changes ownership of all directories in a tree safely."},{"id":91,"category":"System Auditing","command":"find /bin -type f -ctime -1 | xargs ls -l","example":"find /bin -type f -ctime -1 | xargs ls -l","explanation":"Identifies system binaries that have been changed in the last 24 hours."},{"id":92,"category":"Config Validation","command":"find /etc/nginx -name '*.conf' | xargs -n 1 nginx -t -c","example":"find /etc/nginx -name '*.conf' | xargs -n 1 nginx -t -c","explanation":"Validates the syntax of individual Nginx configuration files."},{"id":93,"category":"Checksum Validation","command":"cat checksums.sha256 | xargs -n 2 sh -c 'echo \"$1  $2\" | sha256sum -c -'","example":"cat checksums.sha256 | xargs -n 2 sh -c 'echo \"$1  $2\" | sha256sum -c -'","explanation":"Verifies file integrity using a list of checksums and filenames."},{"id":94,"category":"Broken Links","command":"find . -type l -xtype l -print0 | xargs -0 rm","example":"find . -type l -xtype l -print0 | xargs -0 rm","explanation":"Finds and removes broken symbolic links."},{"id":95,"category":"Log Search Parallel","command":"find /var/log -type f | xargs -P 4 grep 'ERROR'","example":"find /var/log -type f | xargs -P 4 grep 'ERROR'","explanation":"Greps through logs in parallel to speed up error finding."},{"id":96,"category":"IP Blocking (Simulated)","command":"cat blacklisted_ips.txt | xargs -I {} iptables -A INPUT -s {} -j DROP","example":"cat blacklisted_ips.txt | xargs -I {} iptables -A INPUT -s {} -j DROP","explanation":"Adds firewall rules to drop traffic from a list of IP addresses."},{"id":97,"category":"Key Rotation","command":"cat keys.txt | xargs -I {} aws kms schedule-key-deletion --key-id {}","example":"cat keys.txt | xargs -I {} aws kms schedule-key-deletion --key-id {}","explanation":"Schedules a list of AWS KMS keys for deletion."},{"id":98,"category":"JSON Parsing","command":"cat data.json | jq -r '.[] .id' | xargs echo IDs:","example":"cat data.json | jq -r '.[] .id' | xargs echo IDs:","explanation":"Extracts IDs from a JSON file and formats them into a single line."},{"id":99,"category":"Kubernetes Logs","command":"kubectl get pods -l app=web -o name | xargs -n 1 -P 3 kubectl logs","example":"kubectl get pods -l app=web -o name | xargs -n 1 -P 3 kubectl logs","explanation":"Fetches logs from multiple pods matching a label in parallel."},{"id":100,"category":"Advanced Arg File","command":"xargs -a params.txt -L 1 command","example":"xargs -a params.txt -L 1 command","explanation":"Reads arguments from a file line-by-line without using pipes."},{"id":101,"category":"Shell Injection Defense","command":"ls | xargs -I {} bash -c 'echo \"$1\"' -- {}","example":"ls | xargs -I {} bash -c 'echo \"$1\"' -- {}","explanation":"Passes arguments to a subshell securely using positional parameters."},{"id":102,"category":"High Volume Deletion","command":"find . -name 'temp*' -print0 | xargs -0 -n 1000 rm","example":"find . -name 'temp*' -print0 | xargs -0 -n 1000 rm","explanation":"Deletes huge numbers of files in batches of 1000 to avoid argument list too long errors."},{"id":103,"category":"Dynamic Parallelism","command":"seq 100 | xargs -P $(nproc) -n 1 echo","example":"seq 100 | xargs -P $(nproc) -n 1 echo","explanation":"Dynamically sets the number of parallel processes based on available CPU cores."},{"id":104,"category":"File Locking","command":"find . -name '*.db' | xargs -I {} flock {} echo 'Locked {}'","example":"find . -name '*.db' | xargs -I {} flock {} echo 'Locked {}'","explanation":"Uses flock to ensure exclusive access to files before processing."},{"id":105,"category":"Final Cleanup","command":"find . -maxdepth 1 -name 'xargs_test*' -print0 | xargs -0 -p rm","example":"find . -maxdepth 1 -name 'xargs_test*' -print0 | xargs -0 -p rm","explanation":"Safely prompts to clean up any test files created during this workflow session."}],"slug":"xargs","category":"utilities","url":"https://terminal.rokibulroni.com/tool/utilities/xargs","markdown":"https://terminal.rokibulroni.com/api/v1/tools/utilities/xargs.md"}