开发者

command line with mv - file disappeared?

Folks, I have a bunch of files compressed with gzip like so:

    ...
la.20110208.gz
va.20110208.gz
la.20110209.gz
va.20110209.gz
    ...

I typed by accident the following command

mv la.20110209* <enter>

while I meant to type

mv la.20110209* /docs_backup/<enter>

Now I 开发者_如何学Gocannot find my file: only va.20110209.gz remains. Any idea where la.20110209.gz went? I'm on Ubuntu, running bash shell....

Thanks.


If there were exactly two files that matched that pattern, I'm afraid that you will have lost one of them. When you type:

mv *20110209*

... bash tries to expand those wildcards before running mv, so what mv would see if just those two files matched is:

mv blahblah.20110209-b.gz blahblah.20110209.gz

So blahblah.20110209.gz would have been overwritten by blahblah.20110209-b.gz. If there were more than two files that matched then you would get the error:

mv: target `blahblah.20110209.gz' is not a directory

The best case would be if *20110209* expanded to a list of files and a directory as the last item, in which case they'd all be moved into that directory. However, it sounds as if this was the first case I mentioned.

(Some people like to alias mv to mv -i for this kind of reason.)


When you typed mv *20010209* your shell performed pathname expansion on that such that the mv command saw the following arguments:

mv la.20110208.gz va.20110208.gz ... la.20110209.gz last_file

If last_file just so happens to be a directory, then all the files listed before it will be moved into there. Unless you only have 2 files that matched, this must be what have happened because you would have received an error from mv otherwise.

Look for a directory that matches *20010209* via the following command, that is where you files will be:

find . -type d -name "*20010209*"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜