1

I was moving all data to another folder and made 1 mistake and run this commmand

mv * /*

all files have disappeared now. How can I find them? Or are they deleted?

jasonwryan
  • 73,126
Guru
  • 121

2 Answers2

3

All wildcards like * are expanded by the shell and passed to the command. That means that the first star was replaced with the files in your current working directory, and the second one replaced with all of the files in /. You can see this by running

echo /*

On my system, that results in

/bin /boot /dev /etc /home /lib /lib64 /lost+found /media
/misc /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var

So, your command ended up being something like:

mv file1 file2 ... ... ... /tmp /usr /var

which moves everything to /var. Of course, what exactly was last may vary on your system. Whatever it is, you'll probably find your files there.

I'm assuming you were running as root. If you weren't, you wouldn't be able to write most of the directories in /, so nothing would have happened. Be extra-careful when running as root, and avoid it when possible.

mattdm
  • 40,245
1

I made a good observation from this:

mkdir test; cd test; mkdir t1 t2 t3
cd ~/
mkdir testmove;
cd testmove;
touch abcd
mv * ~/test/*

Here is the interesting part the file "abcd" is moved to directory t3 along with directories t1 and t2 that is:

ls test
-> t3
cd t3
ls 
t1 t2 abcd

what I understood is when we write * the command actually expands and then gets executed so the mv command gets expanded as

mv abcd ~/test/t1 ~/test/t2 ~/test/t3

Thus it took t3 as the destination and moved abcd,t1,t2 to t3

So to answer your question it will be in last directory in /

From man page of mv if you have symlink

Avoid specifying a source name with a trailing slash,
when it might be a symlink to a directory.  Otherwise, `mv' may do
something very surprising, since its behavior depends on the underlying
rename system call.  On a system with a modern Linux-based kernel, it
fails with `errno=ENOTDIR'.  However, on other systems (at least
FreeBSD 6.1 and Solaris 10) it silently renames not the symlink but
rather the directory referenced by the symlink.  *Note Trailing
slashes::.

You can search for your file using find / -type f -name <filename>

terdon
  • 242,166