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 *  --使用统配符*,代表所有文件
  • 相关阅读:
    【总有一些东西老是忘】之——常见HTML的块级标签、内联标签
    【JS跨域取XML】之——借助AS的URLLoader
    【前端重构技能天赋】(二)——Javascript、CSS篇
    【IE大叔的嘴歪眼斜】之—— 由hasLayout引发的临床CSS Bug表
    【F12一下,看看页面里的第一行】——说说浏览器兼容性模式
    【IE大叔的杀马特审美】之——CSS盒子模型
    【前端重构技能天赋】(一)——内容篇
    【总有一些东西要弄清】——说说面试时一系列的CSS问题
    【拆了CSS照样是页面】之——HTML语义化(含H5)
    【javascript继承】之——原型链继承和类式继承
  • 原文地址:https://www.cnblogs.com/lbg-database/p/10109985.html
Copyright © 2011-2022 走看看