Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Dec 31 '12 at 15:25

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

add comment

3 Answers

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 at 20:41
add comment
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
add comment

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
add comment

Your Answer

 
discard

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