Linux 伺服器維護相關常用命令總結

來源:互聯網
上載者:User

文章總結了大概有20條關於Linux 伺服器維護相關常用命令,有需要的朋友可參考一下本文章。

vi 刪除空行

:g/^s*$/d

尋找目錄中的檔案中所含有指定字串的檔案

find ./ -name '*.conf' | xargs grep -in "baidu.com.demo.upall.cn"
# 註:“baidu.com.demo.upall.cn” 是要尋找的字串
# 這個命令用於在大批的設定檔中快速定位到某網域名稱的設定檔名稱,因為:
# 因特殊原因導致該使用者的設定檔名不符合規則或一個設定檔中有多個不相似的網域名稱
#   i:不區分大小寫
#   n:顯示所在行號


查看單個檔案(或檔案夾)大小

 du -sh /var/log/

查看檔案夾中各檔案夾、檔案的大小(區分哪個檔案夾最大)

du -h --max-depth=1 /var/log/

刪除源碼中的^M
 :%s/^M$//g #注意:^M的輸入方式,Ctrl+V+M

批量去除include及其下檔案的寫入權限

find /var/www -type d -name "include" -print0 | xargs -0 chmod ugo-w -R # 去除執行許可權可以看這篇文章:
尋找當前檔案夾中包含字串“fsockopen”的所有檔案

其實尋找“udp://$”的話會精準一些,當然也要看實際情況,^_^。

 代碼如下 複製代碼

1find ./ -type f | xargs grep -sni "fsockopen"
# 或者(下邊這行協助理解“-sni”參數)
find ./ -type f | xargs grep --silent --line-number --ignore-case "fsockopen"
# 如果找出的檔案全部可以刪除的話,可以用下邊這條命令來刪除:
find ./ -type f | xargs grep -lsi "fsockopen" | xargs rm


查看網域名稱的MX記錄是否生效

[upall@linux ~]$ host -t mx upall.cn upall.cn mail is handled by 10 mx.upall.cn.

列出所有網站檔案夾中 zip 的檔案,並顯示其大小

經常會在伺服器上下載一些源碼包或者打包一些備份檔案之後忘記刪除,這個命令可以找出它們。

find /www/ -type f -name "*.zip" -print0 | xargs -0 du -h

刪除使用者及其檔案(刪除使用者登入目錄以及目錄中所有檔案)

 userdel -r upall

查看指定連接埠啟動並執行程式

# 查看3428連接埠啟動並執行程式: lsof -i :3428

修改 /etc/aliases 後更新 /etc/aliases.db 資料庫

newaliases

禁用停用鎖定使用者、恢複啟用使用者

passwd -l upall #禁用使用者upall passwd -u upall #啟用使用者upall

清除UTF-8中的BOM頭

grep -r $'xEFxBBxBF' * |grep .php #或者直接配置vim:set nobomb

查看記憶體使用量情況,命令:free

 

 代碼如下 複製代碼
[root@vm ~]# free
total used free shared buffers cached
Mem: 514860 481808 33052 0 107536 134892
-/+ buffers/cache: 239380 275480
Swap: 1048568 80 1048488
[code]

free命令將顯示相關的記憶體使用量情況,注意:對於獨立伺服器或者XEN/KVM架構的虛擬機器,free命令顯示的free那一列並非真實的剩餘記憶體,為什嗎?見:free命令記憶體顯示指南

3、查看磁碟分割使用方式:fdisk與df

 代碼如下 複製代碼

[code]
[root@www ~]# fdisk -l
Disk /dev/hda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        1958    15623212+  8e  Linux LVM


查看各個分區的使用:df -hl

 代碼如下 複製代碼


[root@www ~]# df -hl
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
14G  2.9G  9.9G  23% /
/dev/hda1              99M   19M   76M  20% /boot
tmpfs                 252M     0  252M   0%  /dev/shm


4、查看系統負載與健全狀態:uptime

 代碼如下 複製代碼


[root@www ~]# uptime

13:36:09 up 2 days, 16:09, 1 user, load average: 0.03, 0.02, 0.00


示系統啟動的時間,後面的load average三個數分別表示最近1分鐘、5分鐘、15分鐘的系統平均負載。
一般來說,一個CPU核心的滿負載數值為1,有幾個核心,滿負載狀態就為幾。如果Load超出這個數,說明系統中有等待處理的排隊請求。實際使用中,一般不要讓Load大於CPU總核心數×2,否則系統效率將大打折扣。
5、查看目前使用者/查看當前路徑/查看目前時間/列印所有進程列表

 

 代碼如下 複製代碼

[root@www local]# who

root pts/0 2012-01-14 13:35 (58.47.62.202)
[root@www local]# whoami
root
[root@www local]# pwd
/usr/local
[root@www local]# date
Sat Jan 14 13:44:39 CST 2012
[root@www local]# ps -aux
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 2160 648 ? Ss Jan11 0:01 init [3]
root 2 0.0 0.0 0 0 ? S< Jan11 0:00 [migration/0]
root 3 0.0 0.0 0 0 ? SN Jan11 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S< Jan11 0:00 [watchdog/0]
root 5 0.0 0.0 0 0 ? S< Jan11 0:00 [migration/1]
...

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.