When I issue the command
mv file1 *.file1
in the directory where file1 is located, it disappears. Where does it end up? I know *
is a valid character in file names under Linux and that I should have escaped the *
character to have the expected result like
mv file1 \*.file1
but if didn't escape it, where was it moved to?
The result of mv file1 *.file1
depends on what is matched by *.file1
*.file1
matches nothing, then file1
is renamed to *.file1
*.file1
matches exactly one file, then file1
is renamed to the name of the matched file, and the matched file is lost.*.file1
matches exactly one file, and that file is a directory, then file1
is moved to the matched directory.*.file1
matches more than one files, and the last file matched is a directory, then file1
, and all matched files (except this directory) will be moved to the directory.*.file1
matches more than one files, and the last file matched is NOT a directory, then mv
will fail with an error.See experiment below:
$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"
NAME="Ubuntu"
VERSION="12.04.2 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.2 LTS)"
VERSION_ID="12.04"
$ ls
$ touch file1
$ ls
file1
$ mv file1 *.file1
$ ls
*.file1
$ touch file1
$ ls
file1 *.file1
$ mv file1 *.file1
$ ls
*.file1
$ touch 1.file1
$ touch file1
$ mv file1 *.file1
mv: target `*.file1' is not a directory
$ ls
1.file1 file1 *.file1
$ mkdir z.file1
$ mv file1 *.file1
$ ls z.file1/
1.file1 file1 *.file1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With