Linux Copy File Command ( cp command examples )
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:
- UNIX / Linux: copy master boot record (MBR)
- Linux or UNIX securely copy files across a network computer
- Linux Copy all the files including subdirectories from DVD / Floppy / CD / Other directory (recursive copy)
- Linux Copy One Hard Disk to Another Using dd Command
- Linux / UNIX: Cannot Preserve Ownership Error when Files are Moved or Copied
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!
Tags: access control, bsd, copy, copy file, cp command, filesystem, Linux, linux copy file command, shell, UNIX




Recent Comments
Yesterday ~ 3 Comments
09/06/2008 11:03 pm (2 days ago) ~ 12 Comments
09/06/2008 02:10 pm (2 days ago) ~ 7 Comments
09/06/2008 06:51 am (2 days ago) ~ 2 Comments
09/06/2008 01:28 am (2 days ago) ~ 3 Comments