Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make soft link of all the binary files of folder A to folder B like,

find /home/A/bin/* -print | xargs -I {} ln -sf {} /tmp/B/$(basename {})

the problem is that I cant execute sub command inside the xargs.

what should I do ?

share|improve this question

migrated from Dec 31 '12 at 15:25

This question came from our site for professional and enthusiast programmers.

launching a subshell will do what you want:

find /home/A/bin/* -print |
xargs -I {} sh -c 'ln -sf "$1" /tmp/B/$(basename "$1")' - {}
share|improve this answer
This is the real answer to the question. @alinsoar may have showed a better way to do what the OP wanted to do, but this is how you do what he asked for. – ACK_stoverflow Feb 7 '14 at 20:41
mkdir A ; touch A/file1 ; touch A/file2
mkdir B
for i in `ls A`; do ln -sf $PWD/A/$i B/; done
share|improve this answer

You can execute directly ln -sf /h/a/bin/* /tmp .

Or, you can go to /tmp, and do so:

cd /tmp
ln -sf /home/A/bin/*

Using xargs:

cd /tmp
find /home/A/bin/* -print0 | xargs -0 ln
share|improve this answer
thnx for the answer. That worked like a charm. but how can i execute any sub command inside the xargs ?? – JohnG Nov 24 '12 at 8:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.