User Tools

Site Tools


cp

If you want to send us your comments, please do so. Thanks
More on comments


cp

When -a or -u are used -i is ignored
Some command options

ShortLongDescription
-a--archivesame as -dR --preserve=all
-d Same as --no-dereference --preserve=links
-f--forceIf an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used)
-i--interactivePrompt before overwrite (overrides a previous -n option)
-n--no-clobberDo not overwrite an existing file (overrides a previous -i option)
-P--no-dereferenceNever follow symbolic links in SOURCE
-p Same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]Preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all
--parentsUse full source file name under DIRECTORY
-R, -r--recursiveCopy directories recursively
--remove-destinationRemove each existing destination file before attempting to open it (contrast with --force)
--strip-trailing-slashesRemove any trailing slashes from each SOURCE argument
-t--target-directory=DIRECTORYCopy 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
--helpDisplay the help and exit
--versionOutput version information and exit

standard command

Standaard copy options. Copy from current folder to . foldertocopyto/

cp --recursive --update --no-dereference --preserve=all --verbose . foldertocopyto/

is

cp -rPv --preserve=all . foldertocopyto/

Check with

diff -rs . foldertocopyto/

if needed

Copy (hidden) files and directories

Situation 1

mkdir --parents /tmp/somedirectory
cp --recursive /home/user/somedirectory /tmp/somedirectory

All the contents of /home/user/somedirectory is copied into /tmp/somedirectory

Situation 2

/tmp/otherdirectory does not exist and is not created before

cp --recursive /home/user/somedirectory /tmp/otherdirectory

/tmp/otherdirectory is created and the contents of /home/user/somedirectory is copied into /tmp/otherdirectory

Situation 3

/tmp/otherdirectory does exist

cp --recursive /home/user/somedirectory /tmp/otherdirectory

somedirectory is copied into /tmp/otherdirectory. The result: /tmp/otherdirectory/somedirectory inclusive all the files in /home/user/somedirectory

Preserve filedate

In order to preserve the file date when copying add the --preserve=timestamps option

cp --preserve=timestamps

Errors

is not a directory

cp file.1 file.2
cp: target 'file.2' is not a directory

Check your aliases. If a command has options --preserve=all and / or --no-dereference then this error may occur

No such file or directory

When trying to create a symlink from a client on a server. The server folder “folderonserver” is mounted on the client (via sshfs)

ln -sf /mnt/server/folderonserver/file.1.txt /mnt/folderonserver/file.txt
ln: failed to create symbolic link '/mnt/folderonserver/file.txt': No such file or directory

Create a symbolic link on the client

ln -sf /mnt/server/folderonserver/file.1.txt file.txt

Copy the symbolic link file to the server

cp file.txt /mnt/server/folderonserver/
cp: not writing through dangling symlink '/mnt/server/folderonserver/file.1.txt'

It is not possible to have a symbolic link on a server for use on a client where it refereneces a file on the server

preserving times not permitted

cp: preserving times for 'file': Operation not permitted 

The timestamp can not be preserved for a file the user does not own


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
cp.txt · Last modified: 11-07-2021 21:08 by wim