cp执行命令,如何直接覆盖不提示

参数说明

-i, --interactive prompt before overwrite (overrides a previous -n option)   #文件存在是,交互式提示是否覆盖

-n, --no-clobber do not overwrite an existing file (overrides a previous -i option)  #文件存在,忽略

-f, --force if an existing destination file cannot be opened, remove it and try again (redundant if the -n option is used) #强制覆盖文件

-R, -r, --recursive          copy directories recursively  #递归目录操作

由于别名的存在,当执行下面命令时, 
cp -f test.txt test1.txt
会被替换为
cp -i -f test.txt test1.txt
所以会有交互式的提示是否覆盖文件
 
查看别名具体配置

[root@VM_145_128 ~]# alias cp
alias cp='cp -i'

1、永久关闭当前用户下的cp别名配置

sed -i "s/alias cp='cp -i'/#alias cp='cp -i'/g" ~/.bashrc 

source ~/.bashrc 

 

2、屏蔽当前命令使用别名

[root@VM_166_132 ~]# cat test1.txt
ddddddd
[root@VM_166_132 ~]# \cp -f test.txt test1.txt
[root@VM_166_132 ~]# cat test1.txt
test1

 

转载 http://w-tingsheng.blog.163.com/blog/static/2505603420124309130528/  

posted @ 2016-12-02 15:40  hufangrui  阅读(71504)  评论(1编辑  收藏  举报