What does an asterisk at the end of a mv command do
The shell expands the wildcard *
. The mv
command never sees the wildcard, only the result of the expansion.
The wildcard *
expands to the list of files in the current directory in lexicographic order. If the last file is a directory, then all the preceding files (/source.filenafoo
, /source/filenabar
, /dest/dest
, hello
) are moved to that subdirectory. If the last file is not a directory, mv
complains that “target a.png
is not a directory” (or words to that effect).
See What does mv ./*
without specifying destination do? for more detailed examples.
An asterisk at the end of a command line is treated the same way as an asterisk anywhere else on the line — it's a wildcard that matches zero or more characters. Specifically, in this instance, the *
in mv /source/filena* /dest/dest/ *
is replaced by the name of each & every file and folder in your current directory (except those beginning with a dot), and whatever happens to be last in this list is where mv
is going to try to put everything.