zoukankan      html  css  js  c++  java
  • linux cp 拷贝文件或目录

    cp 拷贝文件或目录

    默认不能拷贝目录

    常用来备份;
    [root@MongoDB ~]# cp a.txt  /tmp/
    [root@MongoDB ~]# cp /root/a.txt  /tmp/
    cp: overwrite ‘/tmp/a.txt’? y

    提示是否覆盖,首先考虑到有别名     -i  在覆盖前提示 

    cp命令默认是不会提示overwrtite的,但是cp的-i选项会提示,而一般linux的用户环境文件~/.bashrc中会把cp命名成alias 

    cp='cp -i'  如:

    [root@MongoDB ~]# alias |grep cp
    alias cp='cp -i'

    这样在linux下输入cp命令实际上运行的是cp -i,加上一个"" 符号或者写cp全路径/bin/cp就是让此次的cp命令不使用别名(cp -i)运行

    拷贝覆盖不提示,默认是提示的

    第一种方法:cp

    cp /mnt/test.txt /tmp

    第二种方法:cp加 命令全路径

    /bin/cp /mnt/test.txt /tmp

     屏蔽掉系统默认的对应的命令别名,默认执行cp的操作调用了别名,所以会提示覆盖

    复制的文件时间改变了

    [root@MongoDB ~]# cp file1.txt file4.txt
    [root@MongoDB ~]# ll
    total 4
    -rw-------. 1 root root 1851 Mar 27 08:38 anaconda-ks.cfg
    -rw-r--r--  1 root root    0 May 18 07:41 file1.txt
    -rw-r--r--  1 root root    0 May 18 07:41 file2.txt
    -rw-r--r--  1 root root    0 May 18 07:41 file3.txt
    -rw-r--r--  1 root root    0 May 18 07:42 file4.txt

    -a 保持属性不变

    [root@MongoDB ~]# cp -a file1.txt file4.txt 
    [root@MongoDB ~]# ll
    total 4
    -rw-------. 1 root root 1851 Mar 27 08:38 anaconda-ks.cfg
    -rw-r--r--  1 root root    0 May 18 07:41 file1.txt
    -rw-r--r--  1 root root    0 May 18 07:41 file2.txt
    -rw-r--r--  1 root root    0 May 18 07:41 file3.txt
    -rw-r--r--  1 root root    0 May 18 07:41 file4.txt

    -r 拷贝目录

    也可以使用-a 拷贝目录  -a   等效于   -pdr   参数

    -p 连同属性一同复制过去,权限等

    [root@MongoDB ~]# cp -a dir{3,4}
    [root@MongoDB ~]# ll
    total 4
    -rw-------. 1 root root 1851 Mar 27 08:38 anaconda-ks.cfg
    drwxr-xr-x  2 root root    6 May 18 07:54 dir1
    drwxr-xr-x  2 root root    6 May 18 07:54 dir2
    drwxr-xr-x  2 root root    6 May 18 07:54 dir3
    drwxr-xr-x  2 root root    6 May 18 07:54 dir4
  • 相关阅读:
    leetcode122
    leetcode121
    leetcode773
    leetcode803
    leetcode658
    leetcode723
    leetcode134
    leetcode340
    leetcode721
    leetcode362
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/10771919.html
Copyright © 2011-2022 走看看