linux文件管理類命令匯總及演示

mkdir,rmdir,tree,touch,cp,mv,rm)

mkdir
  • image.png
  • 命令演示
    [root@localhost mytest]# mkdir -p xiangjis
    [root@localhost mytest]# ll
    總用量 0
    drwxr-xr-x. 2 root root 6 7月 19 14:33 xiangjis
    [root@localhost mytest]# mkdir -p xiangjis/al/dy
    [root@localhost mytest]# tree xiangjis
    xiangjis
    └── al
     └── dy
    2 directories, 0 files
    [root@localhost mytest]# mkdir -v xiangjis2
    mkdir: 已創(chuàng)建目錄 "xiangjis2"
    [root@localhost mytest]# ll
    總用量 0
    drwxr-xr-x. 3 root root 19 7月 19 14:36 xiangjis
    drwxr-xr-x. 2 root root 6 7月 19 14:36 xiangjis2
    [root@localhost mytest]# mkdir -m g+w xiangjis3
    [root@localhost mytest]# mkdir -m o+w xiangjis4
    [root@localhost mytest]# \ls -l
    總用量 0
    drwxr-xr-x. 3 root root 19 7月 19 14:36 xiangjis
    drwxr-xr-x. 2 root root 6 7月 19 14:42 xiangjis2
    drwxrwxrwx. 2 root root 6 7月 19 14:46 xiangjis3
    drwxrwxrwx. 2 root root 6 7月 19 14:46 xiangjis4
    [root@localhost mytest]# tree
    .
    ├── xiangjis
    │ └── al
    │  └── dy
    ├── xiangjis2
    ├── xiangjis3
    └── xiangjis4
    6 directories, 0 files

rmdir
  • image.png
  • 命令演示
    [root@localhost mytest]# tree
    .
    ├── xiangjis
    │ └── al
    │  └── dy
    ├── xiangjis2
    ├── xiangjis3
    └── xiangjis4
    6 directories, 0 files
    [root@localhost mytest]# rmdir xiangjis
    rmdir: 刪除 "xiangjis" 失敗: 目錄非空
    [root@localhost mytest]# rmdir xiangjis2
    [root@localhost mytest]# rmdir -v xiangjis3
    rmdir: 正在刪除目錄 "xiangjis3"
    [root@localhost mytest]# rmdir -v xiangjis4
    rmdir: 正在刪除目錄 "xiangjis4"
    [root@localhost mytest]# ll
    總用量 0
    drwxr-xr-x. 3 root root 19 7月 19 14:36 xiangjis
    [root@localhost mytest]# tree
    .
    └── xiangjis
    └── al
     └── dy
    3 directories, 0 files
    [root@localhost mytest]# rmdir -vp xiangjis/al/dy
    rmdir: 正在刪除目錄 "xiangjis/al/dy"
    rmdir: 正在刪除目錄 "xiangjis/al"
    rmdir: 正在刪除目錄 "xiangjis"
    [root@localhost mytest]# ll
    總用量 0

tree
  • image.png
  • 命令演示
    [root@localhost mytest]# ll
    總用量 4
    -rw-r--r--. 1 root root 45 7月 19 15:15 du
    drwxr-xr-x. 3 root root 19 7月 19 15:14 xiangjis
    drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis1
    drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis2
    [root@localhost mytest]# tree
    .
    ├── du
    ├── xiangjis
    │ └── al
    │  └── dy
    ├── xiangjis1
    └── xiangjis2
    5 directories, 1 file
    [root@localhost mytest]# tree -a
    .
    ├── du
    ├── .grub2.cfg.swp
    ├── .passwd.swo
    ├── .passwd.swp
    ├── xiangjis
    │ └── al
    │  └── dy
    ├── xiangjis1
    └── xiangjis2
    5 directories, 4 files
    [root@localhost mytest]# tree -L 1
    .
    ├── du
    ├── xiangjis
    ├── xiangjis1
    └── xiangjis2
    3 directories, 1 file
    [root@localhost mytest]# tree -L 2
    .
    ├── du
    ├── xiangjis
    │ └── al
    ├── xiangjis1
    └── xiangjis2
    4 directories, 1 file
    [root@localhost mytest]# tree -L 3
    .
    ├── du
    ├── xiangjis
    │ └── al
    │  └── dy
    ├── xiangjis1
    └── xiangjis2
    5 directories, 1 file
    [root@localhost mytest]# tree -d
    .
    ├── xiangjis
    │ └── al
    │  └── dy
    ├── xiangjis1
    └── xiangjis2
    5 directories

stat
  • image.png
  • 命令演示
    此命令在單獨(dú)演示,會(huì)穿插到其他的文件管理類命令中,展示命令使用

touch
  • image.png
  • 命令演示
    [root@localhost mytest]# touch du
    [root@localhost mytest]# ll
    總用量 0
    -rw-r--r--. 1 root root 0 7月 21 10:45 du
    drwxr-xr-x. 3 root root 19 7月 19 15:14 xiangjis
    drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis1
    drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis2
    [root@localhost mytest]# stat du
    文件:"du"
    大忻颊怼:0 塊:0 IO 塊:4096 普通空文件
    設(shè)備:fd00h/64768d Inode:865184 硬鏈接:1
    權(quán)限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環(huán)境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問(wèn):2017-07-21 10:45:39.622956106 +0800
    最近更改:2017-07-21 10:45:39.622956106 +0800
    最近改動(dòng):2017-07-21 10:45:39.622956106 +0800
    創(chuàng)建時(shí)間:-
    [root@localhost mytest]# date
    2017年 07月 21日 星期五 10:45:40 CST
    [root@localhost mytest]# touch -c du2
    [root@localhost mytest]# ll
    總用量 0
    -rw-r--r--. 1 root root 0 7月 21 10:45 du
    drwxr-xr-x. 3 root root 19 7月 19 15:14 xiangjis
    drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis1
    drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis2
    [root@localhost mytest]# stat du
    文件:"du"
    大型胩省:0 塊:0 IO 塊:4096 普通空文件
    設(shè)備:fd00h/64768d Inode:865184 硬鏈接:1
    權(quán)限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環(huán)境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問(wèn):2017-07-21 10:46:28.756680491 +0800
    最近更改:2017-07-21 10:46:28.756680491 +0800
    最近改動(dòng):2017-07-21 10:46:28.756680491 +0800
    創(chuàng)建時(shí)間:-
    [root@localhost mytest]# touch -a du
    [root@localhost mytest]# stat du
    文件:"du"
    大小:0 塊:0 IO 塊:4096 普通空文件
    設(shè)備:fd00h/64768d Inode:865184 硬鏈接:1
    權(quán)限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環(huán)境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問(wèn):2017-07-21 10:47:32.738321575 +0800
    最近更改:2017-07-21 10:46:28.756680491 +0800
    最近改動(dòng):2017-07-21 10:47:32.738321575 +0800
    創(chuàng)建時(shí)間:-
    [root@localhost mytest]# date
    2017年 07月 21日 星期五 10:49:04 CST
    [root@localhost mytest]# touch -m du
    [root@localhost mytest]# stat du
    文件:"du"
    大星缮簟:0 塊:0 IO 塊:4096 普通空文件
    設(shè)備:fd00h/64768d Inode:865184 硬鏈接:1
    權(quán)限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環(huán)境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問(wèn):2017-07-21 10:48:03.170150868 +0800
    最近更改:2017-07-21 10:49:10.459773392 +0800
    最近改動(dòng):2017-07-21 10:49:10.459773392 +0800
    創(chuàng)建時(shí)間:-
    [root@localhost mytest]# touch -t 201606201020.20 du
    [root@localhost mytest]# stat du
    文件:"du"
    大斜!:0 塊:0 IO 塊:4096 普通空文件
    設(shè)備:fd00h/64768d Inode:865184 硬鏈接:1
    權(quán)限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環(huán)境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問(wèn):2016-06-20 10:20:20.000000000 +0800
    最近更改:2016-06-20 10:20:20.000000000 +0800
    最近改動(dòng):2017-07-21 10:50:47.179230825 +0800
    創(chuàng)建時(shí)間:-
    [root@localhost mytest]# touch -at 201606201020.20 du
    [root@localhost mytest]# stat du
    文件:"du"
    大欣教馈:0 塊:0 IO 塊:4096 普通空文件
    設(shè)備:fd00h/64768d Inode:865184 硬鏈接:1
    權(quán)限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環(huán)境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問(wèn):2016-06-20 10:20:20.000000000 +0800
    最近更改:2017-07-21 10:51:18.172056968 +0800
    最近改動(dòng):2017-07-21 10:51:47.230893961 +0800
    創(chuàng)建時(shí)間:-
    [root@localhost mytest]# touch -mt 201606211020.20 du
    [root@localhost mytest]#
    [root@localhost mytest]# stat du
    文件:"du"
    大小:0 塊:0 IO 塊:4096 普通空文件
    設(shè)備:fd00h/64768d Inode:865184 硬鏈接:1
    權(quán)限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環(huán)境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問(wèn):2016-06-20 10:20:20.000000000 +0800
    最近更改:2016-06-21 10:20:20.000000000 +0800
    最近改動(dòng):2017-07-21 10:52:20.761705862 +0800
    創(chuàng)建時(shí)間:-

cp
  • image.png
  • 命令演示
    [root@localhost mytest]# ll
    總用量 0
    -rw-r--r--. 1 root root 0 7月 21 11:06 du
    drwxr-xr-x. 3 root root 19 7月 19 15:14 xiangjis
    drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis1
    drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis2
    [root@localhost mytest]#
    [root@localhost mytest]#
    [root@localhost mytest]#
    [root@localhost mytest]# head -2 du
    [root@localhost mytest]# cp /etc/passwd du
    cp:是否覆蓋"du"敢艰? yes
    [root@localhost mytest]# head -2 du
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/sbin/nologin
    [root@localhost mytest]# cp /etc/issue du1
    [root@localhost mytest]# ls
    du du1 xiangjis xiangjis1 xiangjis2
    [root@localhost mytest]# head -2 du1
    \S
    Kernel \r on an \m
    [root@localhost mytest]# ls xiangjis
    alwin
    [root@localhost mytest]# cp /etc/issue xiangjis
    [root@localhost mytest]# ls xiangjis
    alwin issue
    [root@localhost mytest]# head xiangjis/issue
    \S
    Kernel \r on an \m
    [root@localhost mytest]# ls
    du du1 xiangjis xiangjis1 xiangjis2
    [root@localhost mytest]# ls xiangjis1
    [root@localhost mytest]# cp /etc/{passwd,issue} xiangjis4
    cp: 目標(biāo)"xiangjis4" 不是目錄
    [root@localhost mytest]# cp /etc/{passwd,issue} du
    cp: 目標(biāo)"du" 不是目錄
    [root@localhost mytest]# cp /etc/{passwd,issue} xiangjis2
    [root@localhost mytest]# ls xiangjis2
    issue passwd
    [root@localhost mytest]# basename xiangjis2
    xiangjis2
    [root@localhost mytest]# dirname xiangjis2
    .
    [root@localhost mytest]# basename du
    du
    [root@localhost mytest]# dirname du
    .
    [root@localhost mytest]# ls xiangjis1
    du du1
    [root@localhost mytest]# cp xiangjis1 xiangjis2
    cp: 略過(guò)目錄"xiangjis1"
    [root@localhost mytest]# cp -r xiangjis1 xiangjis2
    [root@localhost mytest]# ls xiangjis2
    issue passwd xiangjis1
    [root@localhost mytest]# tree xiangjis2
    xiangjis2
    ├── issue
    ├── passwd
    └── xiangjis1
     ├── du
     └── du1
     
    1 directory, 4 files
    [root@localhost mytest]# tree -d xiangjis2
    xiangjis2
    └── xiangjis1
     
    1 directory
    [root@localhost mytest]# ls
    du du1 xiangjis xiangjis1 xiangjis2
    [root@localhost mytest]# cp -r xiangjis1 xiangjis3
    [root@localhost mytest]# ls
    du du1 xiangjis xiangjis1 xiangjis2 xiangjis3
    [root@localhost mytest]# ls xiangjis3
    du du1
    [root@localhost mytest]# tree xiangjis3
    xiangjis3
    ├── du
    └── du1
     
    0 directories, 2 files
    [root@localhost mytest]# tree -d xiangjis3
    xiangjis3
     
    0 directories
    [root@localhost mytest]# ll /etc/grub2.cfg
    lrwxrwxrwx. 1 root root 22 5月 30 06:34 /etc/grub2.cfg -> ../boot/grub2/grub.cfg
    [root@localhost mytest]# cp /etc/grub2.cfg gru
    [root@localhost mytest]# head -2 /etc/grub2.cfg

# DO NOT EDIT THIS FILE
[root@localhost mytest]# head -2 gru

# DO NOT EDIT THIS FILE
[root@localhost mytest]# ll
總用量 16
-rw-r--r--. 1 root root 2228 7月 21 11:06 du
-rw-r--r--. 1 root root 23 7月 21 11:07 du1
-rw-r--r--. 1 root root 4243 7月 21 11:45 gru
drwxr-xr-x. 3 root root 32 7月 21 11:08 xiangjis
drwxr-xr-x. 2 root root 27 7月 21 11:13 xiangjis1
drwxr-xr-x. 3 root root 50 7月 21 11:14 xiangjis2
drwxr-xr-x. 2 root root 27 7月 21 11:16 xiangjis3
[root@localhost mytest]# cp -d /etc/grub2.cfg gru
cp:是否覆蓋"gru"诬乞? yes
[root@localhost mytest]# ll
總用量 8
-rw-r--r--. 1 root root 2228 7月 21 11:06 du
-rw-r--r--. 1 root root 23 7月 21 11:07 du1
lrwxrwxrwx. 1 root root 22 7月 21 11:46 gru -> ../boot/grub2/grub.cfg
drwxr-xr-x. 3 root root 32 7月 21 11:08 xiangjis
drwxr-xr-x. 2 root root 27 7月 21 11:13 xiangjis1
drwxr-xr-x. 3 root root 50 7月 21 11:14 xiangjis2
drwxr-xr-x. 2 root root 27 7月 21 11:16 xiangjis3
[root@localhost mytest]# cat gru
cat: gru: 沒(méi)有那個(gè)文件或目錄

mv
  • image.png
  • 命令演示
    和cp命令用法大致相同,mv在移動(dòng)目錄時(shí)不用加-v參數(shù)钠导。

rm
  • image.png
  • 命令演示
    [root@localhost mytest]# mkdir xiangjis
    [root@localhost mytest]# mkdir -p xiangjis1/al/d
    [root@localhost mytest]# ll
    總用量 0
    drwxr-xr-x. 2 root root 6 7月 21 12:06 xiangjis
    drwxr-xr-x. 3 root root 16 7月 21 12:06 xiangjis1
    [root@localhost mytest]# rm xiangjis
    rm: 無(wú)法刪除"xiangjis": 是一個(gè)目錄
    [root@localhost mytest]# rm du
    rm:是否刪除普通空文件 "du"震嫉?yes
    [root@localhost mytest]# rmdir xiangjis
    [root@localhost mytest]# ls
    xiangjis1
    [root@localhost mytest]# tree xiangjis1
    xiangjis1
    └── al
     └── d
     
    2 directories, 0 files
    [root@localhost mytest]# rmdir xiangjis1
    rmdir: 刪除 "xiangjis1" 失敗: 目錄非空
    [root@localhost mytest]# rm -r xiangjis1
    rm:是否進(jìn)入目錄"xiangjis1"? yes
    rm:是否進(jìn)入目錄"xiangjis1/al"? yes
    rm:是否刪除目錄 "xiangjis1/al/d"?yes
    rm:是否刪除目錄 "xiangjis1/al"牡属?yes
    rm:是否刪除目錄 "xiangjis1"票堵?yes
    [root@localhost mytest]# mkdir -p xiangjis2/al/d
    [root@localhost mytest]# tree
    .
    └── xiangjis2
     └── al
      └── d
     
    3 directories, 0 files
    [root@localhost mytest]# rm -rf xiangjis2
    [root@localhost mytest]# ll
    總用量 0
    [root@localhost mytest]# mkdir -p xiangjis2/al/d
    [root@localhost mytest]# rm -rf xiangjis2/*
    [root@localhost mytest]# ls
    xiangjis2
    [root@localhost mytest]# tree xiangjis2
    xiangjis2
     
    0 directories, 0 files

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市湃望,隨后出現(xiàn)的幾起案子换衬,更是在濱河造成了極大的恐慌痰驱,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,590評(píng)論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件瞳浦,死亡現(xiàn)場(chǎng)離奇詭異担映,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)叫潦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,157評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門(mén)蝇完,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人矗蕊,你說(shuō)我怎么就攤上這事短蜕。” “怎么了傻咖?”我有些...
    開(kāi)封第一講書(shū)人閱讀 169,301評(píng)論 0 362
  • 文/不壞的土叔 我叫張陵朋魔,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我卿操,道長(zhǎng)警检,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 60,078評(píng)論 1 300
  • 正文 為了忘掉前任害淤,我火速辦了婚禮扇雕,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘窥摄。我一直安慰自己镶奉,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,082評(píng)論 6 398
  • 文/花漫 我一把揭開(kāi)白布崭放。 她就那樣靜靜地躺著哨苛,像睡著了一般。 火紅的嫁衣襯著肌膚如雪莹菱。 梳的紋絲不亂的頭發(fā)上移国,一...
    開(kāi)封第一講書(shū)人閱讀 52,682評(píng)論 1 312
  • 那天,我揣著相機(jī)與錄音道伟,去河邊找鬼迹缀。 笑死,一個(gè)胖子當(dāng)著我的面吹牛蜜徽,可吹牛的內(nèi)容都是我干的祝懂。 我是一名探鬼主播,決...
    沈念sama閱讀 41,155評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼拘鞋,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼砚蓬!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起盆色,我...
    開(kāi)封第一講書(shū)人閱讀 40,098評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤灰蛙,失蹤者是張志新(化名)和其女友劉穎祟剔,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體摩梧,經(jīng)...
    沈念sama閱讀 46,638評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡物延,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,701評(píng)論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了仅父。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片叛薯。...
    茶點(diǎn)故事閱讀 40,852評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖笙纤,靈堂內(nèi)的尸體忽然破棺而出耗溜,到底是詐尸還是另有隱情,我是刑警寧澤省容,帶...
    沈念sama閱讀 36,520評(píng)論 5 351
  • 正文 年R本政府宣布抖拴,位于F島的核電站,受9級(jí)特大地震影響蓉冈,放射性物質(zhì)發(fā)生泄漏城舞。R本人自食惡果不足惜轩触,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,181評(píng)論 3 335
  • 文/蒙蒙 一寞酿、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧脱柱,春花似錦伐弹、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,674評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至随闺,卻和暖如春日川,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背矩乐。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,788評(píng)論 1 274
  • 我被黑心中介騙來(lái)泰國(guó)打工龄句, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人散罕。 一個(gè)月前我還...
    沈念sama閱讀 49,279評(píng)論 3 379
  • 正文 我出身青樓分歇,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親欧漱。 傳聞我的和親對(duì)象是個(gè)殘疾皇子职抡,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,851評(píng)論 2 361

推薦閱讀更多精彩內(nèi)容