Question

Running the following script:

for i in $(find dir -name "*.jpg"); do
  ln -s $i
done

incredibly makes symbolic links for 90% of the files and makes of a copy of the remaining 10%. How's that possible?

Edit: what's happening after is relevant:

Those are links to images that I rotate through mogrify e.g.

mogrify -rotate 90 link_to_image

It seems like mogrify on a link silently makes a copy of the image, debatable choice, but that's what it is.

Was it helpful?

Solution 2

(Imagemagick) mogrify applied on a link delete the link and makes a copy of the image

OTHER TIPS

Skip the first paragraph if you want to know more about processing of files with spaces in the names

It was not clear, what is the root of the problem and our assumption was that the problem is in the spaces in the filenames: that files that have them are not processed correctly.

The real problem was mogrify that applied to the created links, processed them and changed with real files.

No about spaces in filenames.

Processing of files with spaces in their names

That is because of spaces in names of the files. You can write something like this:

find dir -name \*.jpg | while IFS= read i
do
  ln -s "$i"
done

(IFS= is used here to avoiding stripping of leading spaces, thanks to @Alfe for the tip).

Or use xargs.

If it is possible that names contain "\n", it's better to use print0:

find dir -name \*.jpg -print0 | xargs -0 -N1 ln -s

Of course, you can use other methods also, for example:

find dir -name '*.jpg' -exec ln -s "{}" \;
ln -s "$(find dir -name '*.jpg')" .

Try with single quotes:

find dir -name '*.jpg' -exec ln -s "{}" \;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top