1753813 Members
7949 Online
108805 Solutions
New Discussion

Re: mv command

 
rajesh73
Super Advisor

mv command

I have one doubt
#pwd
#/tmp
#ls -ltr
-rwx-rwx-rwx. data.zip
#mv data.zip /log

From the above command what will happen. Please explain
7 REPLIES 7
rajesh73
Super Advisor

Re: mv command

If i need to move some files to some other location

mv log /tmp

Or

mv log /tmp/

From the above command which one is correct
Patrick Wallek
Honored Contributor

Re: mv command

Your first question:

 

>>>> #mv data.zip /log
>>>> From the above command what will happen. Please explain

 

Well, the simple explanation is that the data.zip file will be moved from the /tmp directory to the /log directory.

 

Without know **exactly** how the 'mv' code is written, the file is likely copied from the current location to the new location and once the copy is verified the file is removed from the original location.

 

Your second question:

 

>>>> mv log /tmp
>>>> Or
>>>> mv log /tmp/
>>>> From the above command which one is correct 

 

It doesn't matter.  Either one will do the same thing.

rajesh73
Super Advisor

Re: mv command

-------Well, the simple explanation is that the data.zip file will be moved from the /tmp directory to the /log directory.

From the command not create log directory in /. it will create log file. In /
Steven Schweda
Honored Contributor

Re: mv command

> From the command not create log directory in /. it will create log file. In /

   Everything's complicated.  A command like:
      mv path1/name1 path2/name2
can do different things, depending on what path2/name2 is.  If
path2/name2 is an existing directory, then the file at path1/name1 will
be moved into that directory, becoming "path2/name2/name1".
If path2/name2 does not exist, then the file at path1/name1 will be
moved to a file at "path2/name2".  (And if path2/name2 is an existing
regular file, then it will be overwritten.)

   If you want the file "data.zip" to be moved into the _directory_
"/log", and you don't know if the directory "/log" exists, then you
might be happier with a command like:
      mv data.zip /log/data.zip
or:
      mv data.zip /log/
either of which makes it clear that "/log" is expected to be a
directory.  And these commands should fail if "/log" is not a directory.

> mv log /tmp
> Or
> mv log /tmp/
> From the above command which one is correct [?]

 

   Sadly, that's not enough information.  The result depends on whether
"/tmp" is a directory.  The second one is probably what you want, but
the first can work if "/tmp" is a directory.  

rajesh73
Super Advisor

Re: mv command

Now I told clearly what mistake I done

I want to move data.zip file to /tmp/log
#pwd
#/tmp
#ls -ltr
-rwx-rwx-rwx. data.zip
#mv data.zip /log

But I unfortunately u missed to put tmp in the above command

So any impact happen from the above command
Steven Schweda
Honored Contributor

Re: mv command

> So any impact happen from the above command

  Is that a question?  If so, then using a question mark ("?") can be
helpful.

   Define "impact"?  Which "the above command"?  If you moved a file
into the wrong place, then you should be able to move it from there into
the right place.

hpuxrox
Respected Contributor

Re: mv command

impact?

 

 

Well if /log is suppost be on a different file system and is not mounted. You risk filling the / file system depending on the size of the file being moved.

 

If there is no /log at all. Then you likely to create a file called "log" in the / file system.