About Linux FAQ

Browse More FAQs:

Linux Copy File Command ( cp command examples )

Posted by Vivek Gite [Last updated: May 29, 2008]

Q. How do I copy file under Linux? How do I make 2nd copy of a file?

A. To copy files and directories use cp command under Linux, UNIX, and BSD operating systems. cp is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.

To make a copy of a file in the current directory, enter:
$ cp file.doc file.doc.bak

To copy a file in your current directory into another directory, enter:
$ cp filename /tmp
$ ls /tmp/filename
$ cd /tmp
$ ls
$ rm filename

To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
$ cp -p filename /path/to/new/location/myfile

To copy all the files in a directory to a new directory, enter:
$ cp * /home/tom/backup

To copy a directory, including all its files and subdirectories, to another directory, enter (copy directories recursively):
$ cp -R * /home/tom/backup

E-mail this to a friend      Printable version

Related Other Helpful FAQs:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.