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

185 questions
49
votes
3 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
  • 605
  • 1
  • 5
  • 6
45
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…
35
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
  • 723
31
votes
3 answers

What is difference between 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
29
votes
3 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
  • 1,021
26
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
  • 945
  • 2
  • 12
  • 20
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
23
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
  • 442
  • 1
  • 6
  • 15
23
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…
22
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
  • 345
  • 1
  • 3
  • 7
18
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
  • 539
17
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
  • 945
  • 2
  • 12
  • 20
12
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,…
12
votes
5 answers

find: -exec vs xargs (aka Why does "find | xargs basename" break?)

I was trying to find all files of a certain type spread out in subdirectories, and for my purposes I only needed the filename. I tried stripping out the path component via basename, but it did't work with xargs: $ find . -name '*.deb' -print |…
quack quixote
  • 43,504
12
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
  • 2,008
1
2 3
12 13