execute sub command within xargs

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 ?


Solution 1:

launching a subshell will do what you want:

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

Solution 2:

mkdir A ; touch A/file1 ; touch A/file2
mkdir B
for i in `ls A`; do ln -sf $PWD/A/$i B/; done

Solution 3:

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