day 13 命令行模式特殊字符and 硬鏈接

Day 13


作者:翟玉龍

歸檔:課堂筆記

2019/3/18

快捷鍵:

Ctrl? + 1??? 標(biāo)題1

Ctrl? + 2??? 標(biāo)題2

Ctrl? + 3??? 標(biāo)題3

Ctrl? + 4??? 實(shí)例

Ctrl? + 5??? 程序代碼

Ctrl? + 6??? 正文

格式說(shuō)明:

藍(lán)色字體:注釋

黃色背景:重要

綠色背景:注意

老男孩教育教學(xué)核心思想6重:重目標(biāo)、重思路、重方法、重實(shí)踐、重習(xí)慣、重總結(jié)

學(xué)無(wú)止境,老男孩教育成就你人生的起點(diǎn)!

聯(lián)系方式:

網(wǎng)站運(yùn)維QQ交流群:

Linux?385168604架構(gòu)師390642196

Python 29215534大數(shù)據(jù)421358633

官方網(wǎng)站:

http://www.oldboyedu.com?

目錄

學(xué)無(wú)止境,老男孩教育成就你人生的起點(diǎn)!... 1

第1章 SELinux. 1

1.1 安全規(guī)則讓Linux系統(tǒng)更安全的一套規(guī)則... 1

1.2 怎么關(guān)掉selinux. 1

1.2.1 臨時(shí)關(guān)閉... 1

1.2.2 永久關(guān)閉... 1

第2章 老男孩思想之優(yōu)秀的運(yùn)維思想... 1

第3章 防火墻簡(jiǎn)介... 1

第4章 硬鏈接... 2

4.1 什么是硬連接?... 2

第5章 通配符知識(shí)與實(shí)踐... 3

5.1 通配符... 3

5.1.1 基本含意... 3

通配符就是鍵盤(pán)上的一些特殊字符,實(shí)現(xiàn)某些特殊的功能... 3

5.1.2 適用范圍... 3






[if !supportLists]第1章 [endif]SELinux

[if !supportLists]1.1 [endif]安全規(guī)則讓Linux系統(tǒng)更安全的一套規(guī)則

但是這個(gè)規(guī)則太嚴(yán)格了,所以一般情況下都會(huì)關(guān)閉selinux

[if !supportLists]1.2 [endif]怎么關(guān)掉selinux

查看狀態(tài)getenforce

[if !supportLists]1.2.1 [endif]???臨時(shí)關(guān)閉

?????? Setenforce? 0

[if !supportLists]1.2.2 [endif]???永久關(guān)閉

??/etc/selinux/config

[if !supportLists]第2章 [endif]防火墻簡(jiǎn)介

Linux 里的防火墻?C6 iptables???C7 firewalld

作用:防護(hù)計(jì)算機(jī) 防止被入侵

Systemctl? status firewalld.service

開(kāi)機(jī)自啟動(dòng)4

Systemctl enable firewalld.service

開(kāi)機(jī)不啟動(dòng)即使

?? Disable

C6用法

???? Chkconfig? iptables[if !vml]

[endif]off

[if !supportLists]第3章 [endif]硬鏈接

[if !supportLists]3.1[endif]???什么是硬連接?

具有相同inode 節(jié)點(diǎn)號(hào)的文件互為硬鏈接



一個(gè)文件的兩個(gè)入口。

[root@oldboyedu~]# ls -ldi test test/.

16964029drwxr-xr-x. 2 root root 4096 Oct? 1 14:07test

16964029drwxr-xr-x. 2 root root 4096 Oct? 1 14:07test/.

[root@oldboyedu/data]# ls -ldi oldboy

33631853drwxr-xr-x. 5 root root 45 Oct? 4 21:03oldboy

[root@oldboyedu/data]# ls -ldi oldboy oldboy/. oldboy/test{1..3}/..

33631853drwxr-xr-x. 5 root root 45 Oct? 4 21:03oldboy

33631853drwxr-xr-x. 5 root root 45 Oct? 4 21:03oldboy/.

33631853drwxr-xr-x. 5 root root 45 Oct? 4 21:03oldboy/test1/..

33631853drwxr-xr-x. 5 root root 45 Oct? 4 21:03oldboy/test2/..

33631853drwxr-xr-x. 5 root root 45 Oct? 4 21:03oldboy/test3/..

2.硬鏈接的原理?

相同文件不同名字

3? 測(cè)試

創(chuàng)建硬鏈接

?Ln?? 原文件??硬鏈接文件

A? 文件的硬鏈接a.文件硬鏈接

[root@oldboyedu/data]# echo "I am oldboy." >oldboy.txt

[root@oldboyedu/data]# cat oldboy.txt

I am oldboy.

[root@oldboyedu/data]# ln oldboy.t

oldboy.tar.gz? oldboy.txt????

[root@oldboyedu/data]# ln oldboy.txt oldboy_hard_link

[root@oldboyedu/data]# ls -lirt

total 20

33631860 -rw-r--r--.1 root root?? 0 Oct? 1 00:19 5.txt

33631855-rw-r--r--. 1 root root?? 0 Oct? 1 00:19 4.txt

33631847-rw-r--r--. 1 root root?? 0 Oct? 1 00:19 3.txt

33631845-rw-r--r--. 1 root root?? 0 Oct? 1 00:19 2.txt

33631841-rw-r--r--. 1 root root?? 0 Oct? 1 00:19 1.txt

33656236-rw-r--r--. 1 root root? 18 Oct? 1 09:01 paichu.txt

33631869-rw-r--r--. 1 root root 187 Oct? 1 09:01oldboy.tar.gz

33656257-rwxr-xr-x. 1 root root? 14 Oct? 1 11:07 test.txt

33631853drwxr-xr-x. 5 root root? 45 Oct? 4 21:03 oldboy

33656238-rw-r--r--. 2 root root? 13 Oct? 4 21:10 oldboy.txt

33656238-rw-r--r--. 2 root root? 13 Oct? 4 21:10 oldboy_hard_link



作用:

1、備份,防止誤刪。

[root@oldboyedu/data]# ln /etc/hostname /opt/hostname

[root@oldboyedu/data]# cat /opt/hostname

oldboyedu

[root@oldboyedu/data]# rm -f /etc/hostname

[root@oldboyedu/data]# cat /etc/hostname

cat:/etc/hostname: No such file or directory

[root@oldboyedu/data]# cat /opt/hostname

oldboyedu

[root@oldboyedu/data]# ln /opt/hostname /etc/hostname

[root@oldboyedu/data]# cat /etc/hostname

oldboyedu

作用,備份?防止誤刪

Linux里不支持人工對(duì)目錄創(chuàng)建硬鏈接

Linux 文件刪除原理

[if !vml]

[endif]

[if !supportLists]1.???? [endif]靜態(tài)文件,:沒(méi)有進(jìn)程或者程序正在訪(fǎng)問(wèn)的文件

所有的硬鏈接數(shù)為0(i_link)? 即所有硬鏈接都被干掉了,包括自身

硬鏈接的數(shù)量的代表變量符號(hào)I_link

Rm -f

oldboy.txtt oldboy_hard_link 執(zhí)行完,其實(shí)文件也沒(méi)刪

A.系統(tǒng)會(huì)定時(shí)清理沒(méi)有文件名的inode

???? b.磁盤(pán)檢查的時(shí)候會(huì)清理

???? c.當(dāng)增加新文件是會(huì)優(yōu)先占用沒(méi)有文件名的inode

恢復(fù)工具:debugfs,ext3grep等等

但是亡羊補(bǔ)牢實(shí)不可取的,直接違反運(yùn)維的三大職責(zé)

解決方法:多備份,操作前備份,異服務(wù)器備份和異地備份

[if !supportLists]2.???? [endif]動(dòng)態(tài)文件:有程序或進(jìn)程訪(fǎng)問(wèn)的文件

[if !supportLists]A.??? [endif]i_link為0

[if !supportLists]B. [endif]i_count為0 。i_count是進(jìn)程調(diào)用文件的數(shù)量(引用計(jì)數(shù)),所有進(jìn)程調(diào)用都要停止取消。

[if !supportLists]3.???? [endif]實(shí)踐文件刪除原理。

環(huán)境準(zhǔn)備,命令集合如下:

mkdir -p /app/logs?????????????????????????? #<==創(chuàng)建用于掛載的目錄。

dd if=/dev/zero of=/dev/sdc bs=8K? count=10?#<==創(chuàng)建指定大小的文件。

mkfs.ext4 /dev/sdc?????????????????????????? #<==格式化。

mount -o loop /dev/sdc /app/logs???????????? #<==掛載。

df -h???????????????????????????? ???????????#<==檢查掛載結(jié)果。

實(shí)踐:

[root@oldboyedu /data]# cd /app/logs/

[root@oldboyedu /app/logs]# touch nginx.log

[root@oldboyedu /app/logs]# tail -fnginx.log


[root@oldboyedu /app/logs]# cat/etc/services >>nginx.log

cat: write error: No space left on device

[root@oldboyedu /app/logs]# df -h

Filesystem????? Size?Used Avail Use% Mounted on

/dev/sda3??????? 19G?1.9G?? 18G? 10% /

devtmpfs??????? 980M??80K? 980M?? 1% /dev

tmpfs?????????? 991M???? 0?991M?? 0% /dev/shm

tmpfs?????????? 991M?9.5M? 981M?? 1% /run

tmpfs?????????? 991M???? 0?991M?? 0% /sys/fs/cgroup

/dev/sda1?????? 253M?136M? 118M? 54% /boot

tmpfs?????????? 199M???? 0?199M?? 0% /run/user/0

/dev/loop0?????? 73K??71K???? 0 100% /app/logs


2


明明刪除了,結(jié)果還是100%。

[root@oldboyedu /app/logs]# rm -f nginx.log

[root@oldboyedu /app/logs]# lsof|grep nginx

tail?????7927???????? root??? 3r?????REG??????????????? 7,0???? 57344???????? 12 /app/logs/nginx.log (deleted)


[root@oldboyedu /app/logs]# df -h

Filesystem????? Size?Used Avail Use% Mounted on

/dev/sda3??????? 19G?1.9G?? 18G? 10% /

devtmpfs??????? 980M??80K? 980M?? 1% /dev

tmpfs?????????? 991M???? 0?991M?? 0% /dev/shm

tmpfs?????????? 991M?9.5M? 981M?? 1% /run

tmpfs?????????? 991M???? 0?991M?? 0% /sys/fs/cgroup

/dev/sda1????? ?253M?136M? 118M? 54% /boot

tmpfs?????????? 199M???? 0?199M?? 0% /run/user/0

/dev/loop0?????? 73K??71K???? 0 100% /app/logs


重來(lái):

模擬進(jìn)程讀文件:

[root@oldboyedu /app/logs]# touch nginx.log

[root@oldboyedu /app/logs]# tail -fnginx.log


ln nginx.log nginx_hard.log


當(dāng)前:

i_link=2

i_count=1


模擬把文件變大,讓分區(qū)滿(mǎn)

[root@oldboyedu /app/logs]# cat/etc/services >>nginx.log

cat: write error: No space left on device

[root@oldboyedu /app/logs]# df -h

Filesystem????? Size?Used Avail Use% Mounted on

/dev/sda3??????? 19G?1.9G?? 18G? 10% /

devtmpfs??????? 980M??80K? 980M?? 1% /dev

tmpfs?????????? 991M???? 0?991M?? 0% /dev/shm

tmpfs?????????? 991M?9.5M? 981M?? 1% /run

tmpfs?????????? 991M???? 0?991M?? 0% /sys/fs/cgroup

/dev/sda1?????? 253M?136M? 118M? 54% /boot

tmpfs??????????199M???? 0?199M?? 0% /run/user/0

/dev/loop0?????? 73K??71K???? 0 100% /app/logs


分區(qū)滿(mǎn)了:清理,刪除。


刪除源文件

[root@oldboyedu /app/logs]# rm -f nginx.log

結(jié)果:

i_link=1

i_count=1



ctrl+c 中斷進(jìn)程調(diào)用文件

結(jié)果:

i_link=1

i_count=0



刪除硬鏈接文件

[root@oldboyedu /app/logs]# rm -fnginx_hard.log

結(jié)果:

i_link=0

i_count=0


[root@oldboyedu /app/logs]# df -h

Filesystem????? Size?Used Avail Use% Mounted on

/dev/sda3??????? 19G?1.9G?? 18G? 10% /

devtmpfs??????? 980M??80K? 980M?? 1% /dev

tmpfs?????????? 991M???? 0?991M?? 0% /dev/shm

tmpfs?????????? 991M?9.5M? 981M?? 1% /run

tmpfs?????????? 991M???? 0?991M?? 0% /sys/fs/cgroup

/dev/sda1?????? 253M?136M? 118M? 54% /boot

tmpfs?????????? 199M???? 0?199M?? 0% /run/user/0

/dev/loop0?????? 73K??14K?? 54K? 21% /app/logs


軟鏈接:

本質(zhì)是快捷方式?指向原文件實(shí)體,本身和原文件是不同的文件

目錄

必會(huì)面試題:

軟鏈接和硬鏈接的區(qū)別?

??? ????????????????????第十章特殊符號(hào)

[if !supportLists]第4章 [endif]通配符知識(shí)與實(shí)踐

[if !supportLists]4.1 [endif]通配符

[if !supportLists]4.1.1 [endif]基本含意

通配符就是鍵盤(pán)上的一些特殊字符,實(shí)現(xiàn)某些特殊的功能

例如可以用*來(lái)代表所有模糊查找系統(tǒng)中的文件

[if !supportLists]4.1.2 [endif]適用范圍

命令行中普通命令或者腳本編程中。

[if !vml]

[endif]

?著作權(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)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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