1. 描述Linux發(fā)行版的系統(tǒng)目錄名稱命名規(guī)則以及用途。
- 文件系統(tǒng)從根目錄開始,用"/"表示
- 標(biāo)準(zhǔn)Linux文件系統(tǒng)(如ext4),文件名稱大小寫敏感
- 路徑分隔的/
- 文件名最長255個字節(jié)
- 包括路徑在內(nèi)文件名稱最長4095個字節(jié)
- 藍(lán)色-->目錄 綠色-->可執(zhí)行文件 紅色-->壓縮文件 淺藍(lán)色-->鏈接文
件 灰色-->其他文件 - 除了斜杠和NUL,所有字符都有效.但使用特殊字符的目錄名和文件不推薦使用,有些字符需要用引號來引用它們
目錄的用途
/bin 所有用戶使用的基本命令;不能關(guān)聯(lián)至獨(dú)立分區(qū),OS啟動即會用到的程序。存放二進(jìn)制可執(zhí)行文件(ls,cat,mkdir等),常用命令一般都在這里
/boot 引導(dǎo)文件存放目錄,內(nèi)核文件(vmlinuz)、引導(dǎo)加載器(bootloader, grub)都存放于此目錄
/dev 設(shè)備文件及特殊文件存儲位置
/etc 配置文件目錄
/home 普通用戶家目錄,各個普通用戶的家目錄都是在此
/root 管理員的家目錄
/sbin 存放二進(jìn)制可執(zhí)行文件,超級權(quán)限用戶才能訪問
/tmp 存放各種臨時文件
/var 用于存放運(yùn)行時需要改變數(shù)據(jù)的文件
/lib 存放跟文件系統(tǒng)中的程序運(yùn)行所需要的共享庫及內(nèi)核模塊
/mnt 臨時文件系統(tǒng)的安裝點(diǎn)
proc 用于輸出內(nèi)核與進(jìn)程信息相關(guān)的虛擬文件系統(tǒng)
sys 用于輸出當(dāng)前系統(tǒng)上硬件設(shè)備相關(guān)信息虛擬文件系統(tǒng)
/opt 第三方應(yīng)用程序的安裝位置
/usr 全局共享的只讀數(shù)據(jù)路徑
2. 描述文件的元數(shù)信息有哪些,分別表示什么含義,如何查看?如何修改文件的時間戳信息?
查看文件元數(shù)信息的主要命令有:file ,ls type,stat等
[root@centos7 ~]# stat /tmp/profile
File: ‘/tmp/profile’
Size: 1819 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 67792775 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-12-01 20:10:11.470129625 +0800
Modify: 2020-12-01 20:10:00.536129214 +0800
Change: 2020-12-01 20:10:00.536129214 +0800
Birth: -
file:文件的完整名稱
Size:文件的數(shù)據(jù)大小
Blocks:占用磁盤的塊數(shù)
IO Block:IO 塊的大小
Device:所在設(shè)備
regular:文件的類型
Indoe:文件的節(jié)點(diǎn)
Links:文件的鏈接數(shù)
Access:文件的訪問權(quán)限
Uid:屬主id/用戶
Gid:屬組id/組名
access time :訪問時間,atime,讀取文件內(nèi)容
modify time :修改時間, mtime,改變文件內(nèi)容
change time :改變時間, ctime,元數(shù)據(jù)發(fā)生改變(chmod,chown)
何修改文件的時間戳
touch -a 修改access time 和 change time
[root@centos7 ~]# stat /tmp/profile
File: ‘/tmp/profile’
Size: 1819 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 67792775 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-12-01 20:45:05.814208313 +0800
Modify: 2020-12-01 20:45:05.814208313 +0800
Change: 2020-12-01 20:45:05.814208313 +0800
Birth: -
[root@centos7 ~]# touch -a /tmp/profile
[root@centos7 ~]# stat /tmp/profile
File: ‘/tmp/profile’
Size: 1819 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 67792775 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-12-01 20:46:08.593210671 +0800
Modify: 2020-12-01 20:45:05.814208313 +0800
Change: 2020-12-01 20:46:08.593210671 +0800
touch -m 修改Modify time和 change time
[root@centos7 ~]# touch -m /tmp/profile
[root@centos7 ~]# stat /tmp/profile
File: ‘/tmp/profile’
Size: 1819 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 67792775 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-12-01 20:46:08.593210671 +0800
Modify: 2020-12-01 20:46:29.943211474 +0800
Change: 2020-12-01 20:46:29.943211474 +0800
Birth: -
當(dāng)然很多命令操作都會更改文件的時間戳,如chown , cat , vim等。
[root@centos7 ~]# chown kenny /tmp/profile
[root@centos7 ~]# stat /tmp/profile
File: ‘/tmp/profile’
Size: 1819 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 67792775 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ kenny) Gid: ( 0/ root)
Access: 2020-12-01 20:46:08.593210671 +0800
Modify: 2020-12-01 20:46:29.943211474 +0800
Change: 2020-12-01 20:48:50.279216746 +0800
Birth: -
[root@centos7 ~]# cat /tmp/profile > /dev/null
[root@centos7 ~]# stat /tmp/profile
File: ‘/tmp/profile’
Size: 1819 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 67792775 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ kenny) Gid: ( 0/ root)
Access: 2020-12-01 20:49:26.591218111 +0800
Modify: 2020-12-01 20:46:29.943211474 +0800
Change: 2020-12-01 20:48:50.279216746 +0800
Birth: -
[root@centos7 ~]#
3. 總結(jié)軟連接和硬連接的區(qū)別,并用實(shí)例操作說明。
| 軟鏈接 | 硬鏈接 | |
|---|---|---|
| 本質(zhì) | 不是同一個文件,inode不同 | 同一個文件,inode相同 |
| 跨文件系統(tǒng) | 支持 | 不支持 |
| 目錄 | 支持 | 不支持 |
| 鏈接數(shù) | 創(chuàng)建和刪除,鏈接數(shù)不變 | 新的硬鏈接,鏈接數(shù)增加 |
| 相對路徑 | 原始文件相對于鏈接文件的相對路徑(一般用絕對路徑設(shè)置) | 原始文件相對于當(dāng)前工作路徑 |
| 文件類型 | 鏈接文件 | 和源文件相同 |
| 設(shè)置命令 | ln -s 命令 | ln默認(rèn)是硬鏈接 |
示例說明
/tmp 和/data是不同的文件系統(tǒng),同文件系統(tǒng)不能建立硬鏈接。建成后的inote號,和鏈接數(shù),文件大小都不同。
root@centos7 ~]# ln -s /tmp/profile /data/profile-softlink
[root@centos7 ~]# ln /tmp/profile /data/profile-hardlink
ln: failed to create hard link ‘/data/profile-hardlink’ => ‘/tmp/profile’: Invalid cross-device link
[root@centos7 ~]# ln /tmp/profile /root/profile-hardlink
[root@centos7 ~]# ls -li /root/profile-hardlink /data/profile-softlink /tmp/profile
67 lrwxrwxrwx 1 root root 12 Dec 1 21:19 /data/profile-softlink -> /tmp/profile
67792775 -rw-r--r-- 2 kenny root 1819 Dec 1 20:46 /root/profile-hardlink
67792775 -rw-r--r-- 2 kenny root 1819 Dec 1 20:46 /tmp/profile
4. Linux上的文件管理類命令有哪些,其常用的使用方法及其相關(guān)示例演示。
-
顯示當(dāng)前工作目錄:pwd
選項(xiàng):
-P 顯示真實(shí)物理路徑
-L 顯示鏈接路徑(默認(rèn))[root@centos7 ~]# pwd /root
-
更改目錄: cd
-p 如果要切換到的目標(biāo)目錄是一個符號連接,直接切換到符號連接指向的目標(biāo)目錄
-L 如果要切換的目標(biāo)目錄是一個符號的連接,直接切換到字符連接名代表的目錄,而非符號連接所指向的目標(biāo)目錄。cd 進(jìn)入用戶主目錄;
cd ~ 進(jìn)入用戶主目錄;
cd - 返回進(jìn)入此目錄之前所在的目錄;
cd .. 返回上級目錄(若當(dāng)前目錄為“/“,則執(zhí)行完后還在“/";".."為上級目錄的意思);
cd ../.. 返回上兩級目錄;[root@centos7 ~]# cd /tmp [root@centos7 tmp]#
-
列出目錄內(nèi)容: ls
ls -a 包含隱藏文件
ls -l 顯示額外的信息
ls -R 目錄遞歸
ls -ld 目錄和符號鏈接信息
ls -1 文件分行顯示
ls –S 按從大到小排序
ls –t 按mtime排序
ls –u 配合-t選項(xiàng),顯示并按atime從新到舊排序
ls –U 按目錄存放順序顯示
ls –X 按文件后綴排序
stat 用于顯示文件的狀態(tài)信息[root@centos7 tmp]# ls -l total 8 -rwx------. 1 root root 836 Nov 22 03:35 ks-script-y0Mnoe -rw-r--r-- 2 kenny root 1819 Dec 1 20:46 profile drwx------ 2 root root 6 Nov 29 14:06 vmware-root_531-4282236595 drwx------ 2 root root 6 Nov 22 04:06 vmware-root_534-2957583592 drwx------. 2 root root 6 Nov 22 03:49 vmware-root_538-2999460707 drwx------. 2 root root 6 Nov 22 03:46 vmware-root_539-4248811709 drwx------ 2 root root 6 Dec 1 15:49 vmware-root_542-2991268582 drwx------. 2 root root 6 Nov 22 03:42 vmware-root_564-2965382482 -rw-------. 1 root root 0 Nov 22 03:30 yum.log
-
復(fù)制文件和目錄
cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...
cp SRC DEST-a:此參數(shù)的效果和同時指定"-dpR"參數(shù)相同;
-d:當(dāng)復(fù)制符號連接時,把目標(biāo)文件或目錄也建立為符號連接,并指向與源文件或目錄連接的原始文件或目錄;
-f:強(qiáng)行復(fù)制文件或目錄,不論目標(biāo)文件或目錄是否已存在;
-i:覆蓋既有文件之前先詢問用戶;
-l:對源文件建立硬連接,而非復(fù)制文件;
-p:保留源文件或目錄的屬性;
-R/r:遞歸處理,將指定目錄下的所有文件與子目錄一并處理;
-s:對源文件建立符號連接,而非復(fù)制文件;
-u:使用這項(xiàng)參數(shù)后只會在源文件的更改時間較目標(biāo)文件更新時或是名稱相互對應(yīng)的目標(biāo)文件并不存在時,才復(fù)制文件;
-S:在備份文件時,用指定的后綴“SUFFIX”代替文件的默認(rèn)后綴;
-b:覆蓋已存在的文件目標(biāo)前將目標(biāo)文件備份;
-v:詳細(xì)顯示命令執(zhí)行的操作。[root@centos7 tmp]# cp /tmp/profile /data [root@centos7 tmp]#
mv 移動和重命名文件
語法:
mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...
選項(xiàng):
-i 交互式
-f 強(qiáng)制
-b 目標(biāo)存在,覆蓋前先備份
[root@centos7 tmp]# mv /data/profile ~/
[root@centos7 tmp]# ls ~/
anaconda-ks.cfg profile profile-hardlink
rm 刪除
語法:
rm [OPTION]... FILE...
選項(xiàng):
-i 交互式
-f 強(qiáng)制刪除
-r 遞歸
--no-preserve-root 刪除/
[root@centos7 tmp]# rm ~/profile
rm: remove regular file ‘/root/profile’? y
[root@centos7 tmp]# ls ~/
anaconda-ks.cfg profile-hardlink
[root@centos7 tmp]#
5. 復(fù)制/etc/profile至/tmp/目錄,用查找替換命令刪除/tmp/profile文件中的行首的空白字符。
[root@centos7 tmp]# cp /etc/profile /tmp
[root@centos7 tmp]# vim /tmp/profile
#擴(kuò)展命令模式下輸入
:%s/^[[:blank:]]*//g
#或者
:%s/^\s*//g
6. 在vim中設(shè)置tab縮進(jìn)為4個字符
編輯~/.vimrc,添加兩行內(nèi)容,也可以在擴(kuò)展命令模式中設(shè)置。
set ts=4
set et
:set invlist 將不可見的字符顯示出來