Examples of using the cp command

Examples of using the cp command

To copy a file from a subdirectory to the current working directory:

   cp notes/note3 sect3.txt

This copies the file note3 from the subdirectory notes to the file sect3 in the current working directory. A relative pathname notes/note3 is used to define the source file.


To copy a file from another directory to the current working directory, preserving the file name:

   cp /usr/lib/more.help .

This creates a copy of the file more.help in the current working directory. A full pathname /usr/lib/more.help is used to define the source file.


To copy a file from another user's directory using a relative pathname:

   cp ~helper/tmp/for_john tmp/comments

This copies the file for_john from the directory tmp in which is in the home directory of the user helper, to a directory with the same name in the user's home directory. The name of this new file is comments.

Notice that a relative pathname ~helper/tmp/for_john is used to define the source file.


[Home] [Search] [Index] This site maintained by unixhelp@math.rutgers.edu
This page was last updated on September 05, 2006 at 10:29 am and is maintained by webmaster@math.rutgers.edu.
For questions regarding courses and/or special permission, please contact mclausen@math.rutgers.edu.
For questions or comments about this site, please contact help@math.rutgers.edu.
© 2012 Rutgers, The State University of New Jersey. All rights reserved.