Using the -i Option for Interactive Copying
When copying files, you might encounter situations where the destination already contains a file with the same name. The -i
option makes cp
interactive, prompting you before overwriting existing files.
Let's simulate this scenario:
First, let's see the content of an existing file:
cat ~/project/test_file.txt
Tips: If you're unfamiliar with the cat
command, don't worry; it will be explained in detail later.
You should see "Original content" displayed.
Now, let's try to copy a file with the same name:
cp -i ~/project/new_test_file.txt ~/project/test_file.txt
When prompted, type y
and press Enter to overwrite the file. If you don't want to overwrite, type n
and press Enter.
The -i
option stands for "interactive". It tells cp
to ask for confirmation before overwriting any existing files. This is a safety measure to prevent accidental data loss.
Now, check the content of the file:
cat ~/project/test_file.txt
If you chose to overwrite, you should see "New content" displayed. If not, you'll still see "Original content".