Saturday, July 17, 2010

cp Command

Copies files from one location to another.

Syntax

cp [OPTION]... SOURCE DEST

-a, --archivesame as -dpR
--backupmake a backup of each existing destination file
-blike --backup but does not accept an argument
--copy-contentscopy contents of special files when recursive
-dsame as --no-dereference --preserve=link
--no-dereferencenever follow symbolic links
-f, --forceif an existing destination file cannot be opened, remove it and try again
-i, --interactiveprompt before overwrite
-Hfollow command-line symbolic links
-l, --linklink files instead of copying
-L, --dereferencealways follow symbolic links
-psame as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: links,
all
--no-preserve=ATTR_LISTdon't preserve the specified attributes
--parentsappend source path to DIRECTORY
-Psame as '--no-dereference'
-R, -r, --recursivecopy directories recursively
--remove-destinationremove each existing destination file before attempting to open it (contrast with --force)
--reply={yes,no,query}specify how to handle the prompt about an existing destination file
--sparse=WHENcontrol creation of sparse files
--strip-trailing-slashesremove any trailing slashes from each SOURCE argument
-s, --symbolic-linkmake symbolic links instead of copying
-S, --suffix=SUFFIXoverride the usual backup suffix
--target-directory=DIRECTORYmove all SOURCE arguments into DIRECTORY
-u, --updatecopy only when the SOURCE file is newer than the destination file or when the destination file is missing
-v, --verboseexplain what is being done
-x, --one-file-systemstay on this file system

Examples

cp file.sh newfolder

Copies the file.sh from current directory to the newfolder directory.

cp /home/log.txt /home/backuplog.txt

Copies the log.txt file in the home directory to the home directory itself but as backuplog.txt. The files are identical however have different names.

cp *.c new

Copy all files ending in .c extention into the "new" directory.

No comments:

Post a Comment