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

learn more… | top users | synonyms

0
votes
0answers
55 views

Bash script parsing problems [on hold]

I created a script that would comb through SSH output on my Minecraft server for a particular expression and the resulting lines would be sent to xargs and then to curl so they could be pushed to my ...
0
votes
0answers
40 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 ...
1
vote
2answers
36 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
54 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
55 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
79 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
30 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
53 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
58 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
104 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
246 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
36 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
234 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
48 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
23 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
39 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
43 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
71 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 ...
2
votes
2answers
23 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
53 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
47 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 ...
4
votes
2answers
56 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
97 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
296 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
158 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 ...
1
vote
2answers
55 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
209 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
246 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
2answers
44 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 ...
3
votes
3answers
170 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 ...
5
votes
4answers
221 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
180 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 ' ' ...
7
votes
3answers
155 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 ...
2
votes
2answers
136 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
188 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
113 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
134 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 ...
4
votes
1answer
225 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
116 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
56 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 ...
2
votes
2answers
160 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 ...
2
votes
1answer
156 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
415 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
206 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
438 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
445 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 ...
2
votes
1answer
367 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 ...
1
vote
2answers
2k views

How can I concatenate all files in a directory together in one command line operation? [duplicate]

I have 1000 csv files in a directory. I would like to concatenate them all together in order. They are named img_size_1.csv to approx img_size_1000.csv This answer is close but assumes a list file. ...
5
votes
4answers
756 views

How do I get a single total of lines with `wc -l`?

I've added a git alias to give me the line counts of specific files in my history: [alias] lines = !lc() { git ls-files -z ${1} | xargs -0 wc -l; }; lc However, wc -l is reporting multiple totals, ...
0
votes
1answer
180 views

Order a list of files, by date modified, then unzip them in that order

I have a list of zip files, that must be extracted by date modified, they contain updated images and the strange way the local mls provides them means that newer zip files container newer versions of ...