【最新】 Linux常用命令

Linux常用命令

系統(tǒng)服務(wù)管理

systemctl

  • 啟動(dòng)服務(wù):systemctl start httpd.service
  • 關(guān)閉服務(wù):systemctl stop httpd.service
  • 重啟服務(wù)(不管是否在運(yùn)行):systemctl restart httpd.service
  • 重新載入配置(不中斷服務(wù)):systemctl reload httpd.service
  • 查看運(yùn)行狀態(tài):systemctl status httpd.service
  • 設(shè)置開(kāi)機(jī)啟動(dòng):systemctl enable httpd.service
  • 禁止開(kāi)機(jī)啟動(dòng):systemctl disable httpd.service
  • 查看系統(tǒng)安裝的服務(wù):systemctl list-units --type=service

文件管理

ls

列出/home目錄下的子目錄:ls -l /home
列出當(dāng)前文件夾下所有文件夾及文件大小:ls -lht

pwd

顯示當(dāng)前工作目錄

cd

切換目錄: cd /usr/local

date

以指定格式顯示日期;date '+date:%x time:%X'

passwd

修改root密碼:passwd root

su

普通用戶切換到超級(jí)用戶:su -

clear

清除屏幕信息

man

查看ls命令的幫助信息:man ls

who

  • 查看當(dāng)前運(yùn)行級(jí)別:who -r
  • 顯示用的登錄詳情:who -buT

free

以MB顯示內(nèi)存使用狀態(tài):free -m

ps

查看系統(tǒng)所有進(jìn)程:ps -ef
查看運(yùn)行的java進(jìn)程: ps -ef | grep java

top

查看系統(tǒng)當(dāng)前活躍進(jìn)程信息

mkdir

創(chuàng)建目錄

more

分頁(yè)查看
每10行顯示一屏查看:more -c -10

cat

查看config文件:cat -Ab config

rm

  • 刪除文件:rm a.txt
  • 刪除文件夾: rm -rf a/

touch

創(chuàng)建一個(gè)文件:touch a.txt

cp

將目錄a的文件拷貝到目錄b: cp -r /home/a /home/b

mv

移動(dòng)或覆蓋文件:mv a.txt b.txt

壓縮與解壓

tar

  • 打包文件夾到單獨(dú)的文件: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
  • 解壓文件到當(dāng)前目錄(gzip):tar -zxvf /opt/etc.tar.gz

磁盤和網(wǎng)絡(luò)管理

df

查看磁盤占用情況:df -hT

ifconfig

查看當(dāng)前網(wǎng)絡(luò)接口狀態(tài)

netstat

  • 查看路由信息:netstat -rn
  • 查看所有有效TCP連接:netstat -an
  • 查看系統(tǒng)中啟動(dòng)的監(jiān)聽(tīng)服務(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
  • 驗(yàn)證軟件包內(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
  • 在資源庫(kù)中查找軟件包信息:yum info nginx*
  • 列出已經(jīng)安裝的所有軟件包:yum info installed
  • 列出軟件包名稱:yum list redis*
  • 模糊搜索軟件包:yum search redis

網(wǎng)絡(luò)安全

iptables

  • 開(kāi)啟防火墻:systemctl start iptables.service
  • 關(guān)閉防火墻:systemctl stop iptables.service
  • 查看防火墻狀態(tài):systemctl status iptables.service
  • 設(shè)置開(kāi)機(jī)啟動(dòng):systemctl enable iptables.service
  • 禁用開(kāi)機(jī)啟動(dòng):systemctl disable iptables.service
  • 查看filter表的鏈信息:iptables -L -n
  • 查看NAT表的鏈信息:iptables -t nat -L -n
  • 清除防火墻所有規(guī)則:iptables -F;iptables -X;iptables -Z;
  • 添加過(guò)濾規(guī)則(開(kāi)發(fā)80端口):iptables -I INPUT -p tcp --dport 80 -j ACCEPT
  • 查找規(guī)則所做行號(hào):iptables -L INPUT --line-numbers -n
  • 根據(jù)行號(hào)刪除過(guò)濾規(guī)則:iptables -D INPUT 1
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容