What happened when I "mv *"? No errors were shown and now only one folder is left. Why?

Solution 1:

My guess is that bash expands the wildcard, and thus moves every folder into your last one.

For example:

$ ls
test1  test2  test3  test4

$ mv *

$ ls
test4

$ ls test4
test1  test2  test3

Here, mv * is expanded to mv test1 test2 test3 test4 corresponding to mv [OPTION]... SOURCE... DIRECTORY format. Thus, every folder is moved into the last one.

Solution 2:

As described by @ssssteffff, with mv *, the shell is doing wildcard expansion from files in current directory. However the behaviour of mv command depends on how many arguments * expands to. If there are more than two arguments, then the last argument must be a directory:

   mv [OPTION]... SOURCE... DIRECTORY

So,

I created 5 files

$ touch 1 2 3 4 5
$ ls
1  2  3  4  5
$ mv *
mv: target ‘5’ is not a directory
$ ls
1  2  3  4  5

Now if I create a directory which comes as a last parameter to wild-card expansion, then:

$ mkdir 6
$ mv *
$ ls
6
$ ls 6
1  2  3  4  5

You should double check what that last argument was.

  • If the last argument was a directory, then your data is perhaps safe.
  • If the total number of arguments were 2, and the last argument was a directory, then also your data is perhaps safe.
  • If the total number of arguments were 2, and the last argument was a file, then the second file is gone for sure.

Are you sure you didn't see the error something like this?

 mv: target ‘5’ is not a directory`