zoukankan      html  css  js  c++  java
  • linux文件增删拷(touch/mkdir/cp/mv/rm)

    touch或>命令创建普通文件:

    [root@localhost test]# touch a  ---创建单个文件
    [root@localhost test]# ls
    a
    [root@localhost test]# > b   ---创建单个文件
    [root@localhost test]# ls
    a  b
     
    mkdir创建目录文件:
    [root@localhost test]# mkdir c  --创建文件夹
    [root@localhost test]# ll
    total 0
    -rw-r--r-- 1 root root 0 Oct  1 19:54 a
    -rw-r--r-- 1 root root 0 Oct  1 19:54 b
    drwxr-xr-x 2 root root 6 Oct  1 19:55 c
     
    一次创建多个普通文件:
    [root@localhost test]# touch d e  ---创建多个文件
    [root@localhost test]# ls
    a  b  c  d  e
     
    选项-p递归创建多个目录文件:
    [root@localhost test]# mkdir -p aa/bb  ---使用-p递归创建目录
    [root@localhost test]# ll
    total 0
    -rw-r--r-- 1 root root  0 Oct  1 19:54 a
    drwxr-xr-x 3 root root 16 Oct  1 19:57 aa
    -rw-r--r-- 1 root root  0 Oct  1 19:54 b
    drwxr-xr-x 2 root root  6 Oct  1 19:55 c
    -rw-r--r-- 1 root root  0 Oct  1 19:55 d
    -rw-r--r-- 1 root root  0 Oct  1 19:55 e
    [root@localhost test]# cd aa
    [root@localhost aa]# ls
    bb
     
    选项-R递归显示文件:
    [root@localhost test]# ls -R  ----使用选项-R递归显示文件。
    .:
    a  aa  b  c  d  e
    ./aa:
    bb
    ./aa/bb:
    ./c:
    [root@localhost test]# mkdir -pv cc/dd  --v指verbose。详细显示递归创建。
    mkdir: created directory ?.c?
    mkdir: created directory ?.c/dd?
     
    cp拷贝单个普通文件:
    [root@localhost test]# ll
    total 0
    -rw-r--r-- 1 root root  0 Oct  1 19:54 a
    drwxr-xr-x 3 root root 16 Oct  1 19:57 aa
    -rw-r--r-- 1 root root  0 Oct  1 19:54 b
    drwxr-xr-x 2 root root  6 Oct  1 19:55 c
    drwxr-xr-x 3 root root 16 Oct  1 20:00 cc
    -rw-r--r-- 1 root root  0 Oct  1 19:55 d
    -rw-r--r-- 1 root root  0 Oct  1 19:55 e
    [root@localhost test]# cp a f
    [root@localhost test]# ll
    total 0
    -rw-r--r-- 1 root root  0 Oct  1 19:54 a
    drwxr-xr-x 3 root root 16 Oct  1 19:57 aa
    -rw-r--r-- 1 root root  0 Oct  1 19:54 b
    drwxr-xr-x 2 root root  6 Oct  1 19:55 c
    drwxr-xr-x 3 root root 16 Oct  1 20:00 cc
    -rw-r--r-- 1 root root  0 Oct  1 19:55 d
    -rw-r--r-- 1 root root  0 Oct  1 19:55 e
    -rw-r--r-- 1 root root  0 Oct  1 20:02 f
     
    cp拷贝多个普通文件:
    [root@localhost test]# cp a b aa
    [root@localhost test]# cd aa
    [root@localhost aa]# ll
    total 0
    -rw-r--r-- 1 root root 0 Oct  1 20:04 a
    -rw-r--r-- 1 root root 0 Oct  1 20:04 b
    drwxr-xr-x 2 root root 6 Oct  1 19:57 bb
     
    cp加选项-r拷贝目录文件:
    [root@localhost test]# ll
    total 0
    -rw-r--r-- 1 root root  0 Oct  1 19:54 a
    drwxr-xr-x 3 root root 34 Oct  1 20:04 aa
    -rw-r--r-- 1 root root  0 Oct  1 19:54 b
    drwxr-xr-x 2 root root  6 Oct  1 19:55 c
    drwxr-xr-x 4 root root 26 Oct  1 20:07 cc
    -rw-r--r-- 1 root root  0 Oct  1 19:55 d
    -rw-r--r-- 1 root root  0 Oct  1 19:55 e
    -rw-r--r-- 1 root root  0 Oct  1 20:02 f
    [root@localhost test]# cp -r aa cc
    [root@localhost test]# cd cc
    [root@localhost cc]# ll
    total 0
    drwxr-xr-x 3 root root 34 Oct  1 20:07 aa
    drwxr-xr-x 2 root root  6 Oct  1 20:00 dd
     
    cp拷贝普通文件并重命名:
    [root@localhost test]# cp a ./bb/1
    [root@localhost test]# ls ./bb
    1
     
    mv剪切文件:
    剪切文件没有-r之分,无论是普通文件还是目录都不用加-r.,不用区分普通文件还是目录文件,可以一次剪切多个文件.也有重命名的作用.
    [root@localhost test]# ls
    a  aa  b  bb  c  cc  d  e  f
    [root@localhost test]# mv b g
    [root@localhost test]# ls
    a  aa  bb  c  cc  d  e  f  g
     
    rm删除文件:
    [root@localhost test]# ls
    a  aa  bb  c  cc  d  e  f  g
    [root@localhost test]# rm -fr a
    [root@localhost test]# ls
    aa  bb  c  cc  d  e  f  g
    [root@localhost test]# rm -fr ? ---使用统配符?代表单个字符的文件
    [root@localhost test]# ls
    aa  bb  cc
    [root@localhost test]# rm -fr *  --使用统配符*,代表所有文件
  • 相关阅读:
    tp5 url 线上访问 在nginx 上 出现404错误,解决办法(1.80nginx 配置 pathInfo)
    Windows下配置nginx+php(wnmp)
    windows向github提交代码
    改变图片尺寸
    mysql字符编码的设置以及mysql中文乱码的解决方法
    wamp升级php7
    C++Primer第五版——习题答案和解析
    Ubuntu16.04下安装显卡驱动记录
    Ubuntu环境下No module named '_tkinter'错误的解决
    TensorFlow:NameError: name ‘input_data’ is not defined
  • 原文地址:https://www.cnblogs.com/lbg-database/p/10109985.html
Copyright © 2011-2022 走看看