linuxcp命令的15个示例

不及物动词 其他 11

回复

共3条回复 我来回复
  • 不及物动词的头像
    不及物动词
    这个人很懒,什么都没有留下~
    评论

    1. 将文件file1复制到目录dir中:cp file1 dir

    2. 将目录dir1复制到目录dir2中:cp -R dir1 dir2

    3. 将文件file1和file2复制到目录dir中:cp file1 file2 dir

    4. 将目录dir1中的所有文件和子目录复制到目录dir2中:cp -R dir1/* dir2

    5. 将文件file1重命名为file2:cp file1 file2

    6. 强制复制文件 file1 到目标文件 file2:cp -f file1 file2

    7. 如果目标文件 file2 已经存在,提示用户是否覆盖:cp -i file1 file2

    8. 递归复制目录dir1及其子目录和文件到目录dir2中,且保持源文件夹结构:cp -R –preserve=links dir1 dir2

    9. 递归复制目录dir1及其子目录和文件到目录dir2中,且忽略指定的文件和目录:cp -R –exclude=file1 –exclude=dir1 dir1 dir2

    10. 复制文件时,保持源文件的属性(如权限、所有者等)不变:cp -p file1 file2

    11. 拷贝文件时,显示详细的进度信息:cp -v file1 file2

    12. 递归拷贝目录,但不拷贝文件和子目录:cp -R –no-preserve=links dir1 dir2

    13. 将多个文件复制到目标目录,且保持源文件名不变:cp file1 file2 file3 dir

    14. 复制目录时,不拷贝子目录:cp -R –no-preserve=links –no-preserve=mode dir1 dir2

    15. 将指定的多个文件复制到目标文件夹:cp file1 file2 file3 … dir

    2年前 0条评论
  • fiy的头像
    fiy
    Worktile&PingCode市场小伙伴
    评论

    1. 将文件从一个目录复制到另一个目录:
    cp /path/to/source/file /path/to/destination

    2. 复制整个目录:
    cp -r /path/to/source/directory /path/to/destination

    3. 复制多个文件到目标目录:
    cp file1 file2 file3 /path/to/destination

    4. 复制文件并更改文件名:
    cp /path/to/source/file /path/to/destination/new_filename

    5. 复制整个目录并更改目录名:
    cp -r /path/to/source/directory /path/to/destination/new_directory_name

    6. 使用通配符复制匹配的文件:
    cp /path/to/source/*.txt /path/to/destination

    7. 递归复制并保持链接:
    cp -R /path/to/source/directory /path/to/destination

    8. 仅复制新文件或有差异的文件:
    cp -u /path/to/source/file /path/to/destination

    9. 静默模式,不显示复制进度:
    cp -q /path/to/source/file /path/to/destination

    10. 强制复制,如果目标文件已存在则覆盖:
    cp -f /path/to/source/file /path/to/destination

    11. 使用交互模式,询问是否覆盖目标文件:
    cp -i /path/to/source/file /path/to/destination

    12. 显示复制进度:
    cp -v /path/to/source/file /path/to/destination

    13. 复制目录而不复制其中的文件:
    cp -r /path/to/source/directory/. /path/to/destination

    14. 递归复制并保留源文件的权限、时间戳等属性:
    cp -a /path/to/source/directory /path/to/destination

    15. 复制符号链接而不是链接指向的文件:
    cp -P /path/to/source/symlink /path/to/destination

    2年前 0条评论
  • worktile的头像
    worktile
    Worktile官方账号
    评论

    一、将文件复制到指定目录下

    1. 将文件 `file1.txt` 复制到目录 `/home/user1/` 下:`cp file1.txt /home/user1/`

    2. 将文件 `file1.txt` 复制到目录 `/home/user1/` 下并重命名为 `file2.txt`:`cp file1.txt /home/user1/file2.txt`

    3. 将文件 `file1.txt` 复制到当前目录下的子目录 `subdir/` 下:`cp file1.txt subdir/`

    二、复制目录

    4. 复制目录 `dir1/` 到目录 `/home/user1/` 下:`cp -r dir1/ /home/user1/`

    5. 复制目录 `dir1/` 到当前目录下的子目录 `subdir/` 下:`cp -r dir1/ subdir/`

    三、复制多个文件

    6. 将文件 `file1.txt`、`file2.txt` 和 `file3.txt` 复制到目录 `/home/user1/` 下:`cp file1.txt file2.txt file3.txt /home/user1/`

    7. 将当前目录下以 `file` 开头的所有文件复制到目录 `/home/user1/` 下:`cp file* /home/user1/`

    四、复制目录并保持链接

    8. 复制目录 `dir1/` 到目录 `/home/user1/` 下,并保持链接关系:`cp -lr dir1/ /home/user1/`

    五、复制时显示进度条

    9. 复制文件 `file1.txt` 到目录 `/home/user1/` 下,并显示进度条:`cp -v file1.txt /home/user1/`

    10. 复制目录 `dir1/` 到目录 `/home/user1/` 下,并显示进度条:`cp -vr dir1/ /home/user1/`

    六、复制文件并询问是否覆盖已有文件

    11. 复制文件 `file1.txt` 到目录 `/home/user1/` 下,并在复制前询问是否覆盖已有文件:`cp -i file1.txt /home/user1/`

    七、复制文件并保持源文件权限

    12. 复制文件 `file1.txt` 到目录 `/home/user1/` 下,同时保持源文件的所有权限:`cp –preserve=file1.txt /home/user1/`

    八、复制目录,并递归复制符号链接

    13. 复制目录 `dir1/` 到目录 `/home/user1/` 下,并递归复制符号链接:`cp -dR dir1/ /home/user1/`

    九、复制目录并忽略指定文件或目录

    14. 复制目录 `dir1/` 到目录 `/home/user1/` 下,但忽略以 `temp` 开头的文件或目录:`cp -r –exclude=”temp*” dir1/ /home/user1/`

    十、将复制的文件视为软链接

    15. 将文件 `file1.txt` 复制到目录 `/home/user1/` 下,并将复制的文件视为软链接:`cp -s file1.txt /home/user1/`

    2年前 0条评论
注册PingCode 在线客服
站长微信
站长微信
电话联系

400-800-1024

工作日9:30-21:00在线

分享本页
返回顶部