How do I find my file which was moved without destination
Solution 1
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.
Solution 2
I would like to merely expand on the answer that A.B. posted.
The wildcard merely expands IDENTIFIER_* to all instances of IDENTIFIER_*. Therefore, mv IDENTIFIER_*
in reality is read as mv IDENTIFIER_1 IDENTIFIER_2
.
This is a same reason why for loops work like so for file in *; do
, as well as echo IDENTIFIER_*
, and so on and so forth.
Now the reason why 3 files dont work is again because the command mv IDENTIFIER_*
expands to mv IDENTIFIER_1 IDENTIFIER_2 IDENTIFIER_3
, and you are confusing mv
with too many arguments.
Solution 3
You overwrote the second file with the first one.
It's lost unless you unmount immediately the partition/device and try to recover it with a tool like testdisk, photorec, extundelete, or whatever.
Related videos on Youtube
![Abhishek Anshu](https://lh3.googleusercontent.com/-oubSjlvweKQ/AAAAAAAAAAI/AAAAAAAAAts/-BBemgJhTAs/photo.jpg?sz=256)
Abhishek Anshu
Updated on September 18, 2022Comments
-
Abhishek Anshu almost 2 years
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.
-
A.B. about 9 yearsI should delete my answer =) +1
-
Sergiy Kolodyazhnyy about 9 yearsno, no, don't delete it. It's still shows everything correctly
-
Beno about 9 yearsOne of the tricks that I learned from years ago, to move the contents into
mkdir z; mv *
which moves everything into the directoryz
... of course, assuming that thez
directory is the last item in the*
expansion. -
A.B. about 9 yearsSounds dangerous :)
-
Beno about 9 yearsYou could always touch a file named
-i
if you are worried about that.