Linux上文件管理类命令实例讲解

下面介绍三个文件cp, mv, rm管理命令:

  1. cp命令:copy,复制命令
    命令格式: cp 源文件 目标文件
    复制又分为单源复制和多源复制两种情况:

    • 单源复制
      • 如果目标文件不存在,创建此文件,并复制数据流到此文件;
        [root@localhost tmp]# cp yum.log ok
        [root@localhost tmp]# ls -l
        total 4
        drwxr-xr-x. 2 root root 21 Feb 28 02:38 ok
        -rw-------. 1 root root 24 Feb 28 02:29 yum.log
        [root@localhost tmp]# ls -l ok/
        total 4
        -rw-------. 1 root root 24 Feb 28 02:38 yum.log
      • 如果目标文件存在
        • 目标文件是非目录文件,覆盖目标文件;
          [root@localhost tmp]# cat ok/yum.log 
          !!!!!
          [root@localhost tmp]# cp yum.log ok/
          cp: overwrite ‘ok/yum.log’? y
          [root@localhost tmp]# cat ok/yum.log 
          aaaaa
          bbbbb
          ccccc
          ddddd
        • 目标文件是目录文件,先在目录下创建此文件,并复制数据流到此文件;
          [root@localhost tmp]# tree
          .
          ├── ok
          └── yum.log
          [root@localhost tmp]# cp yum.log ok/
          [root@localhost tmp]# tree
          .
          ├── ok
          │   └── yum.log
          └── yum.log
          1 directory, 2 files
    • 多源复制
      • 目标不存在;错误提示;
        [root@localhost tmp]# tree
        .
        ├── ok
        ├── yum1.log
        └── yum.log
        1 directory, 2 files
        [root@localhost tmp]# cp {yum.log,yum1.log} ok1
        cp: target ‘ok1’ is not a directory
      • 目标存在:
        • 目标非目录,错误;
          [root@localhost tmp]# ls -l
          total 12
          -rw-r--r--. 1 root root  7 Feb 28 03:11 aaa
          drwxr-xr-x. 2 root root  6 Feb 28 03:05 ok
          -rw-------. 1 root root 30 Feb 28 03:02 yum1.log
          -rw-------. 1 root root 24 Feb 28 02:29 yum.log
          [root@localhost tmp]# cp {yum.log,yum1.log} aaa
          cp: target ‘aaa’ is not a directory
        • 目标是目录文件,分别复制每个文件到目录中,保持原名
          [root@localhost tmp]# tree
          .
          ├── aaa
          ├── ok
          ├── yum1.log
          └── yum.log
          1 directory, 3 files
          [root@localhost tmp]# cp {yum.log,yum1.log} ok/
          [root@localhost tmp]# tree
          .
          ├── aaa
          ├── ok
          │   ├── yum1.log
          │   └── yum.log
          ├── yum1.log
          └── yum.log
          1 directory, 5 files
  2. mv命令:move,移动命令
    命令格式:mv 源文件 目标文件 (除了复制成功后删除源文件,其他都和复制命令相同)

    • 剪切到ok目录下
      [root@localhost tmp]# tree
      .
      ├── aaa
      ├── ok
      ├── yum1.log
      └── yum.log
      1 directory, 3 files
      [root@localhost tmp]# mv {yum.log,yum1.log} ok/
      [root@localhost tmp]# tree
      .
      ├── aaa
      └── ok
        ├── yum1.log
        └── yum.log
      1 directory, 3 files
    • ok目录改名为yes目录
      [root@localhost tmp]# tree
      .
      ├── aaa
      └── ok
        ├── yum1.log
        └── yum.log
      1 directory, 3 files
      [root@localhost tmp]# mv ok/ yes/
      [root@localhost tmp]# tree
      .
      ├── aaa
      └── yes
        ├── yum1.log
        └── yum.log
      1 directory, 3 files
  3. rm命令:remove,删除命令
    [root@localhost tmp]# tree
    .
    ├── aaa
    └── yes
      ├── yum1.log
      └── yum.log
    1 directory, 3 files
    [root@localhost tmp]# rm -rf yes/
    [root@localhost tmp]# tree
    .
    └── aaa
    0 directories, 1 file

    危险操作:rm -rf /*
    注意:不用的文件单独放到独立目录,不要轻易删除,否则找不回来;

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/91778

(0)
华龙华龙
上一篇 2018-02-28
下一篇 2018-02-28

相关推荐

  • 使用httpd反向代理模块实现tomcat负载均衡集群(下)

    上一篇讲解了http使用mod_http和mod_ajp代理模块实现tomcat负载均衡,下面我们来讲解使用http的mod_jk实现taomcat的负载均衡集群: 注意:http的mod_jk是第三方扩展模块,在新http版本中以不支持,在httpd 1.3和2.0效果较好 6、使用mod_jk实现tomcat负载均衡集群 6.1安装mod_jk [roo…

    Linux干货 2015-07-21
  • 关于加密那点事

    作者【Jev Tse】 环境:sentos6.8     【本文预览】      一、关于加密      二、对称加密      三、非对称加密      四、单向散列 …

    Linux干货 2016-12-01
  • iptables详解

    iptables命令: iptables [-t table] {-A|-C|-D} chain rule-specification iptables [-t table] -I chain [rulenum] rule-specification iptables [-t table] -R chain rulenum rule-specificatio…

    Linux干货 2017-11-12
  • 十二.Linux博客-2016年8月16日文件查找和压缩、rpm包管理、while循环、until循环

    格式说明: 操作 概念 命令 说明及举例 十二.文件查找和压缩、rpm包管理、yum、while循环、until循环 tar tar -zcvf /testdir/etc.tar.gz /etc/ 备份etc创建etc.tar.gz文件 压缩为gz格式 显示过程 tar -jcvf&nbs…

    Linux干货 2016-08-24
  • N25期—第一周作业

    计算机的组成及其功能 计算机主要由硬件和软件两部分组成, 硬件目前由5大部件组成 控制器:类似人类的大脑!控制整个计算机的运作 运算器:对数据进行逻辑运算处理 存储器:存放数据部件 输出设备:比如显示器,打印机 输入设备:比如键盘,鼠标 Linux发行版本 主要三大分之:Debian系,Reb Hat系,Slackware系。 1.Debian GNU / …

    Linux干货 2016-12-01
  • 采用二进制包安装mysql

    本文是在CentOS7系统平台下安装Mysql5.6.26版本数据库的操作说明,如有错误,请指正。 系统平台:CentOS-7-x86_64    数据库版本:mysql-5.6.26   Mysql镜像文件下载地址:http://dev.mysql.com/downloads/mirrors.html 本次演示的Mysql安装…

    Linux干货 2017-05-04

评论列表(1条)

  • 马哥教育
    马哥教育 2018-03-20 21:49

    尽量把一周作业写在一个博客上。