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

learn more… | top users | synonyms

1
vote
3answers
73 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 ...
1
vote
2answers
49 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 ...
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 ...
2
votes
1answer
111 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
82 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
59 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
66 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
933 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
364 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 ...
2
votes
2answers
53 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
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
113 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
299 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
144 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 | ...
5
votes
2answers
573 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
83 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
37 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
67 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
40 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, ...
2
votes
4answers
425 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
53 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
198 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
206 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"[__]" ...
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 ...
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
88 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 ...
2
votes
3answers
145 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 ...
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
146 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
76 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
150 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
257 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 ...
4
votes
1answer
139 views

cmd2 `cmd1` vs cmd1 | xargs cmd2

I'm trying to find a file with find and then pass the found path to sqlite3. I'm only dropped into the sqlite> prompt if my command is of the form: sqlite3 `find . -type f -iname "*.db" | head ...
5
votes
2answers
591 views

How to quote arguments with xargs

Suppose that I want to delete all files in a folder that are greater than 1 MB. $ find . -size +1M | xargs -0 rm This will not delete files that have space in their names. So I want it to quote all ...
0
votes
1answer
456 views

Command that prints file contents given filename on stdin

I have a command that produces some output part of which is actually a file name containing the full output data. I want to extract the file name (which I trivially do with cut) and then pass it to ...
2
votes
3answers
1k views

find, xargs and mv: renaming files with double-quotes, expansion and bash precedence issue

Ok, I'm simply trying to strip out double-quotes in my filenames. Here's the command I came up with (bash). $ find . -iname "*\"*" -print0 | xargs -0 -I {} mv {} {} | tr -d \" The problem is the ...
0
votes
3answers
171 views

Cannot prompt user using rm bultin prompt option -i with xargs and find

I am using xargs and rm with find in order to remove files that follow a specific pattern defined by find as follows. touch file find . -name file | xargs rm Everything works fine with the above ...
1
vote
1answer
57 views

xargs: running command once with all arguments

My aim is to get a list of files that have been modified in git, then run rspec command passing each file in as an argument. Currently I have: $ git status -s | awk '{if ($1 == "M") print $2}' | tr ...
2
votes
1answer
93 views

Problems with find, xargs and egrep

I this is what I what I'm trying to end up with (except working) find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vZ 'vvv|iii' What am I doing wrong? $ ll total 0 -rw-rw-r-- 1 ...
1
vote
1answer
72 views

Where does `xargs` add the option from STDIN?

Due to some reasons, the option order is important to the command. For example, different options order may cause different actions in ffmpeg, so where does xargs add the option from stdin? For ...
1
vote
2answers
166 views

Seaching a File in Unix for a given string and then another set of Strings within this file and print file properties too

I am using command to search for files staring from a given Directory in Unix , files ending *.sas and containing the string DB2. I then inturn want to search the resultant set of files for the ...