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

learn more… | top users | synonyms

14
votes
2answers
940 views

gnu find and masking the {} for some shells - which?

The man page for gnu find states: -exec command ; [...] The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, ...
11
votes
3answers
5k views

Find -exec + vs find | xargs. Which one to choose?

I understand that the -exec can take a + option to mimic the behaviour of xargs. Is there any situation where you'd prefer one form over the other? I personally tend to prefer the first form, if ...
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, ...
3
votes
3answers
603 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
2answers
932 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 ...
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 ...
11
votes
6answers
6k views

xargs with stdin/stdout redirection

I would like to run: ./a.out < x.dat > x.ans for each *.dat file in the directory A. Sure, it could be done by bash/python/whatsoever script, but I like to write sexy one-liner. All I could ...
11
votes
8answers
892 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 ...
11
votes
1answer
359 views

How to do `head` and `tail` on null-delimited input in bash?

find command can output names of files as a null-delimited strings (if -print0 is provided), and xargs can consume them with -0 option turned on. But in between, it's hard to manipulate that ...
4
votes
2answers
604 views

Append line to many files

I want to add some text to over 200,000 files I am trying this find . -name *.txt -print | xargs -I % echo "hello world" >> % But nothing is happening. When i run find . -name *.txt it work ...
6
votes
6answers
15k 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?
4
votes
4answers
1k views

xargs and vi - “Input is not from a terminal”

I have about 10 php.ini files on my system, located all over the place, and I wanted to quickly browse through them. I tried this command: locate php.ini | xargs vi But vi warns me Input is not ...
1
vote
1answer
381 views

Speeding a find rm command with test through parallelization

I want to recursively delete all files in directories and subdirectories with number of lines less than 10, and am currently using the following command find . -type f -name "*.txt" | while read; do ...
0
votes
1answer
161 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 ...
0
votes
2answers
3k 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 ...