|
|
To copy one or more files, use the
cp(C)
command, which takes one of the following formats:
cp filename copyname
cp filename ... pathname
In the first format, filename (with optional path) is the name of the existing file that you want to be copied; copyname (with optional path) is the name you want the copy to be created with.
If you are using the second format to copy a group of files, you can only specify a directory, pathname, as the destination of the specified files. filename and copyname cannot be the same if they are both in the same directory.
When you copy a file you are creating a duplicate of it, which occupies additional space in the filesystem. Although the contents of the new file are the same as those of the original file, the new copy has its own inode number; any operations carried out on it have no impact on the original.
For example, to copy the file project1 from your current directory to the directory /u/workgrp, type the following command:
$ cp project1 /u/workgrpThe copy will retain the name project1, but will have a different pathname.
You can copy a file to your current directory by typing a command line like the following:
$ cp ../../a.out .In this case, the file called a.out is located two levels above the current working directory, and is to be copied to the current location (as indicated by the ``.'' notation).
When you copy a file, you automatically become its new owner. Accordingly, you must have read permission on a file before you can copy it. You can place files in any directory for which you have write permission. If you want to create a copy of a file without changing its ownership, use the command copy -o instead of cp; this preserves the owner and group of the file. For example, to copy /tmp/johnsfile to your home directory without changing the ownership of the file, type the following:
$ copy -o /tmp/johnsfile johnsfileFor information on how you can assign the ownership of a file to someone else, see ``Giving a file to someone else'' and ``Access control for files and directories''.