Unix Manual Pages

A History of Unix

Unix in Summary

An introductory tutorial on Unix...


Selecting a Shell

Regular Expressions...

Perl and Unix...

Help with vi...

Shell scripting...


The 10 Unix commands every beginner needs to know...

The 10 most misunderstood commands...

The 62 Core Commands

Commands by Category

Alphabetic list of commands...


Copyright/Copyleft info...

cd





Copy Files

cp [-R [-H | -L | -P]] [-f | -i] [-p] source_file target_file
cp [-R [-H | -L | -P]] [-f | -i] [-p] source_file ... target_directory
In the first form, the cp utility copies the contents of the 'source_file' to the 'target_file'. In the second form, the contents of each named 'source_file' is copied to the destination 'target_directory'. The names of the files are left unchanged. If the same file is used as source and destination, the copy will fail.

Examples

There is a file in /usr/bin/~mschmeckle/ called stuff.html and you want to copy (not move) it to /www/httpd/htdocs/

Using absolute paths:
cp /usr/bin/~mschmeckle/stuff.html /www/httpd/htdocs

If you are already in /usr/bin/~mschmeckle/ and you want to use relative paths:
cp stuff.html /www/httpd/htdocs

Options

  • -R
    Recursive
    If the 'source_file' is a directory, the directory and entire subtree is copied. Symbolic links are copied.
  • -H
    If the -R option is specified, symbolic links on the command line are followed. Symbolic links encountered in the tree scan are not followed.
  • -L
    If the -R option is specified, all symbolic links are followed.
  • -P
    If the -R option is specified, no symbolic links are followed.
  • -f For each existing destination pathname, remove it and create a new file, without prompting for confirmation regardless of its permissions. The -f option overrides any previous -i options.
  • -i
    Cause cp to write a prompt to the standard error output before copying a file that would overwrite an existing file. If the response from the standard input begins with the character `y' or `Y', the file copy is attempted. The -i option overrides any previous -f options.
  • -p
    Cause cp to preserve in the copy as many of the modification time, access time, file flags, file mode, user ID, and group ID as allowed by permissions.

    If the user ID and group ID cannot be preserved, no error message is displayed and the exit value is not altered.

    If the source file has its set user ID bit on and the user ID can- not be preserved, the set user ID bit is not preserved in the copy's permissions. If the source file has its set group ID bit on and the group ID cannot be preserved, the set group ID bit is not preserved in the copy's permissions. If the source file has both its set user ID and set group ID bits on, and either the user ID or group ID cannot be preserved, neither the set user ID or set group ID bits are preserved in the copy's permissions.

    -----
  • © 1999-2004 Matchstick Consulting