So I am going along and moving a bunch of files
mv /source /dest &
mv /source/* /dest/dest/ &
...
...
then I get careless and
mv /source/filena* /dest/dest/ *
OMG! ^c^c^c^c
[No Response from terminal command]
What is actually going on here?
What happens when I put an *
(asterisk) at the end of a command instead of an &
(ampersand)?
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.
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