How does the '-i' option modify the behavior of the 'cp' command?

0206

The -i option (or --interactive) modifies the behavior of the cp command by prompting the user for confirmation before overwriting an existing file at the destination.

Behavior:

  • Prompt for Confirmation: If the destination file already exists, the command will ask the user whether they want to overwrite it. The user can then choose to proceed or cancel the operation.

Example Usage:

cp -i source_file.txt destination_file.txt

If destination_file.txt exists, the terminal will display a prompt like:

cp: overwrite 'destination_file.txt'? 

You can then respond with y (yes) to overwrite or n (no) to skip the copy.

Purpose:

  • Prevent Accidental Data Loss: This option is useful for avoiding unintentional overwrites, providing an extra layer of safety when copying files.

If you have any further questions or need more details, feel free to ask!

0 Comments

no data
Be the first to share your comment!