Questions tagged [xargs]

utility in Unix-like operating systems for passing large numbers of arguments to programs that can only take a small number of arguments

178 questions
42
votes
2 answers

using xargs to cd to a directory

Feeling like an idiot right now. Why does this not work? echo "/some/directory/path" | xargs -n1 cd
Ian Lotinsky
  • 535
  • 1
  • 4
  • 6
36
votes
5 answers

Replacement for xargs -d in osx

In Linux, you can use xargs -d, to quickly run the hostname command against four different servers with sequential names as follows: echo -n 1,2,3,4 |xargs -d, -I{} ssh root@www{}.example.com hostname It looks like the OSX xargs command does not…
Chase Seibert
  • 481
  • 1
  • 5
  • 7
33
votes
3 answers

Why is xargs necessary?

Suppose I want to remove all files in a directory except for one named "notes.txt". I would do this with the pipeline, ls | grep -v "notes.txt" | xargs rm. Why do I need xargs if the output of the second pipe is the input that rm should use? For the…
seewalker
  • 683
  • 6
  • 8
26
votes
3 answers

what is diff bentween xargs with braces and without in linux

I want to know what is the difference between this ls | xargs rm ls | xargs -i{} rm {} Both are working for me
user19140477031
25
votes
5 answers

How can I move files with xargs on Linux?

I am trying this and it's not working: ls file_* | xargs mv {} temp/ Any ideas?
user1953864
24
votes
4 answers

Why does this not work? "ls *.txt | xargs cat > all.txt" (all files into single txt document)

Why does this not work? ls *.txt | xargs cat > all.txt (I want to join the contents of all text files into a single 'all.txt' file.) find with -exec should also work, but I would really like to understand the xargs syntax. Thanks
ajo
  • 885
  • 2
  • 11
  • 20
23
votes
2 answers

Create symlinks recursively for a whole tree

I am seeking for a command that would re-create a whole tree of files in a different directory. I would prefer to have all symlinks absolute. Can I do that with a find and xargs? ;-)
lzap
  • 942
  • 2
  • 10
  • 19
21
votes
8 answers

How can I use two parameters at once with xargs?

I need to convert videos, but I don't know where are they, so I need to find them. How can I give the result and an output file name to FFmpeg with xargs? I already found out that I can construct the two parameters with this command: find . -iname…
kissgyorgy
  • 681
  • 3
  • 8
  • 21
19
votes
1 answer

xargs -I replace-str option difference

From my understanding, the following should mean exactly the same: ls -1 | xargs file {} ls -1 | xargs -I{} file {} if -I option is not specified, it is default to -I{}. I want to list all files in the current directory and run file command on each…
foresightyj
  • 315
  • 1
  • 3
  • 7
19
votes
4 answers

Redirect strace to file

Am trying to trace apache2. These are the commands i'm trying to run. ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace >> trace.txt I tried (ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace ) >> trace.txt or ps…
Marin
  • 402
  • 1
  • 6
  • 15
17
votes
5 answers

How to run sed on over 10 million files in a directory?

I have a directory that has 10144911 files in it. So far I've tried the following: for f in ls; do sed -i -e 's/blah/blee/g' $f; done Crashed my shell, the ls is in a tilda but i can't figure out how to make one. ls | xargs -0 sed -i -e…
Sandro
  • 529
  • 1
  • 4
  • 12
16
votes
3 answers

ls -rt (How to list just THE LAST file? e.g. for: | xargs gnome-open)

e.g. directory containing jpeg files: how to easily open just the most recent jpeg in the current directory?
ajo
  • 885
  • 2
  • 11
  • 20
11
votes
2 answers

How to use wildcards in a xargs-command?

I've got a directory with numbered files, e.g. 1_foo.txt 2_bar.asc 13_test.png, and want to move them into individual directories (e.g. 1, 2 and 13) using as simple a bash command as possible. Creating the numbered directories was easy: mkdir $(seq…
n.st
  • 1,798
  • 14
  • 30
11
votes
4 answers

Xargs pass input to command that contains a pipe

As a vehicle to understand how to manipulate binding precedence with pipes, I'm trying to print the path of one file per directory - for every directory: find $PWD -type d | xargs --delimiter "\n" -I% -n 1 (find % -maxdepth 1 | head -1) I get no…
Sridhar Sarnobat
  • 1,216
  • 1
  • 12
  • 25
10
votes
2 answers

xargs --replace/-I for single arguments

I'm trying to use xargs to run a command for each provided argument, but unfortunately the --replace/-I flag doesn't seem to work properly when conjugated with -n. It seems that {} will expand into the full list of arguments read from stdin,…
André Fernandes
  • 429
  • 8
  • 19
1
2 3
11 12