Problem with mv command

I was trying to move a file to a particular directory. In a hurry i forgot to give the dest directory, as below

 
mv prod.log

The file disappeared. :confused:
Any idea where it might have moved???

And I have tried moving files based on date from one directory to another as below.

 
-rw-rw-rw- 1 plttux edwprod 6130 Mar 8 01:07 XXX_20120308.tar.Z
-rw-rw-rw- 1 plttux edwprod 51 Mar 8 01:15 XXX_20120308_COMPLETE
 
$ mv *20120308*
$ mv *20120308* karthi 
$ cd karthi
$ ls -ltr
total XXXXX
-rw-rw-rw- 1 plttux edwprod 20546 Mar 7 09:14 XXX_20120307.tar.Z
-rw-rw-rw- 1 plttux edwprod 51 Mar 7 09:16 XXX_20120307_COMPLETE
-rw-rw-rw- 1 plttux edwprod 6130 Mar 8 01:07 XXX_20120308_COMPLETE

It seems the content of the file "XXX_20120308.tar.Z" was copied in the name "XXX_20120308_COMPLETE", I assume this from the file size(6130).

Any idea why the file(XXX_20120308.tar.Z) is missing?? :wall:
How to get it back???

Thanks in adv....

mv *20120308* is translated by the shell (in your case) to mv XXX_20120308.tar.Z XXX_20120308_COMPLETE due to shell expansion. So the .Z file is moved/renamed to XXX_20120308_COMPLETE, overwriting that file. So the compressed file is still there, but the other one isn't anymore.

1 Like

mv needs 2 arguments to not complain, unless you have an exotic OS, if mv command displayed nothing, then its needs were satisfied:
In your hurry you did not type what you showed us! or you were not where you thought...
here is what you would have seen

Linus:
ch:/home/vbe $ mv prod.log
mv: missing destination file operand after `prod.log'
Try `mv --help' for more information.
HP-UX:
tant:/sas_wks/prod $ mv prod.log
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
       mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
       mv [-f] [-i] [-e warn|force|ignore] d1 d2
etc...

Look in your history to see what you typed...

@pludi: Now i got what happened. Thanks for the insight :slight_smile:

I am much suspecious about the below command line .

mv *20120308*

mv should throw up error , as the destination argument is missing , right?

Unless you have more than one file matching the criteria... (which is not the case of prod.log (no joker...) here you are right...) in which case pludi's post explains what happens...
here:

slo4:/export/home/vbe $ ll prod*
-rw-r--r--   1 vbe      user         0 Mar  8 15:23 prod.log
slo4:/export/home/vbe $ touch prod.1log
slo4:/export/home/vbe $ touch prod.2log
slo4:/export/home/vbe $ touch prod3.log
slo4:/export/home/vbe $ r ll
ll prod*
-rw-r--r--   1 vbe      user         0 Mar  8 15:24 prod.1log
-rw-r--r--   1 vbe      user         0 Mar  8 15:24 prod.2log
-rw-r--r--   1 vbe      user         0 Mar  8 15:23 prod.log
-rw-r--r--   1 vbe      user         0 Mar  8 15:24 prod3.log
slo4:/export/home/vbe $
slo4:/export/home/vbe $ mv prod.log
mv: Insufficient arguments (1)
Usage: mv [-f] [-i] f1 f2
       mv [-f] [-i] f1 ... fn d1
       mv [-f] [-i] d1 d2
slo4:/export/home/vbe $ mv prod*log
mv: Target prod3.log must be a directory
Usage: mv [-f] [-i] f1 f2
       mv [-f] [-i] f1 ... fn d1
       mv [-f] [-i] d1 d2
slo4:/export/home/vbe $ r ll
ll prod*
-rw-r--r--   1 vbe      user         0 Mar  8 15:24 prod.1log
-rw-r--r--   1 vbe      user         0 Mar  8 15:24 prod.2log
-rw-r--r--   1 vbe      user         0 Mar  8 15:23 prod.log
-rw-r--r--   1 vbe      user         0 Mar  8 15:24 prod3.log
slo4:/export/home/vbe $ mv prod.*log
mv: Target prod.log must be a directory
Usage: mv [-f] [-i] f1 f2
       mv [-f] [-i] f1 ... fn d1
       mv [-f] [-i] d1 d2
slo4:/export/home/vbe $ mv prod*.log
slo4:/export/home/vbe $ r ll
ll prod*
-rw-r--r--   1 vbe      user         0 Mar  8 15:24 prod.1log
-rw-r--r--   1 vbe      user         0 Mar  8 15:24 prod.2log
-rw-r--r--   1 vbe      user         0 Mar  8 15:23 prod3.log

prod.log was canibalized by prod3.log...

In summary, there had to be exactly two wildcard matches to expand to a valid "mv" command.

For completeness you probably now need to rename XXX_20120308_COMPLETE to XXX_20120308_COMPLETE.Z . The original XXX_20120308_COMPLETE file is a total loss (but as it was only 51 bytes I guess it was some sort of process flag).

i tried this command in my machine but the file is on the same location.
so i will suggest u to try fg command(to check to job in running in background)

type fg (it will open the jobs running in the background)

@vipinkumarr89
This thread was answered 4 weeks ago with the correct solution and explanation.