From: http://en.wikipedia.org/wiki/Cp_%28Unix%29
Examples
To make a copy of a file in the current directory, enter:cp prog.c prog.bak
To copy a file in your current directory into another directory, enter:
cp jones /home/nick/clients
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 smith smith.jr
To copy all the files in a directory to a new directory, enter:
cp /home/janet/clients/* /home/nick/customers
To copy a directory, including all its files and subdirectories, to another directory, enter:
cp -R /home/nick/clients /home/nick/customers
cp -R /home/nick/clients/ /home/nick/customers
on a GNU-based system, it does the same thing as without the slash; however, if you run the same thing on a BSD-based system, it will copy all the contents of the "clients" directory over, instead of the "clients" directory itself.To copy a specific set of files to another directory, enter:
cp jones lewis smith /home/nick/clients
To use pattern-matching characters to copy files, enter:
cp programs/*.c .
Copying a file to an existing file is done by opening the existing file in update mode which requires write access and results in the target file retaining the permissions it had originally.
没有评论:
发表评论