Table of Contents
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
Short | Long | Description |
---|---|---|
-a | --archive | same as -dR --preserve=all |
-d | Same as --no-dereference --preserve=links | |
-f | --force | If an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used) |
-i | --interactive | Prompt before overwrite (overrides a previous -n option) |
-n | --no-clobber | Do not overwrite an existing file (overrides a previous -i option) |
-P | --no-dereference | Never 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 | |
--parents | Use full source file name under DIRECTORY | |
-R, -r | --recursive | Copy directories recursively |
--remove-destination | Remove each existing destination file before attempting to open it (contrast with --force) | |
--strip-trailing-slashes | Remove any trailing slashes from each SOURCE argument | |
-t | --target-directory=DIRECTORY | Copy all SOURCE arguments into DIRECTORY |
-u | --update | Copy only when the SOURCE file is newer than the destination file or when the destination file is missing |
-v | --verbose | Explain what is being done |
-x | --one-file-system | Stay on this file system |
--help | Display the help and exit | |
--version | Output 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
Dangling symlink
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.