摘要
開發者必備Linux常用命令,掌握這些命令絕對夠了,基於CenterOS7.6。
系統服務管理
systemctl
- 輸出系統中各個服務的狀態:
systemctl list-units --type=service
複製程式碼

- 檢視服務的執行狀態:
systemctl status firewalld
複製程式碼

- 關閉服務:
systemctl stop firewalld
複製程式碼

- 啟動服務:
systemctl start firewalld
複製程式碼

- 重新啟動服務(不管當前服務是啟動還是關閉):
systemctl restart firewalld
複製程式碼
- 重新載入配置資訊而不中斷服務:
systemctl reload firewalld
複製程式碼
- 禁止服務開機自啟動:
systemctl disable firewalld
複製程式碼

- 設定服務開機自啟動:
systemctl enable firewalld
複製程式碼

檔案管理
ls
列出當前目錄(/)下的所有檔案:
ls -l /
複製程式碼

pwd
獲取目前所在工作目錄的絕對路徑

cd
改變當前工作目錄:
cd /usr/local
複製程式碼

date
顯示或修改系統時間與日期;
date '+%Y-%m-%d %H:%M:%S'
複製程式碼

passwd
用於設定使用者密碼:
passwd root
複製程式碼

su
改變使用者身份(切換到超級使用者):
su -
複製程式碼
clear
用於清除螢幕資訊
man
顯示指定命令的幫助資訊:
man ls
複製程式碼
who
- 查詢系統處於什麼執行級別:
who -r
複製程式碼

- 顯示目前登入到系統的使用者:
who -buT
複製程式碼

free
顯示系統記憶體狀態(單位MB):
free -m
複製程式碼

ps
顯示系統程式執行動態:
ps -ef
複製程式碼
檢視sshd程式的執行動態:
ps -ef | grep sshd
複製程式碼

top
檢視即時活躍的程式,類似Windows的工作管理員

mkdir
建立目錄

more
用於檔案過長時分頁檢視檔案內容 每頁10行檢視boot.log檔案
more -c -10 /var/log/boot.log
複製程式碼

cat
檢視Linux啟動日誌檔案檔案,並標明行號:
cat -Ab /var/log/boot.log
複製程式碼

touch
建立text.txt檔案:
touch text.txt
複製程式碼

rm
- 刪除檔案:
rm text.txt
複製程式碼
- 強制刪除某個目錄及其子目錄:
rm -rf testdir/
複製程式碼

cp
將test1目錄複製到test2目錄
cp -r /mydata/tes1 /mydata/test2
複製程式碼
mv
移動或覆蓋檔案:
mv text.txt text2.txt
複製程式碼
壓縮與解壓
tar
- 將/etc資料夾中的檔案歸檔到檔案etc.tar(並不會進行壓縮):
tar -cvf /mydata/etc.tar /etc
複製程式碼
- 用gzip壓縮資料夾/etc中的檔案到檔案etc.tar.gz:
tar -zcvf /mydata/etc.tar.gz /etc
複製程式碼
- 用bzip2壓縮資料夾/etc到檔案/etc.tar.bz2:
tar -jcvf /mydata/etc.tar.bz2 /etc
複製程式碼

- 分頁檢視壓縮包中內容(gzip):
tar -ztvf /mydata/etc.tar.gz |more -c -10
複製程式碼

- 解壓檔案到當前目錄(gzip):
tar -zxvf /mydata/etc.tar.gz
複製程式碼
磁碟和網路管理
df
檢視磁碟空間佔用情況:
df -hT
複製程式碼

dh
檢視當前目錄下的檔案及資料夾所佔大小:
du -h --max-depth=1 ./*
複製程式碼

ifconfig
顯示當前網路介面狀態

netstat
- 檢視當前路由資訊:
netstat -rn
複製程式碼

- 檢視所有有效TCP連線:
netstat -an
複製程式碼
- 檢視系統中啟動的監聽服務:
netstat -tulnp
複製程式碼

- 檢視處於連線狀態的系統資源資訊:
netstat -atunp
複製程式碼
wget
從網路上下載檔案

軟體的安裝與管理
rpm
- 安裝軟體包:rpm -ivh nginx-1.12.2-2.el7.x86_64.rpm
- 模糊搜尋軟體包:rpm -qa | grep nginx
- 精確查詢軟體包:rpm -qa nginx
- 查詢軟體包的安裝路徑:rpm -ql nginx-1.12.2-2.el7.x86_64
- 檢視軟體包的概要資訊:rpm -qi nginx-1.12.2-2.el7.x86_64
- 驗證軟體包內容和安裝檔案是否一致:rpm -V nginx-1.12.2-2.el7.x86_64
- 更新軟體包:rpm -Uvh nginx-1.12.2-2.el7.x86_64
- 刪除軟體包:rpm -e nginx-1.12.2-2.el7.x86_64
yum
- 安裝軟體包: yum install nginx
- 檢查可以更新的軟體包:yum check-update
- 更新指定的軟體包:yum update nginx
- 在資源庫中查詢軟體包資訊:yum info nginx*
- 列出已經安裝的所有軟體包:yum info installed
- 列出軟體包名稱:yum list nginx*
- 模糊搜尋軟體包:yum search nginx
公眾號
mall專案全套學習教程連載中,關注公眾號第一時間獲取。
