Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create soft-links for every file in a directory?

Tags:

linux

find

bash

I have a directory, /original, that has hundreds of files. I have a script that will process files one at a time and delete the file so it's not executed again if the script gets interrupted. So, I need a bunch of soft links to the files on /original to /processing. Here's what I tried:

find /original -name "*.processme" -exec echo ln -s {} $(basename {}) \;

and got something like:

ln -s /original/1.processme /original/1.processme
ln -s /original/2.processme /original/2.processme
ln -s /original/3.processme /original/3.processme
...

I wanted something like:

ln -s /original/1.processme 1.processme
ln -s /original/2.processme 2.processme
ln -s /original/3.processme 3.processme
...

It appears that $(basename) is running before {} is converted. Is there a way to fix that? If not, how else could I reach my goal?

like image 964
User1 Avatar asked Feb 01 '11 15:02

User1


1 Answers

You can also use cp (specifically the -s option, which creates symlinks), eg.

find /original -name "*.processme" -print0 | xargs -0 cp -s --target-directory=.
like image 100
Hasturkun Avatar answered Oct 21 '22 04:10

Hasturkun