三劍客之sed grep

2022-01-31 12:40:12 字數 4399 閱讀 8595

如何取得/etc/hosts 檔案的許可權對應的數字內容,如-rw-r--r--  為 644,要求使用命令取得644 這樣的數字。

[root@znix ~]# stat /etc/hosts |awk -f "[0/]" 'nr==4'

[root@znix ~]# stat -c%a /etc/hosts

linux 下通過 mkdir 命令建立乙個新目錄/clsn/ett,它的硬鏈結數是多少,為什麼?

如果在/clsn/ett下面再建立乙個目錄 test。再問/clsn/ett 的硬鏈結數是多少?為什麼。

[root@znix clsn]# ls -ldi ett/ ett/.

151313 drwxr-xr-x 2 root root 4096 sep  4 10:09 ett/

151313 drwxr-xr-x 2 root root 4096 sep  4 10:09 ett/.

[root@znix clsn]# mkdir -p ett/dir01

[root@znix clsn]# ls -ldi ett/ ett/. ett/dir01/..

151313 drwxr-xr-x 3 root root 4096 sep  4 10:11 ett/

151313 drwxr-xr-x 3 root root 4096 sep  4 10:11 ett/.

151313 drwxr-xr-x 3 root root 4096 sep  4 10:11 ett/dir01/..

執行命令取出 linux中 eth0 的 ip位址。

[root@znix ~]# ifconfig eth0|awk -f "[ :]+" 'nr==2'

10.0.0.201

[root@znix ~]# ifconfig eth0|egrep  "([0-9]\.?)" -o |head -1

10.0.0.201

[root@znix ~]# ifconfig eth0|sed -nr '2s#^.*dr:(.*)  bc.*$#\1#gp'

10.0.0.201

請給出缺省情況 eth0 網絡卡配置檔案的路徑及客戶端 dns的路徑。

eth0

網絡卡/etc/sysconfig/network-scripts/eth0

dns配置

/etc/resolv.conf

查詢當前目錄下所有檔案,並把檔案中的 www.etiantian.org 字串替換成 www.clsn.cc

[root@znix ~]# find /* |sed 's#www.etiantian.org#www.clsn.cc#g'

1.資料不能丟

2.**7*24執行

3.使用者體驗好

盡量讓使用者從記憶體

讀/寫1、運營人員、**使用者發現問題,**有彈窗廣告。

2、運營人員報給開發人員,開發聯絡運維人員。開發和運維共同解決。

3、開發發現的問題原因就是所有站點目錄被嵌入了一段js**。

4、運維人員解決問題:

a)  備份原始出問題的原始檔案。

b)  find+sed替換。

5、詳細檢視日誌,尋找問題發生**。

6、提供亡羊補牢解決方案

在乙個命令上加什麼引數可以實現下面命令的內容在同一行輸出。

-n  不輸出每行行尾的回車

-e  讓echo支援 \n \t  轉移字元系列

\n  換行

\t   tab鍵

[root@znix etc]# echo -n "123" ; echo "223"

[root@znix etc]# echo -n "123"

123[root@znix etc]#

[root@znix etc]# echo -e "123\n"

[root@znix etc]# echo -ne "123\n"

請給出如下格式的 date 命令

例:11-02-26。在給出實現按周輸出

比如:週六輸出為 6,請分別給出命令。

%f 與 %y-%m-%d 相同

[root@znix etc]# date +%f

2017-09-04

[root@znix etc]# date +%y-%m-%d

2017-09-04

%h:%m:%s 與 %t相同

[root@znix etc]# date +%t

10:57:48

[root@znix etc]# date +%h:%m:%s

10:58:53

%w 表示周

[root@znix ~]# date +%f_%w

2017-09-04_1

使用date -s 命令,手動設定命令,但是很少使用。

[root@znix ~]# date -s "20170101 11:41:00"

sun jan  1 11:41:00 cst 2017

ntpdate 聯網同步主機時間。

[root@znix ~]# ntpdate  ntp1.aliyun.com

4 sep 15:17:22 ntpdate[11593]: step time server 182.92.12.11 offset 27.049824 sec

當從root使用者切到普通使用者clsn時,執行ifconfig會提示。

-bash: command not found.

先去path找找到

執行命令直譯器 shell

找不到提示 command not found

export path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/tmp

path 內容放到/etc/profile 檔案最後

soucre  /etc/profile 讓它生效

-d "-3day" 表示三天前

-d "3day"  表示三天後

[root@znix ~]# date +%f

2017-09-04

[root@znix ~]# date -d "-3day" +%f

2017-09-01

[root@znix ~]# date -d "3day" +%f

2017-09-07

clsn

xizi

xiaochao

請問如何把檔案中的空格過濾掉。

-v 排除 ^$ (空行)

[root@znix ~]# grep -v "^$" test.txt

clsn

xizi

xiaochao

'!/^$/' 排除空行

[root@znix ~]# awk '!/^$/' test.txt

clsn

xizi

xiaochao

'/^$/d' 排除空行

[root@znix ~]# sed '/^$/d' test.txt

clsn

xizi

xiaochao

awk '找誰'

sed '找誰幹啥' 

clsn

clssssn

test

請使用 grep或 egrep 正則匹配的方式過濾出前兩行內容

[root@znix ~]# egrep "c+l+n" test.txt

clsn

clssssn

[root@znix ~]# grep -v "^t" test.txt

clsn

clssssn

[root@znix ~]# grep "^[^t]" test.txt

clsn

clssssn

/var/log/messages         系統普通日誌

/var/log/secure          使用者登陸日誌

/etc/fstab                開機自動掛載

/etc/profile              配置別名

環境變數

/etc/spool/cron/root      定時任務

1、接通電源

2、進入bios自檢

3、進入mbr引導

4、進入grub選擇核心

5、載入核心

6、執行init程序

7、讀取執行級別

8、配置主機名ip位址/etc/rc.sysinit

9、根據不同的執行級別執行不同的軟體或服務/etc/rc3.d

10、顯示登入介面

軟連線 ln -s

硬鏈結 ln   兩個檔案inode號相同互為硬鏈結

目錄不能建立硬鏈結

硬鏈結不能跨檔案相同(分割槽)

軟連線可以跨檔案相同,可以對目錄建立軟連線。

1、inode數為0

2、程序呼叫數為0

三劍客之sed grep

如何取得 etc hosts 檔案的許可權對應的數字內容,如 rw r r 為 644,要求使用命令取得644 這樣的數字。root znix stat etc hosts awk f 0 nr 4 root znix stat c a etc hosts linux 下通過 mkdir 命令建立乙...

三劍客之sed grep

如何取得 etc hosts 檔案的許可權對應的數字內容,如 rw r r 為 644,要求使用命令取得644 這樣的數字。root znix stat etc hosts awk f 0 nr 4 root znix stat c a etc hosts linux 下通過 mkdir 命令建立乙...

三劍客之sed grep

如何取得 etc hosts 檔案的許可權對應的數字內容,如 rw r r 為 644,要求使用命令取得644 這樣的數字。root znix stat etc hosts awk f 0 nr 4 root znix stat c a etc hosts linux 下通過 mkdir 命令建立乙...