linux 操作系统下cp命令介绍及案例应用

linux 操作系统下cp命令介绍及案例应用

cp命令是Linux操作系统中用于复制文件和目录的基本命令。它的功能强大,适用于各种文件管理任务

cp命令概述

  • 基本语法:
  • bash
  • cp [options] <source> <destination>

功能: 复制单个文件或多个文件到指定位置。 递归复制目录及其内容。 选项可以用来控制复制行为,如保留文件属性、强制覆盖等。

常用选项

  • -r 或 --recursive: 递归复制整个目录及其内容。
  • -p: 保留文件的时间戳、权限和所有者信息。
  • -f: 强制覆盖目标文件而不提示。
  • -i: 在覆盖文件前提示用户确认。
  • -v: 显示详细的复制过程信息。
  • -u: 仅在源文件比目标文件新时才进行复制。

命令介绍:

root@meng:~# which cp

/usr/bin/cp

root@meng:~# cp

cp: missing file operand

Try 'cp --help' for more information.

root@meng:~# 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.

Mandatory arguments to long options are mandatory for short options too.

-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

--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

By default, sparse SOURCE files are detected by a crude heuristic and the

corresponding DEST file is made sparse as well. That is the behavior

selected by --sparse=auto. Specify --sparse=always to create a sparse DEST

file whenever the SOURCE file contains a long enough sequence of zero bytes.

Use --sparse=never to inhibit creation of sparse files.

When --reflink[=always] is specified, perform a lightweight copy, where the

data blocks are copied only when modified. If this is not possible the copy

fails, or if --reflink=auto is specified, fall back to a standard copy.

Use --reflink=never to ensure a standard copy is performed.

The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.

The version control method may be selected via the --backup option or through

the VERSION_CONTROL environment variable. Here are the values:

none, off never make backups (even if --backup is given)

numbered, t make numbered backups

existing, nil numbered if numbered backups exist, simple otherwise

simple, never always make simple backups

As a special case, cp makes a backup of SOURCE when the force and backup

options are given and SOURCE and DEST are the same name for an existing,

regular file.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>

Report any translation bugs to <https://translationproject.org/team/>

Full documentation <https://www.gnu.org/software/coreutils/cp>

or available locally via: info '(coreutils) cp invocation'

命令案例:

root@meng:~# ls

f1.txt.bz2 f2.txt.bz2 m1.txt m2.txt meng.txt meng.txt.bz2 rec00001f1.txt s1.txt s2.txt snap tmp

root@meng:~# cp m1.txt m1.txt.bak

root@meng:~# ls -arl m1.txt*

-rw-r--r-- 1 root root 109 Sep 9 09:06 m1.txt.bak

-rw-r--r-- 1 root root 109 Sep 2 16:01 m1.txt

root@meng:~# cp -ivrf *.txt tmp/

'm1.txt' -> 'tmp/m1.txt'

'm2.txt' -> 'tmp/m2.txt'

'meng.txt' -> 'tmp/meng.txt'

'rec00001f1.txt' -> 'tmp/rec00001f1.txt'

's1.txt' -> 'tmp/s1.txt'

's2.txt' -> 'tmp/s2.txt'

root@meng:~# ls tmp/

bin m1.txt m2.txt meng.sh meng.txt rec00001f1.txt s1.txt s2.txt

root@meng:~# cp -ivrf *.txt tmp/

cp: overwrite 'tmp/m1.txt'? y

'm1.txt' -> 'tmp/m1.txt'

cp: overwrite 'tmp/m2.txt'? y

'm2.txt' -> 'tmp/m2.txt'

cp: overwrite 'tmp/meng.txt'? y

'meng.txt' -> 'tmp/meng.txt'

cp: overwrite 'tmp/rec00001f1.txt'? y

'rec00001f1.txt' -> 'tmp/rec00001f1.txt'

cp: overwrite 'tmp/s1.txt'? y

's1.txt' -> 'tmp/s1.txt'

cp: overwrite 'tmp/s2.txt'? y

's2.txt' -> 'tmp/s2.txt'

root@meng:~#

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/875015.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

python基础知识(一)

目录 1.注释 2.关键字 3.标识符 4.常见命名方法 5.变量 6.常见的数据类型 1.注释 注释&#xff1a;在程序中&#xff0c;对代码进行解释说明的文字。 在Python中&#xff0c;注释分为两类&#xff1a; &#xff08;1&#xff09;单行注释&#xff1a;# # 注释文字内容…

降维打击 华为赢麻了

文&#xff5c;琥珀食酒社 作者 | 积溪 真是赢麻了 华为估计都懵了 这辈子还能打这么富裕的仗&#xff1f; 其实在苹果和华为的发布会召开之前 我就知道华为肯定会赢 但我没想到 苹果会这么拉胯 华为这是妥妥的降维打击啊 就说这苹果iPhone 16吧 屏幕是变大了、颜色…

AUTOSAR_EXP_ARAComAPI的5章笔记(3)

返回目录 5.3.4 Finding Services Proxy Class提供类(静态)方法来查找“连接”的服务实例。由于服务实例的可用性本质上是动态的(因为它有一个生命周期)&#xff0c;所以ara::com提供了如下两种不同的方法来实现“FindService ”: StartFindService是一个类方法&#xff0c;…

k8s环境搭建(续)

查看节点信息并做快照 kubectl get nodes 将components.yml文件上传到master主机 创建nginx&#xff0c;会在添加一个新的pod kubectl run nginx --imagesnginx:latest 查看nginx的pod信息 [rootk8s-master ~]# kubectl get po -Aowide|grep nginx 出现错误&#xff0c;查…

需求分析概述

为什么要进行需求分析呢&#xff1f; 笑话&#xff1a;富翁娶妻 某富翁想要娶老婆&#xff0c;有三个人选&#xff0c;富翁给了三个女孩各一千元&#xff0c;请 她们把房间装满。第一个女孩买了很多棉花&#xff0c;装满房间的1/2。第 二个女孩买了很多气球&#xff0c;装满…

网络视频流解码显示后花屏问题的分析

问题描述 rtp打包的ps视频流发送到客户端后显示花屏。 数据分析过程 1、用tcpdump抓包 tcpdump -i eth0 -vnn -w rtp.pcap 2、用wireshark提取rtp的payload 保存为record.h264文件 3、用vlc播放器播放 显示花屏 4、提取关键帧 用xxd命令将h264文件转为txt文件 xxd -p…

KEIL中编译51程序 算法计算异常的疑问

KEIL开发 51 单片机程序 算法处理过程中遇到的问题 ...... by 矜辰所致前言 因为产品的更新换代&#xff0c; 把所有温湿度传感器都换成 SHT40 &#xff0c;替换以前的 SHT21。在 STM32 系列产品上的替换都正常&#xff0c;但是在一块 51 内核的无线产品上面&#xff0c;数据…

STM32-HAL库开发快速入门

注:本文主要记录一下STM32CubeMX软件的使用流程,记录内容以STM32外设&#xff08;中断、I2C、USART、SPI等配置&#xff09;在STM32CubeMX中的设置为主&#xff0c;对驱动代码编写不做记录&#xff0c;所以阅读本文最好有标准库开发经验。除第2节外&#xff0c;使用的都是韦东山…

C++的流提取(>>)(输入) 流插入(<<)(输出)

什么是输入和输出流 流提取&#xff08;<<&#xff09;(输入) 理解&#xff1a;我们可以理解为&#xff0c;输入到io流里面&#xff0c;比如是cin&#xff0c;然后从输入流中读取数据 流插入&#xff08;<<&#xff09;&#xff08;输出&#xff09; 理解&#xff…

网络协议头分析

目录 数据的传输与封装过程 以太网完整帧 以太网头部 IP头 TCP头 数据的传输与封装过程 以太网完整帧 ● 对于网络层最大数据帧长度是1500字节 ● 对于链路层最大数据长度是1518字节&#xff08;150014CRC&#xff09;● 发送时候&#xff0c;IP层协议栈程序检测到发送数…

前端 + 接口请求实现 vue 动态路由

前端 接口请求实现 vue 动态路由 在 Vue 应用中&#xff0c;通过前端结合后端接口请求来实现动态路由是一种常见且有效的权限控制方案。这种方法允许前端根据用户的角色和权限&#xff0c;动态生成和加载路由&#xff0c;而不是在应用启动时就固定所有的路由配置。 实现原理…

路由器的固定ip地址是啥意思?固定ip地址有什么好处

‌在当今数字化时代&#xff0c;‌路由器作为连接互联网的重要设备&#xff0c;‌扮演着举足轻重的角色。‌其中&#xff0c;‌路由器的固定IP地址是一个常被提及但可能让人困惑的概念。‌下面跟着虎观代理小二一起将深入探讨路由器的固定IP地址的含义&#xff0c;‌揭示其背后…

用Unity2D制作一个人物,实现移动、跳起、人物静止和动起来时的动画:下(人物动画)

上个博客我们做出了人物的动画机和人物移动跳跃&#xff0c;接下来我们要做出人物展现出来的动画了 我们接下来就要用到动画机了&#xff0c;双击我们的动画机&#xff0c;进入到这样的页面&#xff0c;我这是已经做好的页面&#xff0c;你们是没有这些箭头的 依次像我一样连接…

【Python】Windows下python的下载安装及使用

文章目录 下载安装检测 使用环境搭建下载PycharmPycharm安装 下载 进入官网下载&#xff1a;https://www.python.org/ 点击下载 64位电脑下载该项 安装 勾选 添加至环境变量 使用自定义安装 检测 安装成功后&#xff0c;打开命令提示符窗口&#xff08;winR,输入cmd回车…

红海云 × 紫光同芯 | 数字化驱动芯片领军企业人力资源管理新升级

紫光同芯微电子有限公司&#xff08;以下简称“紫光同芯”&#xff09;是新紫光集团汽车电子与智能芯片板块的核心企业。专注于汽车电子与安全芯片领域&#xff0c;累计出货超过230亿颗&#xff0c;为亚洲、欧洲、美洲、非洲的二十多个国家和地区提供产品和服务。 为进一步提升…

VSC++: 十转十六进制

void 十转十六进制(int 数) {//缘由https://ask.csdn.net/questions/1089023string 十六模 "0123456789ABCDEF", 进制 "";int j 0;cout << 数 << ends; if (!数)cout << "0";while (数)进制.push_back(十六模[数 % 16]), j…

LCS—最长公共子序列

最长公共子序列问题就是求出两个字符串的LCS长度&#xff0c;是一道非常经典的面试题目&#xff0c;因为它的解法是典型的二维动态规划。 比如输入 str1 "babcde", str2 "acbe"&#xff0c;算法应该输出3&#xff0c;因为 str1 和 str2 的最长公共子序列…

【大模型基础】P2 Bag-of-Words

目录 词袋模型 概述词袋模型 实例第1步 构建语料库第2步 对句子进行分词第3步 创建词汇表第4步 转换词袋表示第5步 计算余弦相似度 词袋模型的局限性 词袋模型 概述 词袋模型&#xff0c;Bag-of-Words&#xff0c;是一种简单的文本表示方法&#xff0c;也是 NLP 中的一个经典模…

[数据集][目标检测]血细胞检测数据集VOC+YOLO格式2757张4类别

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;2757 标注数量(xml文件个数)&#xff1a;2757 标注数量(txt文件个数)&#xff1a;2757 标注…

因MathType导致word复制粘贴失败,显示:运行时错误‘53’

问题&#xff1a;运行时错误‘53’&#xff1a;文件未找到&#xff1a;MathPage.WLL 解决方法&#xff1a;打开MathType所在文件夹 右击MathType图标->点击“打开文件所在位置”->找到MathPage.WLL文件。 然后&#xff0c;把这个文件复制到该目录下&#xff1a;C:\Progr…