Problem with mv command

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Problem with mv command
# 1  
Old 03-08-2012
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



Code:
 
mv prod.log

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

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

Code:
 
-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?? Smilie
How to get it back???

Thanks in adv....
# 2  
Old 03-08-2012
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.
This User Gave Thanks to pludi For This Post:
# 3  
Old 03-08-2012
Quote:
mv prod.log
The file disappeared.
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
Code:
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...
# 4  
Old 03-08-2012
@pludi: Now i got what happened. Thanks for the insight Smilie
# 5  
Old 03-08-2012
I am much suspecious about the below command line .
Code:
mv *20120308*

mv should throw up error , as the destination argument is missing , right?
# 6  
Old 03-08-2012
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:
Code:
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...

Last edited by vbe; 03-08-2012 at 10:32 AM..
# 7  
Old 03-08-2012
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).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

I'm facing problem with rpm command, when running the command and appears this error:

exec(): 0509-036 Cannot load program /usr/opt/freeware/bin/rpm because of the following errors: 0509-022 Cannot load module /opt/freeware/lib/libintl.a(libintl.so.1). 0509-150 Dependent module /opt/freeware/lib/libiconv.a(shr4.o) could not be loaded. 0509-152 Member... (4 Replies)
Discussion started by: Ohmkar
4 Replies

2. Shell Programming and Scripting

Problem with tr command

Hi friends, Today I found one strange behaviour of the tr command. I used the following command: echo "NEE"|tr Sometimes it was giving "nee" as ouput . sometimes it was giving "NEE" as output. Finally I used the below code: echo "NEE"|tr "" "" ... and it gave me the correct... (17 Replies)
Discussion started by: neelmani
17 Replies

3. Shell Programming and Scripting

Problem with mv command and touch command

Hi guys, first of all I would say that this is my first time I write in a Forum. I've read the "forum rules" and I hope i will respect them. I searched everywhere for the solution of my problem but I didn't find anything. Here my problem: I'm using a sap job scheduler: in a particular job... (7 Replies)
Discussion started by: Antcam
7 Replies

4. Red Hat

please help me in if command problem

Please help me this script !!!! Script ***** a=2.0.0.0 b=1.0.0.0 #if test $a -ge $b if then echo "A is Greater than B" else echo "B is Greater than A" fi i am getting following error >sh abc abc: line 6: [: 2.0.0.0: integer expression expected (8 Replies)
Discussion started by: ponmuthu
8 Replies

5. Shell Programming and Scripting

Problem with command tr

Hello, excuse me for my english, i'm a french man. I have a problem with the command tr in applescript (with the accent...in french we have a lot of accents), i have read that is a problem with the version 10.5 of leopard then i would want to download the version 10.4 of universal binary of tr... (1 Reply)
Discussion started by: protocomm
1 Replies

6. Solaris

problem with ps command

Hi all I use to run sql loader inside a script with usename and password written in syntax. Now when I use 'ps' command to know about the status of loading, it also shows username and password that I don't want to share with someone who is sitting with me. If you have any idea except encryption... (1 Reply)
Discussion started by: sanjay1979
1 Replies

7. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

8. Shell Programming and Scripting

problem with dd command or maybe AFS problem

Hi, folks. Sorry for bothering, but maybe someone could help me please. The problem is the following: there is some script that copies files from local file system to AFS. The copying is performed with dd command. The script copies data into some AFS volumes. The problem appeared with one... (0 Replies)
Discussion started by: Anta
0 Replies

9. UNIX for Dummies Questions & Answers

Problem with ps command??

I have a problem to.... (1).List the number of unique users that has active processes. (2).List the number of active processes for each of the users in (1). (3).Determine total memory usage for each user. Help me please....thank you. Best... (2 Replies)
Discussion started by: robocup
2 Replies

10. UNIX for Dummies Questions & Answers

problem with who command

Sorry for my poor english. Unix is SCO ODT ver 3.0 Mine problem is : when I login via some terminal emulator and type : who am i I see information like this : username ttyp02 Feb 28 09:53 after logoff and type who command (from some other terminal) I see that ttyp02 is still... (2 Replies)
Discussion started by: bane_yu
2 Replies
Login or Register to Ask a Question