Find all files matching desription and create hard link in directory

2

I would like to find all .mkv files in my download directory and create a hard link to them in my /movies/ directory.

Here’s what I have so far:

for i in `find /download/ -name *.mkv`; do ln "$i" /movies/; done

Which almost works: I receive a bunch of hard links to partial file names. That is, instead of a hard link to say The Best Movie Ever.mkv I receive four hard links, one to The one to Best one to Movie and one to Ever.mkv

Any suggestions?

curios

Posted 2014-12-07T08:00:23.170

Reputation: 175

Look at this answer. It’s about renaming misnamed files, but the core find logic should work for you. http://superuser.com/a/847795/167207

– JakeGould – 2014-12-07T08:11:54.823

Answers

2

Try this way:

find /download/ -name *.mkv -exec ln {} /movies/ \;

jherran

Posted 2014-12-07T08:00:23.170

Reputation: 1 693

Sweet. It works. I was so close at one point, I had this answer except for the last '' Thanks – curios – 2014-12-07T08:34:53.733

Man page says you have to escape the ';' so bash doesn't interpret it – curios – 2014-12-07T08:36:41.680