Sunday, October 7, 2012

Basic File Handling ( Copy ,Move,Rename ,Delete )

"cp" command

     used to copy files.

          cp filepath/filename  destination/filename

        or

         cp filepath/filename  destination

   ex:
        $ cp exit.png  mydir/q.png

               copies the file exit.png into mydir as q.png


        $ cp Library.sql  mydir

            copies the file Library.sql inside the directory mydir


  copying multiple files ex:


"mv" command

     used to move files

       ex:
          $ mv out1-1.ogv mydir/out1-1.ogv

          the file out1-1.ogv is moved in to mydir

    moving multiple files with mv

         mv file1 file2 file3 destination 

 ex:

   use * when copying or moving files to copy or move all the files in the   current directory     



   the "mv" command can be also used to rename files

   ex :



"rename" command

         used to rename files

        rename a b c

      a  - part of the file name to be renamed
      b - new part of the filename
      c - the file

   ex: to rename a file named "aa" to "newAA"

      $ rename  aa  newAA  aa


      to rename the "newAA" as "oldAA" only the part "new" has to be renamed to old

      $ rename new old newAA

 using " -v " option with the command rename prints what is going to be done

 ex: to change the extension of all the png files to jpg

    $ rename -v png jpg *.png


"rm" command

      used to delete files

      rm filepath/filename

     ex:  $ rm myfile
 
         deletes the file named myfile in current directory    

    deleting multiple files with rm

   ex:   $ rm file1 file2 file3




No comments:

Post a Comment