3
votes
2answers
33 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
121 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
100 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
35 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
120 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
99 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?
0
votes
1answer
43 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
1answer
90 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
35 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
1answer
92 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 | ...
1
vote
2answers
293 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 ...
0
votes
1answer
104 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
199 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 ...
2
votes
2answers
518 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 ...
3
votes
3answers
446 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 ...
0
votes
2answers
242 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 ...
2
votes
4answers
395 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 ...
3
votes
1answer
184 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 ...
5
votes
3answers
253 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 ...
4
votes
2answers
1k views

Why doesn't this xargs command work?

I wanted to delete all .sh extensions so did this: ls *.sh | xargs -I {} mv {} `basename {} .sh` However it doesn't work, it behaves like basename returns unchanged file name. Why is it behaving ...
2
votes
3answers
539 views

Howto recursively create PDF thumnbails on linux command line

I am able to use ImageMagick to create a thumbnail of the first page of a PDF using: convert -thumbnail x80 95.pdf[0] thumb_95.png This works fine and generates a thumb_95.png file. I have tried ...
9
votes
2answers
272 views

Piping nothing to xargs

I have a script that may in some circumstances have nothing on stdout. At the end of the script, I pass the lines I have to another command using xargs. My problem is, when there is nothing on stdout, ...
7
votes
2answers
2k 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 ...
1
vote
3answers
2k views

Linux: Does find | xargs grep have limitations?

I've historically performed something like: find . 2>/dev/null | xargs grep -i something_to_find 2>/dev/null If my pwd is barfoo (/foo/bar/baz/foofoo/foobar/foobaz/barfoo) it finds matches. ...
1
vote
4answers
652 views

No such file or directory error when using xargs

I have some files with .mkv extension and I want to calculate their total size using du -h. Some of the files are preceded by whitespace characters. ranveer@ranveer:~$ ls *.mkv ...
1
vote
3answers
1k views

how to sum output of awk or other expression with xargs

Suppose i have the following bash shell script: #!/bin/bash export count=0; for i in `ls ./mydoc` ;do pdfinfo ./mydoc/$i | egrep Pages |awk {'print $2'} |xargs -+ $count ; ...
3
votes
4answers
4k views

Passing pipeline value as parameter to xargs for use by eval echo

I have a text file that I'm using as a template, it looks like this: Hostname : $HOSTNAME Host Address : $HOSTADDRESS My bash script sets two variables, HOSTNAME and HOSTADDRESS, reads the ...
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 ...
15
votes
7answers
11k 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 ...
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 ...