Ubuntu – How to find the file which was moved without destination

filesmv

I am in a trouble. I pressed 'enter' without the destination. I had two files in the same directory with a common IDENTIFIER in their name. I wanted to move them to a folder, so I entered

mv /path/to/file/IDENTIFIER*

But before I enter destination I pressed 'enter' and one of my file disappeared which was alphabetically higher.. Now I can not find that file anywhere. I was in my

Abhishek@abhishek$ directory in the terminal.

Can anyone give me an elaborate answer about how I can find or is it overwritten by the other file. I am a complete rookie in the Linux world but I know the workhow of the terminal. So I can do some basic commands.

Best Answer

If you have only two files, eg:

IDENTIFIER_1
IDENTIFIER_2

then you have overwritten IDENTIFIER_2 with the content of IDENTIFIER_1.

Example:

$ cat IDENTIFIER_1
IDENTIFIER_1

$ cat IDENTIFIER_2
IDENTIFIER_2

$ ls -og IDENTIFIER_*
-rw-rw-r-- 1  0 Mai 19 18:28 IDENTIFIER_1
-rw-rw-r-- 1 13 Mai 19 18:27 IDENTIFIER_2

$ mv IDENTIFIER_*

$ ls -og IDENTIFIER_*
-rw-rw-r-- 1 13 Mai 19 18:30 IDENTIFIER_2

$ cat IDENTIFIER_2 
IDENTIFIER_1

If you had had more than two files, then would be an error:

$ ls -og IDENTIFIER_*
-rw-rw-r-- 1  0 Mai 19 18:28 IDENTIFIER_1
-rw-rw-r-- 1 13 Mai 19 18:27 IDENTIFIER_2
-rw-rw-r-- 1  0 Mai 19 18:28 IDENTIFIER_3

$ mv IDENTIFIER_*
mv: target ‘IDENTIFIER_3’ is not a directory

For an even better explanation see @Serg.

Related Question