I want to cp
a directory but I do not want to overwrite any existing files even it they are older than the copied files. And I want to do it completely noninteractive as this will be a part of a Crontab Bash script. Any ideas?
If you are copying files using drag-drop or copy/paste, you may simply choose “Skip this file” or “Skip these files” option to not overwrite the files that are already existed at the destination folder. Or, if you are using command line copy, you can answer N to bypass these files that are already existed.
1 Answer. The best method would be for you to learn to create a copy yourself before editing a file. Yes. From command line set the "immutable" attribute (only the admin can remove that option) and nobody will be able to alter the file (edit, remove, move etc.).
By default, cp will overwrite files without asking. If the destination file name already exists, its data is destroyed. If you want to be prompted for confirmation before files are overwritten, use the -i (interactive) option.
In order to copy the content of a directory recursively, you have to use the “cp” command with the “-R” option and specify the source directory followed by a wildcard character.
Taken from the man page:
-n, --no-clobber do not overwrite an existing file (overrides a previous -i option)
Example:
cp -n myoldfile.txt mycopiedfile.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With