04 January 2012

mv Command in Linux/Unix

3 comments
mv Command in Linux/Unix

                         mv command serve two purpose in Linux/Unix
1. renaming file or directory
2. moves file or files to different directory (like cut option in windows)

Syntax

                mv [source]  [destination]               //just like cp command

Example

 1. Renaming  file or directory

                       To rename a file abc.lst to gef.lst we  should write
                     
                           -->  mv  abc.lst   gef.lst 
$ ls
abc.lst    def.lst           examples.desktop     jscript
pqr.lst     sandeep.lst   xyz.lst

$ mv abc.lst gef.lst

$ ls
css    Desktop    gef.lst    jscript   pqr.lst

*unlike cp command mv command does not create new file , it just replace the file-name in the existing directory entry with the new name in the above example.

*Similarly to rename a directory we should write

                                   mv   old-dir-name  new-dir-name
$ ls
Desktop    html    newfile     sandeep2.lst     xyz.lst

$ mv newfile newfile1

$ ls
Desktop   html    newfile1    sandeep2.lst     xyz.lst



2. Moving file(s) to a directory :


                               This is similar to cut and paste in windows.


Syntax


                 mv  file1 file2 file3  dir-name

Example
$ ls
css1          Downloads   js           pqr.lst            shell
def.lst       gef.lst            Music   sandeep          Videos
Desktop   html              newfile1 sandeep2.lst   xyz.lst

$ mv pqr.lst def.lst gef.lst xyz.lst newfile1

$ ls
css    Desktop      examples.desktop   js         newfile1
css1  Documents  html                      jscript    Pictures
cut1  Downloads  java                      Music    Public
Videos                  sandeep.lst           sandeep2.lst

$ cd newfile1

$ ls
def.lst gef.lst pqr.lst xyz.lst

If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

3 comments:

  1. It was so nice article and useful to Informatica learners. we also provide linux/unix course online training our Cubtraining is leader in providing Software Training

    ReplyDelete
  2. Really like your stuff, every article of yours is a fantastic read. Thank you!
    UNIX&LINUX Online Training in USA

    ReplyDelete
  3. Really like your stuff, every article of yours is a fantastic read. Thank you!
    UNIX&LINUX Online Training in USA

    ReplyDelete