文件系統目錄結構
目錄結構
目錄功能
/mnt :臨時文件掛載點
/media :便攜式移動設備掛載點
/run:正在運行中的信息。(臨時生成的文件或者進程文件)
應用程序組成部分:
文件的類型:
基本文件操作命令
絕對路徑相對路徑
- 絕對路徑:/ 開始,完整顯示路徑位置。
- 相對路徑:不已 / 開始,以某個目錄的路徑開始
顯示當前目錄
pwd--顯示當前工作目錄的絕對路徑
- -L 顯示鏈接路徑
- -P 顯示真實物理路徑
[root@localhost /]# ls -al bin
lrwxrwxrwx. 1 root root 7 Nov 12 19:26 bin -> usr/bin //鏈接文件
[root@localhost /]# cd bin
[root@localhost bin]# pwd -P
/usr/bin
查看文件狀態
stat
文件相關信息:metadata(元數據) data (數據)
- Access time:訪問時間 --讀取文件內容
- Modify:修改時間 --改變文件內容(data)
- Change:改變時間 --改變時間(元數據改變)
改變訪問時間例子:
[root@localhost home]# stat test File: ‘test’ Size: 6 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 68 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:home_root_t:s0 Access: 2020-11-21 03:09:29.002143699 -0500 //注意時間 Modify: 2020-11-21 03:09:29.002143699 -0500 Change: 2020-11-21 03:09:29.002143699 -0500 Birth: - [root@localhost home]# cat test //查看內容 hello [root@localhost home]# stat test File: ‘test’ Size: 6 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 68 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:home_root_t:s0 Access: 2020-11-21 03:23:44.831997330 -0500 //時間變化 Modify: 2020-11-21 03:09:29.002143699 -0500 Change: 2020-11-21 03:09:29.002143699 -0500 Birth: -
注意:centos 6修改了時間的記錄形式,不會每次cat都會改變訪問時間。
修改文件內容第一次cat,會修改access時間。
修改時間例子:
[root@localhost home]# stat test File: ‘test’ Size: 6 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 68 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:home_root_t:s0 Access: 2020-11-21 03:23:44.831997330 -0500 Modify: 2020-11-21 03:09:29.002143699 -0500 //注意時間 Change: 2020-11-21 03:09:29.002143699 -0500 Birth: - [root@localhost home]# vi test [root@localhost home]# cat test hello man [root@localhost home]# stat test File: ‘test’ Size: 11 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 69 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:home_root_t:s0 Access: 2020-11-21 03:28:51.039156019 -0500 Modify: 2020-11-21 03:28:43.679200274 -0500 //內容改變,時間變化。 Change: 2020-11-21 03:28:43.679200274 -0500 Birth: -
改變時間例子
[root@localhost home]# stat test File: ‘test’ Size: 11 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 69 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:home_root_t:s0 Access: 2020-11-21 03:28:51.039156019 -0500 Modify: 2020-11-21 03:28:43.679200274 -0500 Change: 2020-11-21 03:28:43.679200274 -0500 //注意時間 Birth: - [root@localhost home]# chmod 777 test [root@localhost home]# stat test File: ‘test’ Size: 11 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 69 Links: 1 Access: (0777/-rwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:home_root_t:s0 Access: 2020-11-21 03:28:51.039156019 -0500 Modify: 2020-11-21 03:28:43.679200274 -0500 Change: 2020-11-21 03:32:05.895984288 -0500 //權限改變, Birth: -
注意:
ls 命令查看文件,顯示的是Modify時間
文件通配符
對比 符號 [ ] { }
[root@localhost home]# ls [a-h].txt a.txt A.txt b.txt B.txt c.txt C.txt d.txt D.txt e.txt E.txt f.txt F.txt g.txt h.txt //小大小大有順序得排序 [root@localhost home]# ls {a..h}.txt a.txt b.txt c.txt d.txt e.txt f.txt g.txt h.txt //與[a.b.c.d.e.f.g].txt等價
[root@localhost home]# ls [1-6].txt
1.txt 2.txt 3.txt 4.txt 5.txt
[root@localhost home]# ls {1..6}.txt
ls: cannot access 6.txt: No such file or directory
1.txt 2.txt 3.txt 4.txt 5.txt
使用中發現,{ }多用於進行批量次按照特定格式的去創建文件,例如:touch {a..z}.txt,使用中帶 { x.. x }; 而[ ]多用於相同格式的匹配,使用 [ x-x ]。
預定義字符類例子,比較[:digit:]和[[:digit:]]用法。
[root@localhost home]# touch file{a..b}{3..4} [root@localhost home]# ls 1.txt 3.txt 5.txt A.txt B.txt C.txt D.txt E.txt filea4 fileb4 F.txt h.txt 2.txt 4.txt a.txt b.txt c.txt d.txt e.txt filea3 fileb3 f.txt g.txt [root@localhost home]# ls file[[:lower:]][[:digit:]] //外面加[ ]會識別一個整體。 filea3 filea4 fileb3 fileb4 [root@localhost home]# ls file[:lower:][:digit:] ls: cannot access file[:lower:][:digit:]: No such file or directory
作業:
2020-11-27 0:27 (得屌絲者得天下)