Linux常用命令
系統(tǒng)服務(wù)管理
systemctl
- 啟動服務(wù):systemctl start httpd.service
- 關(guān)閉服務(wù):systemctl stop httpd.service
- 重啟服務(wù)(不管是否在運行):systemctl restart httpd.service
- 重新載入配置(不中斷服務(wù)):systemctl reload httpd.service
- 查看運行狀態(tài):systemctl status httpd.service
- 設(shè)置開機啟動:systemctl enable httpd.service
- 禁止開機啟動:systemctl disable httpd.service
- 查看系統(tǒng)安裝的服務(wù):systemctl list-units --type=service
文件管理
ls
列出/home目錄下的子目錄:ls -l /home
列出當前文件夾下所有文件夾及文件大邢厍病:ls -lht
pwd
顯示當前工作目錄
cd
切換目錄: cd /usr/local
date
以指定格式顯示日期顽素;date '+date:%x time:%X'
passwd
修改root密碼:passwd root
su
普通用戶切換到超級用戶:su -
clear
清除屏幕信息
man
查看ls命令的幫助信息:man ls
who
- 查看當前運行級別:who -r
- 顯示用的登錄詳情:who -buT
free
以MB顯示內(nèi)存使用狀態(tài):free -m
ps
查看系統(tǒng)所有進程:ps -ef
查看運行的java進程: ps -ef | grep java
top
查看系統(tǒng)當前活躍進程信息
mkdir
創(chuàng)建目錄
more
分頁查看
每10行顯示一屏查看:more -c -10
cat
查看config文件:cat -Ab config
rm
- 刪除文件:rm a.txt
- 刪除文件夾: rm -rf a/
touch
創(chuàng)建一個文件:touch a.txt
cp
將目錄a的文件拷貝到目錄b: cp -r /home/a /home/b
mv
移動或覆蓋文件:mv a.txt b.txt
壓縮與解壓
tar
- 打包文件夾到單獨的文件:tar -cvf /opt/etc.tar /etc
- 壓縮文件夾到壓縮文件(gzip):tar -zcvf /opt/etc.tar.gz /etc
- 壓縮文件夾到壓縮文件(bzip2):tar -jcvf /opt/etc.tar.bz2 /etc
- 查閱壓縮包中內(nèi)容(gzip):tar -ztvf /opt/etc.tar.gz /etc
- 解壓文件到當前目錄(gzip):tar -zxvf /opt/etc.tar.gz
磁盤和網(wǎng)絡(luò)管理
df
查看磁盤占用情況:df -hT
ifconfig
查看當前網(wǎng)絡(luò)接口狀態(tài)
netstat
- 查看路由信息:netstat -rn
- 查看所有有效TCP連接:netstat -an
- 查看系統(tǒng)中啟動的監(jiān)聽服務(wù):netstat -tulnp
- 查看處于連接狀態(tài)的系統(tǒng)資源信息:netstat -atunp
wget
從網(wǎng)絡(luò)上下載軟件
軟件的安裝與管理
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
- 驗證軟件包內(nèi)容和安裝文件是否一致: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*
- 列出已經(jīng)安裝的所有軟件包:yum info installed
- 列出軟件包名稱:yum list redis*
- 模糊搜索軟件包:yum search redis
網(wǎng)絡(luò)安全
iptables
- 開啟防火墻:systemctl start iptables.service
- 關(guān)閉防火墻:systemctl stop iptables.service
- 查看防火墻狀態(tài):systemctl status iptables.service
- 設(shè)置開機啟動:systemctl enable iptables.service
- 禁用開機啟動:systemctl disable iptables.service
- 查看filter表的鏈信息:iptables -L -n
- 查看NAT表的鏈信息:iptables -t nat -L -n
- 清除防火墻所有規(guī)則:iptables -F;iptables -X;iptables -Z;
- 添加過濾規(guī)則(開發(fā)80端口):iptables -I INPUT -p tcp --dport 80 -j ACCEPT
- 查找規(guī)則所做行號:iptables -L INPUT --line-numbers -n
- 根據(jù)行號刪除過濾規(guī)則:iptables -D INPUT 1