Sunday, January 19, 2014

CP Command in Linux

CP Command Examples in Linux

Command: cp

Command Usage: copy files and directories

syntax: $ cp [options] source destination

Command Examples:

1. To display options and help of cp command

    $ cp --help

2. To copy a file from a source to a destination

    $ cp /home/example.txt  /tmp/example.txt

3. To copy a file from source to destination with a different name

    $ cp /home/test.txt  /tmp/sample.txt

4. To copy a directory from source to destination  recursively

    $ cp -r original  backup

5. To copy multiple files and directories

    $ cp file1.txt file2.txt file3.txt  /tmp

    $ cp  -r dir1/ dir2/ /tmp

6. To preserve the links while copying

    $ cp -d test1.sh  /home/dhana/work/test1.sh

7. To create a hardlink to a file while cp

    $ cp -l sample.txt testdir/

8. To create a soft link to a file instead of copy

    $ cp -s libjavascriptcoregtk-3.0.so.0.13.4  libjavafs.so

9. To preserve attributes of file and directory

    cp -p sample.txt sampledir/

10. To copy only when the SOURCE file is newer than
      the destination file or when the destination file is missing

      $ cp -v -u sample.txt  /home/dhana/sampledir/

11. To copy files in interactive mode

      $ cp -i test.txt  /home/dhana/sampledir/

CP Command in Linux

No comments:

Post a Comment

Linux Tips and tricks,Online Linux Helpers