问题
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)?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/18324993/what-does-an-asterisk-at-the-end-of-a-mv-command-do