Skip to content
MagickCmdErrors › mogrify overwrote my original files

mogrify overwrote my original files

mogrify writes in place by design and has no undo. What recovery options exist, and the safe patterns — -path, loops and mogrify -format — that never touch originals.

mogrify modifies files in place. That is its entire purpose, and it is the single most common way people lose a folder of photos to ImageMagick:

mogrify -resize 800x600 *.jpg    # every original is now 800x600

If it just happened

Stop writing to that disk. Then, in rough order of likelihood:

  • Time Machine, File History, or a backup. The obvious first check.
  • Cloud sync version history. Dropbox, Google Drive, OneDrive and iCloud all keep previous versions for 30 days or more, and a mogrify run looks like an ordinary edit to them. This recovers more folders than anything else on this list.
  • The photos are still on the camera or phone. Easy to forget if you thought you had already imported them.
  • Filesystem snapshots. ZFS, Btrfs, LVM, or a NAS with snapshots enabled.
  • Undelete tools. photorec and similar can sometimes recover the old blocks, but only if very little has been written since. Success is unlikely on an SSD with TRIM enabled.

Being honest about it: if none of those apply, the originals are gone. mogrify overwrites rather than deletes, so there is no trash to check.

The safe ways to use mogrify

Write to another directory

mkdir out
mogrify -path out -resize 800x600 *.jpg

-path makes mogrify write into that directory instead of over the source. The directory must already exist — mogrify will not create it, and without it you are back to overwriting.

Change format, which writes new files

mogrify -format webp -quality 80 *.jpg

With -format, mogrify writes photo.webp alongside photo.jpg and leaves the original alone. Combine both for full safety:

mkdir out
mogrify -path out -format webp -quality 80 *.jpg

Or do not use mogrify

A loop is barely longer, and the output path is explicit — you can see exactly where files are going before you press enter:

mkdir -p out
for f in *.jpg; do
  magick "$f" -resize 800x600 "out/$f"
done

This is what the batch mode in the generator on this site produces, for exactly this reason.

Habits worth having

  1. Test on one file first. magick sample.jpg -resize 800x600 test.jpg, look at it, then scale up.
  2. Copy the folder before any in-place operation. cp -r photos photos-backup costs seconds.
  3. Prefer magick in a loop over mogrify. The extra typing is the point — it forces you to name the output.
  4. Beware shell glob scope. *.jpg in the wrong directory, or a ** that recurses further than you expected, turns a small mistake into a large one.

A dry run

mogrify has no dry-run flag. You can see what it would touch:

ls *.jpg | head -50
ls *.jpg | wc -l

If that count is larger than you expected, your glob is wrong — find out before running, not after.


Related

Copied