Ubuntu CP Command Option to Prompt Before Overwriting
This article explains how to prevent accidental data loss when copying files in Ubuntu. It focuses on the specific command-line option that forces the system to ask for confirmation before replacing existing files. By using this interactive flag, users can ensure they do not unintentionally overwrite important data during file management tasks.
The option that makes the cp command prompt before
overwriting existing files is -i. This flag stands for
interactive mode. When you include this option in your command, the
terminal will ask for a yes or no confirmation if the destination file
already exists.
To use this option, type the following command in your terminal:
cp -i source_file destination_file
If the destination file exists, the system will display a prompt
similar to cp: overwrite 'destination_file'?. You must type
y and press Enter to proceed, or n to cancel
the operation.
Many Ubuntu users configure this option by default using an alias.
You can add the following line to your .bashrc file to
always enable prompting:
alias cp='cp -i'
This ensures every copy operation requires confirmation when overwriting, providing an extra layer of safety for your files.