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