xargs is a command that executes another command and generates its arguments from stdin

learn more… | top users | synonyms

8
votes
4answers
3k views

How to delete commands in history matching a given string?

I need to delete all commands in my history matching a string. I've tried: $ history | grep searchstring | cut -d" " -f2 | history -d -bash: history: -d: option requires an argument $ history | grep ...
4
votes
2answers
2k views

xargs : using same argument in multiple commands

Am trying to write a one-liner that can probe the output of df -h and alert when one of the partitions is out [or almost] of space. It's the part using xargs that kicking me in the ass now... echo 95 ...
4
votes
2answers
730 views

Decrypt files encrypted with gpg using xargs

I have a lot of files encrypted with gpg. All files have the same password. Is it possible to use xargs to decrypt files? ls | xargs -n 1 gpg asks for the password for every file.
1
vote
3answers
71 views

Using a function defined in a parent script

I wrote the following script in the test.sh: #!/bin/sh compare() { if [ $1 != root ]; then echo "Fail" >> CAT1.txt fi } awk -F: '$4 == 0' /etc/passwd | cut -d: f1 | xargs -n1 -i bash -c ...
9
votes
5answers
376 views

find | xargs shasum creates checksum of checksum file itself (prematurely) and fails when checking

My problem (in a script with #!/bin/sh) is as follows: I try to checksum all files in a directory for archival purposes. The checksum (in my case sha1) file with all filenames should reside in the ...
1
vote
2answers
46 views

Exec condition and xargs in Find simultaneously

I am trying to include the standard C package stdint.h to files which have the word LARGE_INTEGER, as a part of conversion from Windows to Linux drivers as discussed here for datatypes. I know the ...
2
votes
1answer
100 views

Piping multiple lines within bash script

I have some complicated logs that I try to parse. What I want is to find a string H, get column 5 from the line that matches, and then take all other lines where column 5 matches the line with the ...
1
vote
3answers
81 views

How do I get the current line count from xargs?

I want to grab every 5 images in a directory and merge them together into a new file with a unique filename per 5 image group. find *.jpg | xargs -n 5 -i convert {} -append {#}.png This is really ...
0
votes
1answer
56 views

Using curl with xargs connection hanging sometimes - any way to retry?

echo $LIST | xargs -I{} -n 1 -P 8 sh -c 'curl -o backup.dump http://url.com' I am running this for a large amount of files (around 300). After a while, sometimes curl hangs and won't progress for a ...
3
votes
4answers
136 views

Provide strings stored in a file as a list of arguments to a command?

I install a list of URLs in a text file named myurls: http://www.examples.com/1 http://www.examples.com/2 http://www.examples.com/3 How shall I pass these URLs to wkhtmltopdf as inputs? The direct ...
2
votes
1answer
27 views

Unset all ENV variables matching _PROXY

I'm trying to unset all environment variables that match _PROXY: env | grep -i _proxy | column -t -s '=' | awk '{ print $1 }' | grep -iv 'no_proxy' | xargs -0 -I variable unset variable but it's ...
1
vote
1answer
64 views

piping commands after a piped xargs

HP-UX ***** B.11.23 U ia64 **** unlimited-user license find . -type d -name *log*|xargs ls -la gives me the directory name(the ones which contain log in the directory name) followed by all files ...
6
votes
5answers
907 views

Deleting files with spaces in their names

I am trying to delete all the files with a space in their names. I am using following command. But it is giving me an error Command : ls | egrep '. ' | xargs rm Here if I am using only ls | egrep '. ...
7
votes
2answers
362 views

Why does xargs skip first argument when passing to subshell?

Looking for a way to invoke more than one command in a xargs one-liner, I found the recommendation in findutils to invoke the shell from xargs like this: $ find ... | xargs sh -c 'command $@' The ...
6
votes
1answer
4k views

“Argument list too long”: How do I deal with it, without changing my command?

When I run a command like ls */*/*/*/*.jpg, I get the error -bash: /bin/ls: Argument list too long I know why this happens: it is because there is a kernel limit on the amount of space for ...
2
votes
2answers
52 views

Copy files with parent folder to a new directory

I want to copy some files and include their parent directory in the process. The current structure is similar to: /Module1/A/downloads/m13312/file.pdf /Module1/A/downloads/m17312/file.pdf ...
2
votes
1answer
46 views

xargs not prompting after each line

I want to know the size of all the data files in my directory. I tried using the following command. The file names all start with data_. find . -name 'data_*' -type f | xargs ls -sh -n1 -p I do ...
2
votes
3answers
139 views

Multiple arguments using xargs.

I know xargs can take many arguments like so. xargs -n5 -I{} echo {} but how do I put the arguments in a particular location I want do something like. xargs -n5 -I{} curl ...
2
votes
3answers
56 views

Search a String in a directory- Get output without filename

I am executing the below command to display the lines which matches the pattern. find ./files/ -name "*.txt" -print0 | xargs -0 grep "5|20150507" And output is ...
3
votes
5answers
110 views

`xargs` with spaces in filenames

I'm trying to list only non-image files, searching only in the most recent 500 files. So I run ls -t | head -500 | file | grep -v 'image' which isn't right: it displays a help message. Changing it ...
8
votes
2answers
294 views

Unix: a question about xargs

On AIX (but this happens on HP-UX as well), I have GNU ls in my path and it is also aliased as ls. But when i use xargs, it uses the standard Unix ls instead of the alias. For example (flocate is a ...
8
votes
3answers
140 views

correct xargs parallel usage

I am using xargs to call a python script to process about 30 million small files. I hope to use xargs to parallelize the process. The command I am using is: find ./data -name "*.json" -print0 | ...
1
vote
4answers
368 views

xargs line too long

I am trying to remove all files that have a hexadecimal digit in the first two digits, so I am using the following expression: ls | grep -Z '^[0-9a-f][0-9a-f]' | xargs -0 rm However, the terminal ...
5
votes
4answers
536 views

Format output of xargs

I would like to change the format of the output xargs displays cat k.txt 1 2 3 And cat k.txt | xargs 1 2 3 However I would like to have 1, 2, 3 or 1|2|3. Any suggestions?
5
votes
2answers
567 views

How can I make xargs play nice with stdin?

$ seq 1 3 1 2 3 $ seq 1 3 | xargs echo 1 2 3 $ Mentally replace seq 1 3 with any command that lists entries one-per-line on standard out. How can I get more-or-less what you'd expect, i.e. the ...
2
votes
1answer
76 views

How to tell xargs which argument to choose ? [duplicate]

When xargs redirects the first commands output into the second command's argument and there is no choice about which argument for which element of the output, then there is only one way, for instance: ...
1
vote
1answer
42 views

How to interactively remove all directories matching given criteria?

My script below has two problems: The script stops after first matched directory rm -i is not quite interactive What are my incorrect assumptions that make it fail? How can I fix it? ls -1A | ...
3
votes
1answer
36 views

Moving sub-directory to new parent directory where the new directory name is incremented by 1

I am attempting to move a sub-directory from one parent directory to another for hundreds of instances, while changing the name of the sub-directory during the move. My directories are a set of ...
0
votes
1answer
20 views

Makes it a difference whether I use a different -n flag value for xargs in combination with find command ?

Assume, someone searches for files that match some criteria using the find command and pipes the result into the rm command. find / -type f -name "*.jpg" | xargs rm First, I am not sure if the ...
4
votes
1answer
62 views

why does the output of xargs -n2 applied to the same number of arguments different whether piped or from keyboard?

when I execute xargs -n2, enter x x x x x and hit Enter, I get only 4 x back: $ xargs -n2 x x x x x x x x x But, when I pipe the x x x x x into the same command, I get the same amount of x back: ...
1
vote
2answers
39 views

Do I need “| xargs -n 1” to get around xargs' -I side-effect?

I was suprised to discover this: $ echo 1 2 3 4 5 | xargs -n 1 echo 1 2 3 4 5 $ echo 1 2 3 4 5 | xargs -n 1 -I FOO echo FOO 1 2 3 4 5 That is, using the -I flag has this side effect: Also, ...
1
vote
3answers
126 views

What does xargs do if it's used without any parameter?

[user@notebook ~] echo -e '1\n2\n3\n4' 1 2 3 4 [user@notebook ~] echo -e '1\n2\n3\n4' | xargs 1 2 3 4 [user@notebook ~] My question: So xargs removes the newlines if it's used without parameters?
2
votes
4answers
408 views

How do I perform xargs grep on grep output that has spaces?

I'm searching for files based on a regular expression, and then I'm trying to search those files for content. So, for example, I have something like #Find all C++ files that match a certain pattern ...
1
vote
3answers
37 views

xargs git: skip user input

I have an xargs function that calls git commands recursively. When I now call gitr log I have to hit enter until the end or q to get the next xargs call to run. Can I tell xargs to skip user input ...
1
vote
1answer
50 views

Combine xargs argument with some text

How can I use xargs to pass an argument through to wget, but also add some text to that argument?
1
vote
1answer
190 views

How to remove all but last 10 files

I accumulate sequentially named files as the result of an automated process, and I would like to keep only the last 10 around. I tried this, which had the effect of deleting everything: ls -r | more ...
0
votes
1answer
203 views

/usr/bin/awk: Argument list too long

I am trying to run the following bash script: #!/bin/bash file=$1 filename=${file%%.*} line1=$(sed -n 1~2p ${file}) seqs=$(grep -v '^>' ${file}) pos=$(echo "${line1}" | awk -F"[__]" ...
6
votes
2answers
8k views

Moving files with find + xargs: target is not a directory?

When I run the following command: > mkdir some_dir > find /foo/bar/ -name '*.csv' -print0 | xargs -0 mv {} some_dir I get hundreds of lines that say: mv: target `/foo/bar/XX.csv` is not a ...
0
votes
1answer
58 views

Why does the input to xargs is 1 string but without is strings in separate line?

I am trying to pipe file to rm via xargs. I understand that what I am tryng to do could be done by git clean but I am practicing the cli. I tried this: for files in $(git status --porcelain| sed ...
5
votes
5answers
2k views

xargs and vi - “Input is not from a terminal”

I have about 10 php.ini files on my system, located all over the place, and I wanted to quickly browse through them. I tried this command: locate php.ini | xargs vi But vi warns me Input is not ...
1
vote
2answers
41 views

Why are “{}” and “%” commonly used as replstr in xargs?

I often see xargs -I {} or xargs -I % (less). Is there any reason why those two are commonly used? Why is {}, as longer and more likely to be bad-interpreted, preferred?
0
votes
1answer
86 views

Using Xargs to write a tar archive in numerical order

I need to write an LTO of single frame files (DPX) in frame number order. When using the standard command below the frames are written out of order. tar -b 1024 -cvf /dev/nst0 <directory> ...
0
votes
2answers
67 views

process substitution for opening a list of files with an application

I wish to use process substitution to direct a list of files (produced, for example, by ls or find) to a particular application for opening/viewing. While piping such a list to xargs is suitable for a ...
0
votes
0answers
41 views

Why is the “move” word necessary when using find + xargs + rsync in this example? [duplicate]

I often use this sort of command on my Mac to transfer files remotely: find . -iname '*.txt' -print0 \ | xargs -0 -J % rsync -aP % user@ip:/foo/bar I had to perform this on Linux. Since GNU ...
4
votes
1answer
115 views

Find files recursively that are older than one year and not owned by a specific user

I'm trying to find any files on a specific mount that are older than one year and do not belong to a specific user. This is the command I'm using (within the root directory of the mount): find . ! ...
2
votes
2answers
138 views

Find file, check size and overwrite when filesize is different

Today I found a little bug in my own written CMS. Now I want to rewrite all the files on the server with the same filename. However, I do have some customers with the specific file customized so I ...
3
votes
2answers
127 views

Combining bash % with xargs %

This article says you can use a % syntax to remove file extensions: $ s=a/b.mkv $ echo ${s%.*} a/b How do you combine the % syntax with the % in xargs to achieve the desired result for a set of ...
2
votes
1answer
72 views

basename doesn't work as expected

How do I make ".mkv" disappear in the target filename? $ echo a/b.mkv | xargs -I % echo ffmpeg -i "%" $(basename "%" ".mkv").mp4 ffmpeg -i a/b.mkv a/b.mkv.mp4
-3
votes
1answer
145 views

How to tell xargs to unpack tar into certain directory [closed]

I wrote my first script which goes: find /media/temp/test -type f -printf '%T@ %p\n*.tar.gz' | sort -n | tail -1 | cut -f2- -d" " | xargs tar -xvpf I would like to find latest modified file which ...
-1
votes
2answers
252 views

understanding sed, awk and curl interaction extracting ssh URL information from github page

I needed to pull every public repo in a user's GitHub account. To do this I got the API output of https://api.github.com/users/SOMEUSER/repos This is what I came up with. To extract the ssh_url line ...