FAQ Database Discussion Community


How can heredocs be used with xargs?

find,posix,xargs,heredoc,ed
Background I'm looking to strip any # TODO comments from some python source code files output by git archive before sending it off. I'm looking to do so from a script that will be run from a variety of *nix OSes, so it should be as POSIX-compliant as possible. I'm...

Running programs in parallel using xargs

bash,parallel-processing,xargs
I currently have the current script. #!/bin/bash # script.sh for i in {0..99}; do script-to-run.sh input/ output/ $i done I wish to run it in parallel using xargs. I have tried script.sh | xargs -P8 But doing the above only executed once at the time. No luck with -n8 as...

xargs echo colored output

terminal,xargs
I have the following command: somethingRegex | xargs -I {} sh -c 'echo -e "found \e[34m{}\e[39m";dummy {}' The color part of the echo does not work, example output: -e found \e[34mresult\e[39m dummy output repeat A plain echo does work with {} being nice blue echo -e "found \e[34m{}\e[39m" How do...

Delete directories with specific files in Bash Script

bash,find,xargs,rm
I would like to delete specific files if existed but also the directories that contain these files. I do know the files I would like to wipe but not the directories. So far, as I'm new in bash scripting, I think of this : find ./ -type f -name '*.r*'...

Use Xargs to wait for enter key

linux,bash,shell,xargs
So, I have a list of files that I want to use to generate a new set of groups of files. I want to open up these groups (multiple files) together at once. Edit them. Then go back to the terminal, hit enter, and open up the next group of...

Copy selected files in bash

bash,copy,selected,xargs,cp
I'm trying to copy specific files between directories. So I listed all files with ls, added a line number with cat -n and then selected first 100 files I want to copy with head -100. After that I used xargs command but it does not work. Here is the code:...

/usr/bin/find Argument list too long

linux,shell,find,redhat,xargs
Trying to search for all files that are excluded from list.txt using the following from the command line find . -type f -name "*.ext" $(printf "! -name %s " $(cat list.txt)) I get the following result -bash: /usr/bin/find: Argument list too long I have also tried with xargs but not...

xargs: exec command with prompt

redirect,zsh,xargs
I'm trying to do the following with xargs pacman -Q | grep xf86-video | awk '{print $1}' | xargs pacman -R to remove all xf86-video-* driver on my machine. To make the question more clear, here is the output of pacman -Q | grep xf86-video | awk '{print $1}': xf86-video-ark...

Bash syntax error in CIS document

linux,bash,centos,find,xargs
I'm working on implementing changes as required by CIS standards for section 9.1.12 (CentOS 6.) The following command returns a syntax error: df --local -P | awk {'if (NR!=1) print $6'} | xargs -I '{}' find '{}' -xdev -group -ls The error I get is: find: `-ls' is not the...

xargs does not read line by line properly

unix,xargs
Here is my current commands which i use: xargs -n 1 -P 100 php b <links I have a script 'b' and a file with links in 'links' and sometimes I don't know why this doesn't work correctly and add to every line symbol "?" like this: root 19714 0.0...

How to merge multiple files into single file in given directories

shell,cat,xargs
I want to write a shell script to merge contents of multiple files in a given directories. DIR1 contains sample1.txt sample2.txt sample1.txt contents :---this is sample1 file sample2.txt contents :---this is sample2 file DIR2 contains demo1.txt demo2.txt demo1.txt contents :---this is demo1 file I tried : (find /home/DIR1 /home/DIR2 -type...

Bash command with backticks inside of xargs

linux,bash,xargs
echo $TMPLIST | xargs -I{} -n 1 -P $MAXJOBS curl -o {}_$DATESTRING.dump `get-temp-url --location {}` $TMPLIST has a list of locations which I want processed. I am trying to run something similar to the above, but the brackets inside of the backticks do not get expanded. What am I...

Correctly interpret newline characters

bash,cat,xargs
I have a file which I need to parse, word by word, and make changes to only certain words. My bash script works in everything but retaining newline characters. I have constructed a minimum example as follows: #!/bin/bash # contents of myscript.sh toks=( $* ) for tok in ${toks[*]}; do...

Strange errror while using find in batch script

linux,shell,find,xargs
I'm trying this piece of code to resize jpg files inside folder recursively larger than 1 MB. find . -type f -size +1M -name "*.jpg" | xargs convert -resize 1000x1000\> -verbose Getting error message (which breaks batch after 15-20 iterations) xargs: convert: terminated by signal 9 How to solve this...

Execute a command on a list of strings in Bash

bash,xargs
I'm trying to find all C# interfaces from a given directory. I tried doing this command: find . -type f | xargs basename | grep ^I but basename is giving back an error since I'm sending it a list of strings, not a string itself. How do I get the...

Pipe grep output to xargs

grep,xargs
I'm trying to filter the output of git ls-files for some reporting commands, and then pipe that output to xargs. I was originally using -z on git ls-files which worked fine, but now that I'm piping to grep, I need to restore that functionality. Trying the grep version -Z isn't...

Multiple lines to single line in Linux

bash,awk,sed,scripting,xargs
How to make the below given multiple lines to a single line in Linux? I am able to do with xargs but end of the every line has one space extra. From the below given output you can see 'JAS _Data' 'Exclusiv e' has a space. Thu Feb 19 10:42:50:...

xargs (or something else) without space before parameter

linux,git,xargs,git-squash
I would like to execute something like this (git squash): git rebase -i HEAD~3 extracting the 3 from git log: git log | blabla | xargs git rebase -i HEAD~ This does not work because xargs inserts a space after HEAD~. The problem is that I want to alias this...

Bash Xargs Sleep (Multiple Command Line Arguments)

bash,sleep,xargs
Ok so I have the following script that updates Route43 DNS entries. Unfortunately there is a limit to the number of calls per second you can make so I need to make the final Xargs command sleep for about a second between each iteration. I've tried a couple of things...

xargs - does the program run in loop or get re-executed

linux,command-line,command-line-arguments,execution,xargs
I have a C++ program that is outputting text strings which are read as command line inputs to my Java program. My question is does the Java program continuously run with new inputs given or does the program terminate and then get executed again when new command line arguments are...

Execute bash function from find command

bash,xargs
I have defined a function in bash, which checks if two files exists, compare if they are equal and delete one of them. function remodup { F=$1 G=${F/.mod/} if [ -f "$F" ] && [ -f "$G" ] then cmp --silent "$F" "$G" && rm "$F" || echo "$G was...

Bash script find pattern and replace by filename

bash,shell,sed,xargs
I'm trying to find all files of a specific folder and which contains text "TO_BE_REPLACED" and I would like to replace this string by the filename without the characters Impl. I mean, having a file called MyServiceImpl with text "TO_BE_REPLACED" I would like to replace it with the text "MyService"....