How do I get back files after "mv * .*"?

Solution 1:

Your files are not hidden, you have moved all files (and directories if any) one directory up.

This happens because mv * .* won't work as you think it will. The command mv will only move one file to one file (rename) or move one or multiple files to a directory. It won't move multiple files to multiple files with some smart renaming.


What happened?

Let's assume we have one directory and 3 files in our directory:

dir1
file1
file2
file3

Some Shells (e.g. bash, dash, ...) will expand your command to:

mv dir1 file1 file2 file3 . ..

Your expanded command fits the second form of the SYNOPSIS you find at man mv:

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

Note the . and ..:

  • . is the current directory,
  • .. is one directory up.

The command means: move dir1, file1, file2 and file3 and . to ..; It will also essentially give an error, something like:

mv: cannot move '.' to '../.'

But given you have write permission in that directory, all other files have been moved. You can find your files in .. (= one directory up). However, files with same name have been overwritten and you won't know which files was in which directory before.


If you had a subdirectory .hidden-dir, it would have expanded to:

mv dir1 file1 file2 file3 . .. .hidden-dir

Then, all files would have been moved to .hidden-dir. However, this seems not the case for you, because the you would have seen .hidden-dir in your ls -la output.


How to fix

Run:

mv ../dir1 ../file1 ../file2 ../file3 .

However, you need to know the names.


What you should have used

mmv '*' '.#1'

or

rename 's/^/./' *