brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mv -n moves files without overwriting any that already exist

Files
~/tips/tip-files-mv-n-no-overwrite

mv -n card2/*.jpg ~/Pictures/all/

Merge files into a folder while keeping whatever is already there.

mv replaces a file of the same name without a word. Camera folders are full of repeated names like IMG_0001.jpg, so merging two of them that way can cost you pictures.

Add -n, short for no clobber:

mv -n card2/*.jpg ~/Pictures/all/

Files with a new name are moved. Where the destination already has that name, the existing file is kept and the source stays where it was. So whatever is left in card2 afterwards is your list of conflicts:

ls card2/

I like that better than being asked about each one. If you would rather decide case by case, use -i and answer the prompt:

mv -i notes.txt ~/Documents/

When both are given, the last one wins, which matters if your shell has an alias such as mv='mv -i'.

The skipping is quiet. GNU coreutils 9.7 prints nothing and still reports success when -n skips a file, so a script can’t rely on the exit status to notice a conflict. Check what’s left behind. It compares names only, never contents: two identical photos and two different photos with the same name are treated alike.

Further reading: mv invocation

More Files tips sha256sum -c --ignore-missing SHA256SUMS xxhsum -H64 backup.tar > backup.xxh unzip -j archive.zip -d out/ Files > More > Select > pick files > More > Compress ls -lhS /var/log All Files tips (15) All topics

Link