Linux中cp和scp命令的使用方法

Linux中cp和scp命令的使用方法
cp命令: 用途:同一台电脑上复制文件。
基本格式: cp [OPTIONS] SOURCE DEST cp [OPTIONS] SOURCE... DIRECTORY
常用选项: -a:递归复制,保持属性。
-r:递归复制目录。
-f:强制覆盖目标文件。

范例: cp aaa bbb cp .c /Finished/
scp命令: 用途:不同Linux系统间安全复制,基于ssh。
基本格式: scp [OPTIONS] file_source file_target
常用选项: -v:显示进度。
-C:启用压缩。
-P:指定端口。
-r:递归复制目录。

从本地到远程: 复制文件:scp local_file username@remote_ip:remote_folder 复制目录:scp -r local_folder username@remote_ip:remote_folder
从远程到本地: 调换后两个参数顺序。

范例: scp /home/daisy/full.tar.gz root@1 7 2 .1 9 .2 .7 5 :/home/root scp -r /home/space/music/ root@www.cumt.edu.cn:/home/root/others/
注意事项: 确保用户有读权限。
防火墙限制可能需指定端口。

linux下cp命令的用法是什么

这就是坑:默认cp会覆盖同名文件,不提示。

别信:cp -r复制目录时,若目标已存在,会清空后复制。

别这么干:cp不用于跨文件系统复制,可能会损坏文件。

Linux命令CP的妙用

结论:Linux cp命令实用技巧
1 . 只复制更新的文件:cp -u -v file1 file2 2 . 复制并重命名文件:cp file1 file2 3 . 交互式复制:cp -i file1 file2 4 . 强制复制:cp -f file1 file2 5 . 复制目录:cp -R dir1 dir2 6 . 复制多个文件和目录:cp -R file1 file2 file3 dir1 dir2 dir3 7 . 保留文件属性:cp -p a.txt tmp/ 8 . 保留目录结构(处理符号链接):cp -P /var/tmp/a.txt ./temp/ 9 . 复制时创建备份:cp -b a.txt tmp/ 或 cp -b -V ta.txt /tmp 或 cp -b -S _bak a.txt /tmp
这些技巧能帮助你更高效地在Linux系统中管理文件和目录。