Linux cp mv overwrite without prompt (disable interactive mode)

May 10, 2016 Bash, Linux

Linux cp mv disable prompt
Some Linux distributions (for example: RedHat) have aliases configured in the system, especially for root user, which modify basic command line operations like: cp, mv by adding “-i” parameter to prevent user from accidental overwriting or deleting files (interactive mode). This can be disturbing, especially when we are dealing with many files at a time. To get rid of this issue we can modify aliases in the system to disable interactive mode.

Verify current aliases:

[root@tuxfixer ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

To disable interactive mode for copy and move operations, we need to edit /root/.bashrc file and comment out the corresponding lines:

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

Now log out and log in again for the changes to take effect and verify aliases after changes:

[root@tuxfixer ~]# alias
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

You shouldn’t be now prompted for confirmation when overwriting files during copy and move operations.

One thought on “Linux cp mv overwrite without prompt (disable interactive mode)”

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.