在Linux系统里面,使用cp可以拷贝文件, 遇到覆盖的文件会提示是否覆盖, 这是出于安全考虑.

但是如果我们明知需要覆盖并且需要拷贝多个文件或目录的时候,只能单条操作,比较麻烦.

cp参数

查看cp的参数:

[root@bob ~]# cp --help

Usage: cp [OPTION]... [-T] SOURCE DEST

or: cp [OPTION]... SOURCE... DIRECTORY

or: cp [OPTION]... -t DIRECTORY SOURCE...

Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

-a, --archive same as -dR --preserve=all

--attributes-only don't copy the file data, just the attributes

--backup[=CONTROL] make a backup of each existing destination file

-b like --backup but does not accept an argument

--copy-contents copy contents of special files when recursive

-d same as --no-dereference --preserve=links

-f, --force if an existing destination file cannot be

opened, remove it and try again (this option

is ignored when the -n option is also used)

-i, --interactive prompt before overwrite (overrides a previous -n

option)

-H follow command-line symbolic links in SOURCE

-l, --link hard link files instead of copying

-L, --dereference always follow symbolic links in SOURCE

-n, --no-clobber do not overwrite an existing file (overrides

a previous -i option)

-P, --no-dereference never follow symbolic links in SOURCE

-p same as --preserve=mode,ownership,timestamps

--preserve[=ATTR_LIST] preserve the specified attributes (default:

mode,ownership,timestamps), if possible

additional attributes: context, links, xattr,

all

-c deprecated, same as --preserve=context

--no-preserve=ATTR_LIST don't preserve the specified attributes

--parents use full source file name under DIRECTORY

-R, -r, --recursive copy directories recursively

--reflink[=WHEN] control clone/CoW copies. See below

--remove-destination remove each existing destination file before

attempting to open it (contrast with --force)

--sparse=WHEN control creation of sparse files. See below

--strip-trailing-slashes remove any trailing slashes from each SOURCE

argument

-s, --symbolic-link make symbolic links instead of copying

-S, --suffix=SUFFIX override the usual backup suffix

-t, --target-directory=DIRECTORY copy all SOURCE arguments into DIRECTORY

-T, --no-target-directory treat DEST as a normal file

-u, --update copy only when the SOURCE file is newer

than the destination file or when the

destination file is missing

-v, --verbose explain what is being done

-x, --one-file-system stay on this file system

-Z set SELinux security context of destination

file to default type

--context[=CTX] like -Z, or if CTX is specified then set the

SELinux or SMACK security context to CTX

--help display this help and exit

--version output version information and exit

强制拷贝

其中-f (--force)就是强制覆盖不提示.

命令如下:

cp -f xxx /opt/www/xxx

但实际执行的时候依然会提示是否覆盖.原因是为了安全考虑,系统把cp命令加了个参数-i 提示,可以查看alias

[root@bob ~]# alias

alias cp='cp -i'

除了cp还有mv,rm两个命令都是这样处理的.

解决方法

方法1:

[root@bob ~]# vi ~/.bashrc

在alias cp=’cp -i’前加上#注释掉这行,:wq保存退出,然后重新登陆就可以了。

方法2:

拷贝时加\,如

[root@bob ~]#\cp src dst

方法3:

临时取消cp的alias

[root@bob ~]#unalias cp

[root@bob ~]#cp a /test/a

大家试试吧.

参考:https://blog.csdn.net/lanmolei814/article/details/37725999/

linux里强制覆盖,Linux cp命令无法强制覆盖相关推荐

  1. linux cp命令不提示覆盖,Linux中cp命令不提示直接覆盖的方法

    新做了服务器,cp覆盖时,无论加什么参数-f之类的还是提示是否覆盖,这在大量cp覆盖操作的时候是不能忍受的. 把a目录下的文件复制到b目录 cp –r a/* b 执行上面的命令时,b存在的每个文件都 ...

  2. linux复制文件scp命令,Linux 中的文件复制cp命令和scp命令详解

    Linux 中的文件复制cp命令和scp命令详解 在使用操作系统的使用过程中,常常需要复制文件到本地或者传输文件到其他电脑上,这时候用到两个命令cp和scp. cp命令用来复制文件或者目录.scp是s ...

  3. linux命令中的cp,Linux高级技术:关于cp命令中拷贝所有的写法

    Linux高级技术:关于cp命令中拷贝所有的写法 发布时间:2007-09-30 21:39:36来源:红联作者:GiftPot 今天在编写一个脚本的时候,发现一个比较奇怪的问题:就是在使用cp拷贝当 ...

  4. linux cp命令 强制覆盖,Linux中使用cp命令进行强制覆盖的方法

    cp在拷贝时,如果遇到相同的文件名的文件,就会不断询问是否覆盖,让你输入yes or no .为什么呢?这是为了linux为了安全考虑,在cp命令上用了别名.也就是你输入只是输入cp命令时,其实系统是 ...

  5. linux cp 全覆盖,Linux中使用cp命令进行强制覆盖的方法

    cp在拷贝时,如果遇到相同的文件名的文件,就会不断询问是否覆盖,让你输入yes or no .为什么呢?这是为了linux为了安全考虑,在cp命令上用了别名.也就是你输入只是输入cp命令时,其实系统是 ...

  6. Linux cp命令无法强制覆盖

    在Linux系统里面,使用cp可以拷贝文件, 遇到覆盖的文件会提示是否覆盖, 这是出于安全考虑. 但是如果我们明知需要覆盖并且需要拷贝多个文件或目录的时候,只能单条操作,比较麻烦. cp参数 查看cp ...

  7. Linux下如何使CP命令不提示覆盖

    在Linux下使用CP命令,经常会提示是否覆盖,如果是太批量的文件覆盖,老是这么提示,会很烦的.那如何解决这个问题呢? 我们先来看一下原因吧! 一般我们使用的命令是cp -rf sourcefile ...

  8. 【linux】Linux cp命令拷贝 不覆盖原有的文件

    文章目录 print和printf输出重定向 print items > output-file 保存items到文件,如分别保存用户和家目录, awk -F: '{ print $1 > ...

  9. linux里find用法,Linux中find命令基本使用方法

    Linux中find命令是系统中查找文件的命令,可以帮助用户快速找出自己所需要的文件. 通过文件名查找 find -name 文件名 find /etc/ -name passwd ###查找/etc ...

最新文章

  1. Asp.net 用户控件和自定义控件注册
  2. 脚本程序转变为可执行程序的第三方库——pyinstaller
  3. 主题图片_临床医学院“树树皆秋色,山山唯落晖”主题图片征集活动
  4. oracle给换服务器,Oracle数据库更换服务器10分钟切换方案
  5. Vue使用全局样式,页面没有发生变化:逗号是中文的,引起错误,样式不变化 也没有报错就是不起作用
  6. 网站页首可关闭广告条
  7. java标签组件命名_java编程规范之java命名规范
  8. android 课堂讨论内容,Android端课堂交互应用研究与实现
  9. THREEJS - 获取场景中模型数据
  10. 2019最新 Java商城秒杀系统的设计与实战视频教程(SpringBoot版)_1-2核心技术列表...
  11. Vmware安装Vmware Tools工具
  12. 成都最稳定的dns服务器地址,成都首选DNS服务器地址
  13. lua工具库penlight--06数据(二)
  14. BUU-0CTFpiapiapia(反序列化字符串逃逸)
  15. python爬虫爬取网页壁纸图片(《底特律:变人》)
  16. 微信小程序商城篇(一)首页功能
  17. 猛兽来袭——Integral Protocol
  18. 基于Ardupilot/PX4固件,APM/PIXhawk硬件的VTOL垂直起降固定翼软硬件参数调试(第三篇)故障保护及问题诊断
  19. python sys.path用法
  20. Android直播开发之旅(25):使用AES算法加密多媒体文件(+RSA+MD5+Base64)

热门文章

  1. Golang Import使用入门
  2. 历史上那些差点被扼杀的数学天才,考试、偏见都是凶手
  3. 摄像头驱动0V7725学习笔记连载(三):0V7725 SCCB时序的实现
  4. HTTP协议状态码详解(HTTP Status Code)(转)
  5. vtkDataObject 与vtkImageData
  6. 连续和问题C语言,内存连续的有关问题
  7. java常量数组吗_java – 如何在注释中使用数组常量
  8. linux mysql web界面吗_Linux下安装MySQL Web 管理工具phpMyAdmin
  9. Python+OpenCV:图像修复(Image Inpainting)
  10. 基于Modbus TCP-IP协议的WEINVIEW HMI与PC通讯