Skip to content

How to Copy Files Without Prompts on Enterprise Linux 6

  • by
As I can remember, command cp never asks you the copy operation for sure except that you add -i option to enter the interactive mode. But with newer Enterprise Linux (i.e. CentOS 6.5), it will ask you all the time.
[root@test ~]# cp file1 file2
cp: overwrite `file2'? y

Let's see which cp it's using now.
[root@test ~]# which cp
alias cp='cp -i'
        /bin/cp

Oh, now we know cp is not the cp we used to be, it's an alias command. In such situation, you have several options to skip the prompts:
  1. Redirect "y" to the command in advance. But I don't think it's a good practice.
  2. [root@test ~]# echo "y" | cp file1 file2
    cp: overwrite `file2'? [root@test ~]#

  3. Unalias the command. It could be used to meet dynamic requirements, e.g. shell scripts.
  4. [root@test ~]# unalias cp
    [root@test ~]# which cp
    /bin/cp

  5. Remove or comment out the alias in the first place ~/.bashrc.
  6. [root@test ~]# vi ~/.bashrc
    ...
    #alias cp='cp -i'

  7. Choose another alias name for 'cp -i' to distinguish them.
  8. [root@test ~]# vi ~/.bashrc
    ...
    alias cpi='cp -i'

Leave a Reply

Your email address will not be published. Required fields are marked *