運維linux命令

2021-09-25 09:37:42 字數 4791 閱讀 9856

1、linux啟動過程

開啟電源 --> bios開機自檢 --> 引導程式lilo或grub--> 核心的引導(kernel boot)--> 執行init(rc.sysinit、rc)--> mingetty(建立終端) -->shell

2、網絡卡繫結多ip

# ifconfig eth0:1 192.168.1.99 netmask 255.255.255.0

3、設定dns、閘道器

# echo "nameserver 202.16.53.68" >> /etc/resolv.conf

# route add default gw 192.168.1.1

4、彈出、收回光碟機

# eject

# eject -t

5、用date查詢昨天的日期

# date --date=yesterday

6、查詢file1裡面空行的所在行號

# grep ^$ file

7、查詢file1以abc結尾的行

# grep abc$ file1

8、列印出file1檔案第1到第三行

# sed -n '1,3p' file1

# head -3 file1

9、清空檔案

# true > 1.txt

# echo "" > 1.txt

# > 1.txt

# cat /dev/null > 1.txt

10、刪除所有空目錄

# find /data -type d -empty -exec rm -rf {} ;

11、linux下批量刪除空檔案(大小等於0的檔案)的方法

# find /data -type f -size 0c -exec rm -rf {} ;

# find /data -type f -size 0c|xargs rm –f

12、刪除五天前的檔案

# find /data -mtime +5 -type f -exec rm -rf {} ;

13、刪除兩個檔案重複的部份,列印其它

# cat 1.txt 3.txt |sort |uniq

14、攻取遠端伺服器主機名

# echo `ssh $ip cat /etc/sysconfig/network|awk -f = '/hostname/ '`

15、實時監控網絡卡流量(安裝iftop)

# /usr/local/iftop/sbin/iftop -i eth1 -n

16、檢視系統版本

# lsb_release -a

17、強制踢出登陸使用者

# pkill -kill -t pts/1

18、tar增理備份、還原

# tar -g king -zcvf kerry_full.tar.gz kerry

# tar -g king -zcvf kerry_diff_1.tar.gz kerry

# tar -g king -zcvf kerry_diff_2.tar.gz kerry

# tar -zxvf kerry_full.tar.gz

# tar -zxvf kerry_diff_1.tar.gz

# tar -zxvf kerry_diff_2.tar.gz

19、將本地80埠的請求**到8080埠,當前主機外網ip為202.96.85.46

-a prerouting -d 202.96.85.46 -p tcp -m tcp --dport 80 -j dnat --to-destination 192.168.9.10:8080

20、在11月份內,每天的早上6點到12點中,每隔2小時執行一次/usr/bin/httpd.sh

21、檢視占用埠8080的程序

# netstat -tnlp | grep 8080

lsof -i:8080

22、在shell環境下,如何檢視遠端linux系統執行了多少時間?

# ssh user@被監控主機ip "uptime"

23、檢視cpu使用情況的命令

每5秒重新整理一次,最右側有cpu的佔用率的資料

# vmstat 5

top 然後按shift+p,按照程序處理器佔用率排序

# top

24、檢視記憶體使用情況的命令

用free命令檢視記憶體使用情況

# free -m

top 然後按shift+m, 按照程序記憶體佔用率排序

# top

25、檢視磁碟i/o

用iostat檢視磁碟/dev/sdc3的磁碟i/o情況,每兩秒重新整理一次

# iostat -d -x /dev/sdc3 2

26、修復檔案系統

# fsck –yt ext3 /

-t 指定檔案系統

-y 對發現的問題自動回答yes

27、read命令5秒後自動退出

# read -t 5

28、grep -e -p 是什麼意思

-e, --extended-regexp 採用擴充套件正規表示式。

-p,--perl-regexp 採用perl正規表示式

29、vi編輯器(涉及到修改,新增,查詢)

插入(insert)模式

i     游標前插入

i     游標行首插入

a     游標後插入

a     游標行尾插入

o     游標所在行下插入一行,行首插入

o     游標所在行上插入一行,行首插入

g     移至最後一行行首

ng    移至第n行行首

n+    下移n行,行首

n-    上移n行,行首

:/str/          從當前往右移動到有str的地方

:?str?          從當前往左移動到有str的地方

:s/str1/str2/       將找到的第乙個str1替換為str2  

:s/str2/str2/g      將當前行找到的所有str1替換為str2

:n1,n2s/str1/str2/g    將從n1行至n2行找到的所有的str1替換為str2

:1,.s/str1/str2/g     將從第1行至當前行的所有str1替換為str2

:.,$s/str1/str2/g     將從當前行至最後一行的所有str1替換為str2

30、linux伺服器之間相互複製檔案

copy 本地檔案1.sh到遠端192.168.9.10伺服器的/data/目錄下

# scp /etc/1.sh [email protected]:/data/ 

copy遠端192.168.9.10伺服器/data/2.s**件到本地/data/目錄

# scp [email protected]:/data/2.sh /data/

31、使用sed命令把test.txt檔案的第23行的test換成tset.

# sed -i '23s/test/tset/' test.txt

# sed -i '23 s/test/tset/' test.txt

32、使history命令能顯示時間

# export histtimeformat="%f %t "

33、如何檢視目標主機192.168.0.1開放那些埠

# nmap -ps 192.168.0.1

34、如何檢視網路連線

# netstat -n | awk '/^tcp/ end '

35、如何檢視當前系統使用了那些庫檔案

# ldconfig -v

36、如何檢視網絡卡的驅動版本

# ethtool -i eth0

37、使用tcpdump來監視主機192.168.0.1的tcp的80埠

# tcpdump tcp port 80 host 192.168.0.1

38、 如何看其它使用者的郵件列表

# mial -u king

39、對大檔案進行切割

按每個檔案1000行來分割

按照每個檔案5m來分割

40、合併檔案

取出兩個檔案的並集(重複的行只保留乙份)

# cat file1 file2 | sort | uniq

取出兩個檔案的交集(只留下同時存在於兩個檔案中的檔案)

# cat file1 file2 | sort | uniq -d

刪除交集,留下其他的行

# cat file1 file2 | sort | uniq –u

41、列印文字模式下執行的服務

# chkconfig --list|awk '$5~/on/'

42、刪除0位元組檔案

# find -type f -size 0 -exec rm -rf {} ;

43、檢視程序,按記憶體從大到小排列

# ps -e -o "%c : %p : %z : %a"|sort -k5 -nr

44、檢視http的併發請求數及其tcp連線狀態

# netstat -n | awk '/^tcp/ end '

45、獲取ip位址

運維linux命令

原文 感謝博主的文章!之前做過兩年的運維,用過很多命令,深切體會到某些linux命令熟練掌握後對效率提公升有多大。舉個簡單的例子,在做了研發後經常會有跑一些資料,對於結果資料的處理,我們的產品同學一般都習慣於用excel做統計,把資料複製到excel裡,然後資料分列,排序 最後得出某些簡單的結論,我...

Linux運維命令

12 date date u date y m d h m s 格式化 date f date s 時間戳 date d 時間戳 格式 例 date d 1510111518 y m d h m s clock 當前的硬體時間檢視 clock s 把硬體的時間讀出來覆蓋到系統時間 clock w 把...

linux運維命令

1 linux啟動過程 開啟電源 bios開機自檢 引導程式lilo或grub 核心的引導 kernel boot 執行init rc.sysinit rc mingetty 建立終端 shell top 然後按shift p,按照程序處理器佔用率排序 top 24 檢視記憶體使用情況的命令 用fr...