2020-12-06 第二次

1、描述Linux發(fā)行版的系統(tǒng)目錄名稱命名規(guī)則以及用途。

linux目錄得命名規(guī)則:

1、目錄名稱嚴(yán)格區(qū)分大小寫

2、目錄名稱得長(zhǎng)度超過(guò)255個(gè)字符

3、目錄命名時(shí)嚴(yán)禁使用系統(tǒng)含有特殊含義得字符,例如:/、$、?等

linux存在得各目錄的用途:

/boot:此目錄中存放系統(tǒng)開(kāi)機(jī)時(shí)加載的引導(dǎo)程序文件,內(nèi)核文件(vmlinuz)、引導(dǎo)加載器(bootloader,grub)

/dev: 此目錄存放的是系統(tǒng)的相關(guān)硬件設(shè)備文件

/home:此目錄是普通用戶的家目錄,存放普通用戶的相關(guān)信息

/root:此目錄為管理員的家目錄

/bin: 存放所有用戶使用的基本命令,現(xiàn)已為/usr/bin的軟連接文件

/sbin:存放管理員用戶使用的命令,現(xiàn)已位/usr/sbin的軟連接文件

/lib:?jiǎn)?dòng)時(shí)程序依賴的基本共享庫(kù)文件以及內(nèi)核模塊文件

/lib64:專用于64位系統(tǒng)的輔助共享庫(kù)文件存放位置

/media:移動(dòng)設(shè)備的掛載點(diǎn)

/mnt:臨時(shí)文件系統(tǒng)的掛載點(diǎn)

/tmp:存放臨時(shí)文件的目錄

/opt:第三方應(yīng)用程序的安裝目錄

/sys:存放當(dāng)前系統(tǒng)硬件設(shè)備相關(guān)信息的虛擬文件系統(tǒng)

/proc:存放內(nèi)核于進(jìn)程相關(guān)的虛擬文件系統(tǒng)

/etc:存放配置文件目錄

/srv:此目錄存放一些服務(wù)啟動(dòng)后需要提取的數(shù)據(jù)

/usr:共享資源文件目錄

/var:此目錄存放日志相關(guān)內(nèi)容

====================================

2、描述文件的元數(shù)據(jù)信息有哪些,分別表示什么含義,如何查看?如何修改文件的時(shí)間戳信息?

查看文件的元數(shù)據(jù):

[08:29:12? root@node ~]#ll /data/scripts/systeminfo.sh

-rwxr-xr-x 1 root root 704 Nov 12 23:27 /data/scripts/systeminfo.sh

-rwxr-xr-x:

前面的共有十位:

-:代表文件位普通文件

rwx:文件所有者所擁有的權(quán)限

r-x:文件所屬組所擁有的權(quán)限

r-x:其他人所擁有的權(quán)限

1:代表的是此文件的鏈接文件數(shù)

root(第一個(gè)):文件的所有者

root(第二個(gè)):文件的所屬組

704: 文件的大小是多少

Nov 12 23:27:此文件的生成時(shí)間

/data/scripts/systeminfo.sh:文件的名稱

查看文件的時(shí)間戳:

[09:04:49? root@node scripts]#stat systeminfo.sh

File: systeminfo.sh?

Size: 704? ? ? Blocks: 8? ? ? ? ? IO Block: 4096? regular file

Device: fd00h/64768d Inode: 33615504? ? Links: 1

Access: (0755/-rwxr-xr-x)? Uid: (? ? 0/? ? root)? Gid: (? ? 0/? ? root)

Access: 2020-11-23 07:34:59.342379388 -0500

Modify: 2020-11-12 23:27:22.945408338 -0500

Change: 2020-11-16 01:09:08.550564269 -0500

Birth: -

更改文件的時(shí)間戳信息

[09:04:58? root@node scripts]#touch systeminfo.sh

[09:05:56? root@node scripts]#stat systeminfo.sh

File: systeminfo.sh?

Size: 704? ? ? Blocks: 8? ? ? ? ? IO Block: 4096? regular file

Device: fd00h/64768d Inode: 33615504? ? Links: 1

Access: (0755/-rwxr-xr-x)? Uid: (? ? 0/? ? root)? Gid: (? ? 0/? ? root)

Access: 2020-12-01 09:05:56.960942280 -0500

Modify: 2020-12-01 09:05:56.960942280 -0500

Change: 2020-12-01 09:05:56.960942280 -0500

Birth: -

====================================

3、總結(jié)軟連接和硬連接區(qū)別。


創(chuàng)建硬鏈接文件:

[17:54:56? root@centos8 local]#ln a.txt /tmp/a.txt

[17:55:52? root@centos8 local]#ll -i /tmp/a.txt? a.txt

1190967 -rw-r--r--. 2 root root 0 Dec? 2 17:54 a.txt

1190967 -rw-r--r--. 2 root root 0 Dec? 2 17:54 /tmp/a.txt

[17:56:10? root@centos8 local]#echo "hello world" > a.txt

[17:56:37? root@centos8 local]#cat a.txt

hello world

[17:56:40? root@centos8 local]#cat /tmp/a.txt

hello world

刪除硬鏈接源文件,不影響鏈接文件的查看

[17:56:46? root@centos8 local]#rm a.txt? ? ? ? ?

rm: remove regular file 'a.txt'? y

[17:58:49? root@centos8 local]#ls

[17:58:51? root@centos8 local]#cat /tmp/a.txt

hello world

創(chuàng)建軟鏈接文件

[18:21:10? root@centos8 data]#ln -s /data/mysql/? /tmp/mysql_softlink

[18:21:42? root@centos8 data]#ll /tmp/mysql_softlink

lrwxrwxrwx. 1 root root 12 Dec? 2 18:21 /tmp/mysql_softlink -> /data/mysql/

[18:21:50? root@centos8 data]#cd /data/mysql/

[18:22:35? root@centos8 mysql]#touch a.txt

[18:22:42? root@centos8 mysql]#ls

a.txt

[18:22:49? root@centos8 mysql]#cat /tmp/mysql_softlink/a.txt

[18:22:57? root@centos8 mysql]#ls /tmp/mysql_softlink/

a.txt

刪除軟鏈接文件

[18:23:05? root@centos8 mysql]#rm -rf /data/mysql/

[18:23:43? root@centos8 mysql]#ll /tmp/mysql_softlink

lrwxrwxrwx. 1 root root 12 Dec? 2 18:21 /tmp/mysql_softlink -> /data/mysql/(此處為紅色閃爍狀態(tài))

[18:24:24? root@centos8 tmp]#cd /tmp/mysql_softling? ? ? ? ? ? ? 軟鏈接文件無(wú)法查看

-bash: cd: /tmp/mysql_softling: No such file or directory

====================================

4、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關(guān)示例演示。

*********************************************

pwd:顯示當(dāng)前所在的工作目錄

-P:顯示真實(shí)物理路徑

-L:顯示鏈接路徑(默認(rèn))

例子:

[18:55:11? root@centos8 data]#pwd

/data

[18:55:12? root@centos8 data]#cd /bin/

[18:55:37? root@centos8 bin]#pwd -P

/usr/bin

[18:55:40? root@centos8 bin]#pwd -L

/bin

*********************************************

basename:基名(只取文件的名稱)

dirname:目錄名(只讀取文件的目錄名稱,不要文件名)

例子:

[18:58:54? root@centos8 ~]#touch a.txt;basename /data/mysql/a.txt

a.txt

[18:59:31? root@centos8 ~]#dirname /data/mysql/a.txt

/data/mysql

*********************************************

cd:更改當(dāng)前的工作目錄

? ? -P:切換至物理路勁,而非軟鏈接目錄

cd -:切換至以前工作目錄

cd:切換至當(dāng)前用戶的主目錄

cd ..:切換至當(dāng)前工作目錄的父目錄

例子:

[18:59:53? root@centos8 ~]#cd /data/mysql/

[19:06:36? root@centos8 mysql]#cd ..

[19:06:41? root@centos8 data]#cd -

/data/mysql

[19:06:46? root@centos8 mysql]#cd

[19:06:51? root@centos8 ~]#

[19:06:51? root@centos8 ~]#cd -P /bin

[19:07:19? root@centos8 bin]#pwd

/usr/bin

*********************************************

ls:列出當(dāng)前目錄的內(nèi)容或指定目錄的內(nèi)容

-a:顯示包含隱藏文件的所有文件

-l:以長(zhǎng)格式顯示文件的屬性

-R:遞歸顯示

-ld:目錄和符號(hào)的鏈接信息

-1:文件分行進(jìn)行顯示

-S:按從大到小排序

-t:按mtime排序

-u:配合-t使用,顯示并按atime從新到舊排序

-U:按目存放順序顯示

-X: 按文件后綴排序

例子:

[19:25:32? root@centos8 data]#ls -a

.? ..? local? mysql

[19:25:34? root@centos8 data]#ls -la

total 0

drwxr-xr-x.? 4 root root? 32 Dec? 2 18:28 .

dr-xr-xr-x. 18 root root 236 Dec? 2 17:53 ..

drwxr-xr-x.? 2 root root? 26 Dec? 2 18:06 local

drwxr-xr-x.? 2 root root? 6 Dec? 2 18:28 mysql

[19:25:39? root@centos8 data]#ls -lta

total 0

drwxr-xr-x.? 4 root root? 32 Dec? 2 18:28 .

drwxr-xr-x.? 2 root root? 6 Dec? 2 18:28 mysql

drwxr-xr-x.? 2 root root? 26 Dec? 2 18:06 local

dr-xr-xr-x. 18 root root 236 Dec? 2 17:53 ..

[19:27:31? root@centos8 ~]#ll -R /data/

/data/:

total 0

drwxr-xr-x. 2 root root 26 Dec? 2 18:06 local

drwxr-xr-x. 2 root root? 6 Dec? 2 18:28 mysql

/data/local:

total 4

-rw-r--r--. 1 root root 6 Dec? 2 18:14 softlink.txt

/data/mysql:

total 0

*********************************************

stat:查看文件狀態(tài)

文件的相關(guān)信息:metadata,data

例子:

[09:05:56? root@node scripts]#stat systeminfo.sh

File: systeminfo.sh?

Size: 704? ? ? Blocks: 8? ? ? ? ? IO Block: 4096? regular file

Device: fd00h/64768d Inode: 33615504? ? Links: 1

Access: (0755/-rwxr-xr-x)? Uid: (? ? 0/? ? root)? Gid: (? ? 0/? ? root)

Access: 2020-12-01 09:05:56.960942280 -0500? ? //讀取文件內(nèi)容,此時(shí)間修改

Modify: 2020-12-01 09:05:56.960942280 -0500? ? //改變文件的內(nèi)容,時(shí)間發(fā)生改變

Change: 2020-12-01 09:05:56.960942280 -0500? ? //改變文件的metadata,時(shí)間發(fā)生改變

Birth: -

*********************************************

file:查看文件的類型

-b:列出文件辨識(shí)結(jié)果時(shí),不顯示文件的名稱

-f:filelist列出文件filelist中文件名的文件類型

-L:查看對(duì)應(yīng)軟連接對(duì)應(yīng)文件的文件類型

例子:

[19:27:38? root@centos8 ~]#file /etc/

/etc/: directory

[19:42:35? root@centos8 ~]#file -b /etc/

directory

[19:42:41? root@centos8 ~]#file -L /etc/

/etc/: directory

[19:42:53? root@centos8 ~]#file -L /bin/

/bin/: directory

[20:02:49? root@centos8 ~]#echo "/etc" > /data/local/file.list

[20:03:04? root@centos8 ~]#file -f /data/local/file.list

/etc: directory

*********************************************

touch:可以創(chuàng)建空文件和刷新文件的三個(gè)時(shí)間戳

-a:僅改變atime和ctime

-m:僅改變mtime和ctime

-t:指定atime和mtime的時(shí)間戳格式

-c:文件如果不存在,則不予創(chuàng)建

例子:

[21:08:34? root@centos8 local]#stat file.list

? File: file.list

? Size: 5? ? ? ? Blocks: 8? ? ? ? ? IO Block: 4096? regular file

Device: fd00h/64768d Inode: 1190968? ? Links: 1

Access: (0644/-rw-r--r--)? Uid: (? ? 0/? ? root)? Gid: (? ? 0/? ? root)

Context: unconfined_u:object_r:default_t:s0

Access: 2020-12-02 20:03:07.289592962 +0800

Modify: 2020-12-02 20:03:04.672592763 +0800

Change: 2020-12-02 20:03:04.672592763 +0800

Birth: -

[21:08:51? root@centos8 local]#touch -a? file.list

[21:08:59? root@centos8 local]#stat file.list

? File: file.list

? Size: 5? ? ? ? Blocks: 8? ? ? ? ? IO Block: 4096? regular file

Device: fd00h/64768d Inode: 1190968? ? Links: 1

Access: (0644/-rw-r--r--)? Uid: (? ? 0/? ? root)? Gid: (? ? 0/? ? root)

Context: unconfined_u:object_r:default_t:s0

Access: 2020-12-02 21:08:59.151894356 +0800

Modify: 2020-12-02 20:03:04.672592763 +0800

Change: 2020-12-02 21:08:59.151894356 +0800

Birth: -

[21:09:00? root@centos8 local]#touch -c file.list

[21:10:14? root@centos8 local]#ls

file.list? softlink.txt

*********************************************

cp復(fù)制文件和目錄

-i:目標(biāo)文件存在,提示是否覆蓋

-r|R:遞歸復(fù)制目錄中的文件

-a:歸檔,常用于備份功能

-d:不復(fù)制源文件,只復(fù)制鏈接名

-v:顯示復(fù)制過(guò)程的詳細(xì)信息

-f:強(qiáng)制復(fù)制

-p:復(fù)制文件的所有者、所屬組、權(quán)限、和時(shí)間戳

-b:目標(biāo)存在,覆蓋前先備份,默認(rèn)的形式為filename~

例子:

[21:32:27? root@centos8 ~]#cp /etc/profile /tmp/

cp: overwrite '/tmp/profile'? y

[21:48:45? root@centos8 ~]#alias cp

alias cp='cp -i'

[21:48:49? root@centos8 ~]#cp -r /etc? /tmp/etc

[21:49:30? root@centos8 ~]#ls /tmp/etc/

====================================

5、復(fù)制/etc/profile至/tmp/目錄,用查找替換命令刪除/tmp/profile文件中的 行首的空白字符

[21:23:38? root@centos8 ~]#cp /etc/profile? /tmp

[21:23:38? root@centos8 ~]#cat /tmp/profile | tr -d ' '

====================================

6、在vim中設(shè)置tab縮進(jìn)為4個(gè)字符

[21:32:03? root@centos8 ~]#vim .vimrc

set ts=4

set autoindent

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、基礎(chǔ)1.1 什么是絕對(duì)路徑,什么是相對(duì)路徑(2 分)絕對(duì)路徑:一般以/開(kāi)始的都是絕對(duì)路徑相對(duì)路徑:相對(duì)于當(dāng)前路...
    蜜桃貓七七閱讀 378評(píng)論 1 0
  • 第二次考試1.1 什么是絕對(duì)路徑,什么是相對(duì)路徑(2 分)絕對(duì)路徑是從/開(kāi)始的是從當(dāng)前路徑開(kāi)始的路徑, 1.2 簡(jiǎn)...
    a幕城閱讀 488評(píng)論 1 0
  • 一、基礎(chǔ)1.1 什么是絕對(duì)路徑,什么是相對(duì)路徑(2 分)1.2 簡(jiǎn)述命令執(zhí)行的流程(2 分)1.3 簡(jiǎn)述軟連接與硬...
    江枍_a99e閱讀 681評(píng)論 1 2
  • 一、基礎(chǔ) 1.1 什么是絕對(duì)路徑,什么是相對(duì)路徑 相對(duì)路徑:從當(dāng)前目錄開(kāi)始的就是相對(duì)路徑 絕對(duì)路徑:從根開(kāi)始的路徑...
    生活一場(chǎng)戲而已_b526閱讀 365評(píng)論 1 0
  • 久違的晴天,家長(zhǎng)會(huì)。 家長(zhǎng)大會(huì)開(kāi)好到教室時(shí),離放學(xué)已經(jīng)沒(méi)多少時(shí)間了。班主任說(shuō)已經(jīng)安排了三個(gè)家長(zhǎng)分享經(jīng)驗(yàn)。 放學(xué)鈴聲...
    飄雪兒5閱讀 7,788評(píng)論 16 22

友情鏈接更多精彩內(nèi)容