Tuesday, January 10, 2012

Copy & Delete


Copy (cp):
               Copies file and directories.
               If copying from one destination to other, the path could be either absolute or relative.

                  E.g:
                           Absolute path: cp /users/sr1/a.txt /users1/sr2
                           Relative path: cp a.txt ../sr2 (assuming the directory structure to be same as above)


        Attributes:

  • -f: if an existing destination file cannot be opened, remove it and try again
  • -i: prompt before overwrite
  • -l: link files instead of copying
  • -R: copy directories recursively
  • -r: remove each existing destination file before attempting to open it (contrast with --force)
  • -s: make symbolic links instead of copying
  • -u: copy only when the SOURCE file is newer than the destination file or when the destination file is missing

Delete (rm):


        Removes files and directories.

     Attributes

  •         
  • -d: unlink FILE, even if it is a non-empty directory (super-user only)
  • -f: forcefully remove the file, no prompt if non-existing file
  • -i: prompt before any removal
  • -r, -R: remove the contents of directories recursively 

E.g: for removing all files in a directory and directory itself

   rm -rf directoryname
   
Note: rm -rf  * is most disastrous command in unix as it delete all the files in the directory and sub directories.

No comments:

Post a Comment