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

learn more… | top users | synonyms

3
votes
2answers
68 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
25 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
-4
votes
1answer
44 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
35 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
99 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 ...
4
votes
2answers
229 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 ...
2
votes
3answers
153 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
1answer
23 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 ...
0
votes
3answers
37 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 ...
11
votes
5answers
4k views

How to make `xargs` ignore child's exit and keep processing further

I sometimes run long xargs jobs overnight and it is really annoying to discover in the morning that xargs died somewhere in the middle, for example because of a segmentation fault in one single ...
1
vote
1answer
21 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
35 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
39 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
64 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 ...
51
votes
6answers
6k views

When is xargs needed?

The xargs command always confuses me. Is there a general rule that can help me figure out when I need it? Consider the two examples below: $ \ls | grep Cases | less prints the files that match ...
2
votes
2answers
20 views

Exact format of xargs -I parameters?

Indeed, I would like to know the exact format of '-I' parameter (string, variant, etc.) for a script like this, seq 15 | xargs -I num seq 15 | xargs -I num bash -c "echo num" will work The ...
2
votes
2answers
49 views

How to pipe a the output of find to another find invocation

Here's what I'm trying to do find . -maxdepth 1 -type d -print0 | xargs -0 -P4 find -name 'war' -type d I would like to create a list of directory names, null-terminated, and then pass this list to ...
3
votes
2answers
44 views

echoing basename under xargs?

I have the following command : ls /some/path/*dat | xargs -n 1 -I @ sh -c "echo `basename @`" with the directory /some/path/ containing : /some/path/a /some/path/b /some/path/c /some/path/d I ...
7
votes
3answers
154 views

Is there a way to make this one-liner faster?

Context I have a directory of thousands of zip files that are dated in the form YYYYMMDD_hhmmss.zip and each about 300K. Within each zip file is about 400 xml files each about 3K. The problem I ...
4
votes
2answers
48 views

xargs, records, and standard input

I have a 0-byte-delimited file of records. Record 1, Line 1 Record 1, Line 2 [zero byte] Record 2, Line 1 Record 2, Line 2 I'd like to run the "process.sh" command once for each record, with the ...
0
votes
4answers
89 views

grep for files and open the resultant matches

I'm trying to open all files based on some return values from grep in the command line. I know that I can use the -l option to only return filenames, but I would like to combine this somehow with ...
1
vote
1answer
174 views

How to use defined function with xargs

This is my code #!/bin/bash showword() { echo $1 } echo This is a sample message | xargs -d' ' -t -n1 -P2 showword So I have a function showword which echoes whatever string you pass as a ...
3
votes
2answers
152 views

using modified file content as arguments

In a script I'd like to purge a mercurial repository but be able to retain a number of (configurable) file patterns which I read from $FILENAME. The syntax for the hg command is hg purge --all ...
3
votes
2answers
834 views

Make xargs pass as first parameter

I'm trying to produce this behaviour: grep 192.168.1 *.txt By passing a string into grep via Xargs but it is going on the end instead of as the first parameter. echo 192.168.1 | xargs grep *.txt ...
16
votes
7answers
13k views

Using xargs with input from a file

Say I have a file with the following bob john sue Now these directly corrospond to (in this case) URL pattern such as http://example.com/persons/bob.tar, john.tar, sue.tar. I would like to take ...
1
vote
2answers
46 views

Getting the size of parent folders when using find to search for criteria?

I am hunting for a certain regular expression within the filenames and am seeking to return the parent folders with their sizes in a unique fashion. For example, here is the command that I expected ...
1
vote
3answers
186 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 ...
2
votes
1answer
169 views

xargs command results in sed: ;: No such file or directory

Trying to search and replace recursively across multiple files on a mac running OS X using the following command: grep -rl string1 ./ | xargs sed -i '' s/string1/string2/g \; but it returns the ...
3
votes
3answers
160 views

Is the output mixed like this because of xargs and how can I fix it?

I'm learning a bit of Bash by using xargs to list whois records for a bunch of IP addresses. The command used is: echo "$1" | tr "\n" "\0" | xargs -0 -n 1 -t -P 3 -I % sh -c 'echo "\n 44rBegin whois ...
3
votes
2answers
43 views

xargs how to put result {} into $(cmd {})? [closed]

for example: find /usr/lib -maxdepth 1 -type l -iname "*libblas*"|xargs -I{} echo "{} =>" $(realpath {}) I would like it to output: /usr/lib/libblas.so.3gf=>/usr/lib/libblas/libblas.so.3gf.0 ...
5
votes
4answers
201 views

Have xargs use alias instead of binary

Bash 4.2 on CentOS 6.5: In my ~/.bash_profile I have a bunch of aliases, including: alias grep='grep -n --color=always' so that I can get color highlighting and print line numbers automatically ...
2
votes
1answer
161 views

Using xargs with git

I am trying to practice using xargs. I tried the following, passing the SHA1 via xargs: $ git show SHA1 --name-only I also tried: $ git log --author=jim --grep="patch" |head -n 1|cut -d ' ' ...
2
votes
2answers
130 views

Change directory based on a pipeline's output

I want to go to a directory with using filter For example there is a file named this-is-awsome ls | grep this-is-awsome | xargs cd How can I go to a directory with filter?
4
votes
2answers
184 views

What is the syntax for passing the output of a command to xargs?

As an example I am using xdotool to obtain the list of windows on my desktop, which outputs a list of numbers, one on each line. An example command for that is: xdotool search --name "a_program", ...
0
votes
1answer
101 views

How to make xargs ping and head output as expected?

Given an array of domains I would like to obtain their IP addresses, in the following format: 98.139.183.24 98.137.236.24 This script #!/bin/bash domains=(yahoo.com yahoo.ca) printf "%s\0" ...
4
votes
3answers
132 views

zsh's “echo SomeText >> **/filename” in other shells

I need to fill all files with a specific filename (recursively) with a text. In zsh this can be done with echo SomeText > **/TheFileName I search generic solutions for sh-compatible and/or tcsh ...
5
votes
3answers
679 views

Batch copy to multiple directories

I have about 9000 files in a directory and I want to mv them into 90 files in 100 directories by filename order, ignoring any remainder. In Copy multiple files from filename X to filename Y?, Caleb ...
4
votes
1answer
196 views

Blank lines when executing “grep | xargs” in a “find -exec”

I'm trying to list all directories of a web server that are blocked by Apache via a .htaccess (containing deny from all). I've managed to get the list of blocking .htaccess but when I try to extract ...
4
votes
1answer
112 views

Why do bash variables disappear when I use xargs?

I have a simple bash script and want to count how often a command gets called. Here is a minimal example, the counter is called c and should be 4 at the end: #!/bin/bash c=0; for a in X Y; do for ...
1
vote
2answers
53 views

remove files after insertion into tarball

I want to limit the number of files that get put into a tar ball and erease them after they've been inserted into the tarball and being indipendent from the current directory. I've tried this: tar -C ...
3
votes
2answers
336 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?
2
votes
2answers
159 views

Output of command when piped to another command

I am running a command which does a quick checksum of some file like so find / -type f -ctime +30 -mtime +30 -atime +30 -exec md5sum {} \; | xargs -P 4 and I am trying to run it in parallel with ...
6
votes
5answers
1k views

Find images by size: find / file / awk

I've been trying to find png image files a certain height (over 500px). I know that file will return image dimensions. Example: $ file TestImg1a.png TestImg1a.png: PNG image data, 764 x 200, ...
2
votes
1answer
142 views

How to create infinite pipe of strings in bash

I have about 10 links in file links.txt. I download them through cat links.txt | xargs -i --max-procs=4 bash -c "wget {}" I whould like do it repeatedly like while : do cat links.txt | ...
3
votes
1answer
385 views

How to create multiple tar files with bash script and use date as file names?

I have a lot of files and want to create an archive for every 100 files i.e. the first 100 files are in one tar file, and the 101st to 200th files are in another tar file. And I want to use the date ...
1
vote
1answer
182 views

How to get exit code of a parallel process launched by xargs?

I'd made a script for launching parallel rsync process: #! /bin/bash LIST=$1 DEST_DIR=$2 RSYNC_OPTS=$3 #echo "rsyncing From=$SRC_DIR To=$DEST_DIR RSYNC_OPTS=$RSYNC_OPTS" echo $LIST|xargs -n1 -d, ...
2
votes
1answer
378 views

Convert newlines to null-delimited when using tail

How can I change the output from tail to use null-terminated lines instead of newlines? My question is similar to this one: How to do `head` and `tail` on null-delimited input in bash?, but differs ...
8
votes
3answers
431 views

How to execute a command repeatedly with different arguments?

I'm on Ubuntu. I copied some arguments (separated by newline) and I can use xsel to print them out like this $ xsel arg1 arg2 arg3 arg4 ... Now, I want to use each of these arguments for another ...
3
votes
3answers
766 views

Concatenating thousands of files: > vs >>

I found two seemingly contradictory answers on StackOverflow to the following questions: Concatenating Thousands of Text Files Across Hundreds of Directories (while keeping some structure) How do I ...
2
votes
1answer
339 views

When should you use subshells vs `xargs`?

Many simple commands using xargs could be rewritten as commands using subshells. For instance, here is something I was using earlier today, to concatenate the ten largest binaries in /usr/bin, written ...