2

I'd like to create symbolic links for multiple books searched from running find command.

Firstly, I collect all the JS books

find ~ -type f -iregex  '.*javascript.*\.pdf' > js_books.md 2>/dev/null

It returns 35 books

../Coding/Books/HTML_Collections/Freeman E.T., Robson E. - Head First HTML5. Programming Building Web Apps with JavaScript - 2011.pdf
../Coding/Books/HTML_Collections/Learning Web Design - A Beginner's Guide to HTML, CSS, JavaScript, and Web Graphics - Jennifer Niederst Robbins - 4th Edition - August 2012.pdf
..

Additionally to copy them to directory js_books

mkdir js_books
find ~ -type f -iregex  '.*javascript.*\.pdf' -print0 -exec cp '{}' js_books

It works, however, multiple copies consume lots of disk space.
So I delete the books and try to make symbolic link within.

find ~ -type f -iregex  '.*javascript.*\.pdf' -print0 -exec ln -s '{}' js_books/'{}' \;

It returns nothing in dir js_books.

How to work out such a problem?

2 Answers 2

2

You can loose the -print0 primary and the strong quotes around {}. I suggest that you use a glob pattern instead of a regex. Something like:

 find ~ -type f -iname '*javascript*.pdf' -exec ln -s {} js_books \;
1

Try running the command after removing the last occurrence of '{}' from the command-line that you entered:

find ~ -type f -iregex '.*javascript.*\.pdf' -print0 -exec ln -s '{}' js_books/ \;

This should make it work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .