This forces the destination to be a directory that already exists or the command to fail without effect and is used as a fail-safe.
The meaning of
Every directory in typical Unix/Unix-like filesystems include two special directories: one referencing the directory where it is:
. and one referencing the parent directory of where it is:
.. (allowing to move back in the hierarchy of directories). They are relative to where they are found. So the directory
. inside a directory named
backups. To tell it otherwise, when there's a directory named
backups/. is equivalent to
Different behaviors with the source or destination being a file or directory
If the directory exists, the two commands will have the same effect: when the target is a directory
mv will move source(s) to that directory. That's the expected outcome.
If the target
backups is a file instead of the directory:
- 1st case will fail with the error
Not a directory
- 2nd case will rename
Caiti.bak and overwrite
If the target doesn't exist:
- 1st case will fail with
No such file or directory
- second command will rename the file
Caiti.bak into the file
backups, leading to the previous case and possible loss of data the next time it happens.
That's good practice to append
/. to a directory target supposed to be existing and abort a script at an error from this.
All these cases would work the same when only appending
/ if the source is a file rather than a directory.
If we can't assume this, this example where the source is a directory:
mv somedirectory targetnothere/
would not fail (and somedirectory will be renamed instead of being put into targetnothere or abort). The extra
. will make this case fail too:
$ mv somedirectory targetnothere/.
mv: cannot move 'somedirectory' to 'targetnothere/.': No such file or directory