文件操作CLI Manual
$cp
Copy files and directories to a destination path.
命令语法POSIX Standard
cp [OPTIONS] SOURCE... DEST在交互式终端沙盒中实时运行
无需安装的客户端实时仿真环境。
bash — terminal
AST Sandbox (Free)
概述与工作原理
`cp` (Copy) duplicates files or folders from a source to a destination. It supports copying single files, multiple files into target directories, and recursive directory tree replication with preservation of file modes and timestamps.
常用参数与选项说明
| Flag / Option | Description |
|---|---|
| -r, -R | Copy directories and their contents recursively. |
| -p | Preserve specified attributes like mode, ownership, and timestamps. |
| -a | Archive mode (same as -dR --preserve=all) for exact backups. |
| -u | Copy only when the SOURCE file is newer than the destination file. |
| -v | Verbose output showing files as they are copied. |
实际生产案例与代码范例
#1Create a backup copy of a configuration file
cp welcome.txt welcome.txt.bak && ls -lDuplicates welcome.txt into welcome.txt.bak in the same directory.
相关 Linux 常用命令
$find文件操作
根据文件名、类型、大小或修改时间在目录层级中高效搜索文件与目录。
$cat文件操作
连接文件并在终端标准输出上打印文件内容。
$mkdir文件操作
Create new directories and folder hierarchies.
$rm文件操作
Remove files or directories from the filesystem.
$mv文件操作
Move or rename files and directories.
$touch文件操作
Create empty files or update file access and modification timestamps.