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

learn more… | top users | synonyms

3
votes
3answers
115 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
28 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
91 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
31 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 ' ' ...
5
votes
2answers
115 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
90 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
126 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
38 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
113 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
633 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
77 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
83 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
33 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
226 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?
1
vote
2answers
136 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
996 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
89 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
126 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
77 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, ...
1
vote
1answer
103 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
282 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
441 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
188 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 ...
0
votes
2answers
251 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. ...
0
votes
1answer
70 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 ...
5
votes
4answers
377 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, ...
2
votes
1answer
123 views

xargs and < and > to the same files

I want to run git stripspace on all my source code files, on each build (or precommit or just manually), to remove extraneous whitespace, and later maybe to format the code in a standard way, So ...
-1
votes
2answers
57 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?
5
votes
3answers
249 views

Can you pipe to a .bash_profile function?

I received a great function for highlighting files in Apple's finder using the command-line. It's basically a wrapper for osascript. I got it from Mac OS X: How to change the color label of files ...
1
vote
1answer
41 views

Memory-efficient utility to return N first sorted values

I would like to implement a very popular MapReduce example using only existing programs operating in a UNIX way. The problem is to find N most frequent values in an enormous amount of data. The ...
1
vote
2answers
280 views

How to loop through xargs where each script uses a common env variable

Is it possible to initiate 10 of the same shell scripts which also initiate more copies, and have them all use the same env variable? For example: script.sh: #!/bin/bash export ...
2
votes
2answers
403 views

xargs loop with input variable for use in multi-command

I have a text file with various IP addresses. I would like to cycle through each, and issue a command: cat ips.txt | xargs -L 1 `ssh me@__IP__ echo "text" > file; reboot;` But I'm unsure how ...
0
votes
1answer
88 views

ENV variables in relation to xargs loops

Are env variables (set using export) treated differently when the same script is run multiple times simultaneously? That's a weird question, so here's an example I built out which is similar to my ...
1
vote
2answers
177 views

Use xargs input in eval command [duplicate]

I have a file "commands.php" that dynamically generates bash commands. For example, one line is: # - commands.php ssh me@123.123.123.123 echo "text" > file; reboot; How can I use the output of ...
4
votes
2answers
585 views

Is there any way to use xargs across a pipe?

I'm trying to automatically convert flac files moved to a folder into mp3 in another folder. My current line of code is this: inotifywait -m -r -q -e moved_to --format "'%w%f'" ~/test | xargs -I x ...
9
votes
4answers
3k 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 ...
2
votes
2answers
130 views

Understanding -regex with GNU find

Background I have what I think should be a simple case. I want to find all files with "cisco" in the name and do something with those files (via xargs). Finding files with ls Before I use xargs, ...
6
votes
6answers
11k views

How to search for a word in entire content of a directory in linux

need to search for something in entire content I am trying: find . | xargs grep word I get error: xargs: unterminated quote How to achieve this?
11
votes
3answers
2k views

bash find xargs grep only single occurence

Maybe it's a bit strange - and maybe there are other tools to do this but, well.. I am using the following classic bash command to find all files which contain some string: find . -type f | xargs ...
4
votes
3answers
134 views

cycle through one command's output and use in another command [duplicate]

How can I use the output of one command - line-by-line - into another command? I know how to do this with the | pipe symbol, but this uses the entire output in one command. I would like to go line by ...
11
votes
8answers
821 views

Spreading stdin to parallel processes

I have a task that processes a list of files on stdin. The start-up time of the program is substantial, and the amount of time each file takes varies widely. I want to spawn a substantial number of ...
1
vote
2answers
243 views

xargs inside a for loop

So we got most of it figured out but here's what happens. for i in $(arp |sort |awk '{print $1}'|grep IPADDRESS) do ssh USERNAME@$i "ps -ef |grep X11|grep -v grep |awk '{print $2}'|xargs kill" done ...
3
votes
3answers
389 views

Weird “No such file” error with “xargs” and “file”

I'd like to get the MIME type of all files under the current directory. Why doesn't this work? I've tested bash on OSX or Linux. "file" complains that it can't find the file, but if I run it with the ...
2
votes
2answers
148 views

Use xargs to move files from within a directory

I am searching for some folders in my current directory. What I want to do is, move all the files within those directories to another directory. I am using the following command: find -maxdepth 1 ...
7
votes
3answers
3k views

How to open multiple files from `find` output?

I know I can open multiple files found in a dir like so: find -name *.foo -xargs <command> {} \; This works, but when trying to open a bunch of textfiles in gedit at the same time, it opens ...
0
votes
2answers
223 views

Pass flags to xargs

I want to kill a bunch of processes using this command: sudo ps ax | grep node | awk '{print $1}' | xargs kill But it gives me operation not permitted even with sudo. Then I tried with kill -9 ...
0
votes
2answers
184 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 ...
2
votes
4answers
370 views

Zgrep stop after first match when arguments are passed from xargs

I'm using this command to find patterns in zip files (similar to the one) suggested here http://superuser.com/questions/144926/unix-grep-for-a-string-within-all-gzip-files-in-all-subdirectories find ...
0
votes
2answers
1k views

How can I find files and then use xargs to move them?

I want to find some files and then move them. I can find the file with: $ find /tmp/ -ctime -1 -name x* I tried to move them to my ~/play directory with: $ find /tmp/ -ctime -1 -name x* | xargs ...
3
votes
1answer
174 views

Why is `xargs bash -ic echo` not the same thing as `xargs echo` or `xargs`?

I expect the command ls -d doc/* | grep -P "<some_pattern>" | xargs bash -ic echo to do the same as: ls -d doc/* | grep -P "<some_pattern>" | xargs echo that is, to give me the files ...