mv multiple files on Linux vs. on Mac

To move multiple files on Linux, one could use:

mv -t DESTINATION file1 file2

Whereas on macOS it is

mv file1 file2 DESTINATION

Why is this difference? Is this a Bash vs. Zsh thing, or older vs. newer syntax, or what?

Asked By: jsx97


The first example of mv uses the GNU extension -t (--target-directory), and has a particular rationale.

Your second example is the standard POSIX solution and will work for every platform offering mv (including those systems using the GNU implementation of mv).

If you are using the second version and want to guarantee that the target is a directory that already exists, suffix it with /. The mv will either succeed cleanly or fail with an error. (Without the trailing /, if the target does not exist or is not a directory then the mv will act simply as a rename.)

Answered By: Chris Davies

No, this has nothing to do with the shell (bash vs zsh), it is simply different implementations of mv. A Linux machine will most likely have GNU mv since Linux machines tend to be built using GNU utilities. MacOS, on the other hand, ships with BSD utilities instead. This means that many common command line utilities behave differently since they are different implementations designed to do the same thing, but with different tweaks.

So not older vs newer, simply tools designed to do the same thing, but written by different people who made different design choices. It’s the same idea as a car: all cars will have a way to steer, break, accelerate etc. However, different car manufacturers will add different things (air conditioning, radio, heated seats or whatever) which will be designed in different ways. They’re still all cars, just like both the GNU and BSD mv are still mvs, but they have their own quirks and features beyond the basic functionality.

Note that the standard mv file1 file2 dir/ will work with Linux mv just as well as with Mac’s. if you are not sure what implementation you’re using, just use the mv file1 file2 dir/ syntax and it will work with any mv.

Answered By: terdon
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.