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: 已創建目錄 "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
  • 命令演示
    此命令在單獨演示,會穿插到其他的文件管理類命令中,展示命令使用

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 普通空文件
    設備:fd00h/64768d Inode:865184 硬鏈接:1
    權限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問:2017-07-21 10:45:39.622956106 +0800
    最近更改:2017-07-21 10:45:39.622956106 +0800
    最近改動:2017-07-21 10:45:39.622956106 +0800
    創建時間:-
    [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 普通空文件
    設備:fd00h/64768d Inode:865184 硬鏈接:1
    權限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問:2017-07-21 10:46:28.756680491 +0800
    最近更改:2017-07-21 10:46:28.756680491 +0800
    最近改動:2017-07-21 10:46:28.756680491 +0800
    創建時間:-
    [root@localhost mytest]# touch -a du
    [root@localhost mytest]# stat du
    文件:"du"
    大小:0 塊:0 IO 塊:4096 普通空文件
    設備:fd00h/64768d Inode:865184 硬鏈接:1
    權限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問:2017-07-21 10:47:32.738321575 +0800
    最近更改:2017-07-21 10:46:28.756680491 +0800
    最近改動:2017-07-21 10:47:32.738321575 +0800
    創建時間:-
    [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 普通空文件
    設備:fd00h/64768d Inode:865184 硬鏈接:1
    權限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問:2017-07-21 10:48:03.170150868 +0800
    最近更改:2017-07-21 10:49:10.459773392 +0800
    最近改動:2017-07-21 10:49:10.459773392 +0800
    創建時間:-
    [root@localhost mytest]# touch -t 201606201020.20 du
    [root@localhost mytest]# stat du
    文件:"du"
    大小:0 塊:0 IO 塊:4096 普通空文件
    設備:fd00h/64768d Inode:865184 硬鏈接:1
    權限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問:2016-06-20 10:20:20.000000000 +0800
    最近更改:2016-06-20 10:20:20.000000000 +0800
    最近改動:2017-07-21 10:50:47.179230825 +0800
    創建時間:-
    [root@localhost mytest]# touch -at 201606201020.20 du
    [root@localhost mytest]# stat du
    文件:"du"
    大小:0 塊:0 IO 塊:4096 普通空文件
    設備:fd00h/64768d Inode:865184 硬鏈接:1
    權限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問:2016-06-20 10:20:20.000000000 +0800
    最近更改:2017-07-21 10:51:18.172056968 +0800
    最近改動:2017-07-21 10:51:47.230893961 +0800
    創建時間:-
    [root@localhost mytest]# touch -mt 201606211020.20 du
    [root@localhost mytest]#
    [root@localhost mytest]# stat du
    文件:"du"
    大小:0 塊:0 IO 塊:4096 普通空文件
    設備:fd00h/64768d Inode:865184 硬鏈接:1
    權限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
    環境:unconfined_u:object_r:user_tmp_t:s0
    最近訪問:2016-06-20 10:20:20.000000000 +0800
    最近更改:2016-06-21 10:20:20.000000000 +0800
    最近改動:2017-07-21 10:52:20.761705862 +0800
    創建時間:-

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: 目標"xiangjis4" 不是目錄
    [root@localhost mytest]# cp /etc/{passwd,issue} du
    cp: 目標"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: 略過目錄"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: 沒有那個文件或目錄

mv
  • image.png
  • 命令演示
    和cp命令用法大致相同,mv在移動目錄時不用加-v參數。

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: 無法刪除"xiangjis": 是一個目錄
    [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:是否進入目錄"xiangjis1"? yes
    rm:是否進入目錄"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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,882評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,208評論 3 414
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,746評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,666評論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,477評論 6 407
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 54,960評論 1 321
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,047評論 3 440
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,200評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,726評論 1 333
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,617評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,807評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,327評論 5 358
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,049評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,425評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,674評論 1 281
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,432評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,769評論 2 372

推薦閱讀更多精彩內容