debian常用命令整理


寫在文章頭的注意事項

  一, -y   自動執行安裝

  二,  package   包名/軟件名,以下命令中凡是出現package需要自行替換。

  三,  apt-get   無效時可更換為   apt   反之同理。

  四,某些情況下可以不用輸入   sudo   

1.更新源

sudo apt-get update -y

2.更新已安裝的包 

sudo apt-get upgrade -y

3.升級系統

sudo apt-get dist-upgrade -y

4.使用 dselect 升級

sudo apt-get dselect-upgrade -y

5.了解使用依賴

sudo apt-cache depends package

6.查看該包被哪些包依賴

sudo apt-cache rdepends package

7.安裝相關的編譯環境

sudo apt-get build-dep package

8.下載該包的源代碼

sudo apt-get source package

9.清理無用的包

sudo apt-get clean && sudo apt-get autoclean

10.檢查是否有損壞的依賴

sudo apt-get check

11.清理所有軟件緩存(即緩存在/var/cache/apt/archives目錄里的deb包)

sudo apt-get clean

12.搜索包

sudo apt-cache search package

13.獲取包的相關信息,如說明、大小、版本等

sudo apt-cache show package

14.安裝包

sudo apt-get install package

15.重新安裝包

sudo apt-get install package - - reinstall

16.修復安裝”-f = –fix-missing”

sudo apt-get -f install

17.刪除包

sudo apt-get remove package

18.刪除包,包括刪除配置文件等

sudo apt-get remove package - - purge

19.安裝wget下載工具

sudo apt-get install wget -y

20.安裝git

sudo apt-get install git -y

21.安裝curl

sudo apt-get install curl -y

22.安裝Nginx

apt-get install nginx

#輸入以下命令查看是否可以正常訪問, 順便驗證下安裝是否成功.
curl -I 127.0.0.1

#若輸出類似如下內容, 那么說明安裝沒問題咯.
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Sat, 14 Mar 2020 05:36:45 GMT
Content-Type: text/html
Content-Length: 612 Last-Modified: Sat, 14 Mar 2020 05:36:27 GMT
Connection: keep-alive
ETag: "5e6c6d5b-264"
Accept-Ranges: bytes

  Nginx綁定域名

  22.1配置文件/etc/nginx/conf.d/**.conf

  22.2為每一個域名建立一個單獨的配置文件時輸入以下內容:

server
{
    listen   80;                            #監聽端口設為 80。
    server_name  blog.tgae.xyz;         #綁定您的域名。
    index index.htm index.html index.php;   #指定默認文件。
    root /var/www/html/hlzspace;           #指定網站根目錄。
    include location.conf;                  #當您需要調用其他配置文件時才粘貼此項,如無需要,請刪除此項。
}

  22.3將多個域名規則寫進一個共同的配置文件時輸入以下內容:

server
{
    listen   80;                            #監聽端口設為 80。
    server_name  blog.tgae.xyz;         #綁定您的域名。
    index index.htm index.html index.php;   #指定默認文件。
    root /var/www/html/hlzspace;           #指定網站根目錄。
    include location.conf;                  #當您需要調用其他配置文件時才粘貼此項,如無需要,請刪除此項。
}
server
{
    listen   80;                            #監聽端口設為 80。
    server_name  blog.tgae.xyz;         #綁定您的域名。
    index index.htm index.html index.php;   #指定默認文件。
    root /var/www/html/hlz2space;           #指定網站根目錄。
    include location.conf;                  #當您需要調用其他配置文件時才粘貼此項,如無需要,請刪除此項。
}

  22.4為無 WWW 前綴的域名配置規則並加 301 跳轉時輸入以下內容:

server
{
    listen 80;
    server_name tgae.xyz;
    rewrite ^/(.*) http://www.tgae.xyz/$1 permanent;
}

  22.5需要為域名添加 404 提示時輸入以下內容:

server
{
    listen   80;                            #監聽端口設為 80。
    server_name  blog.tgae.xyz;         #綁定您的域名。
    index index.htm index.html index.php;   #指定默認文件。
    root /var/www/html/hlzspace;           #指定網站根目錄。
    include location.conf;                  #當您需要調用其他配置文件時才粘貼此項,如無需要,請刪除此項。
    error_page 404              #/404.html;
}

  22.6重啟nginx

$ service nginx  restart

23.安裝screen

sudo apt-get install screen -y
#使用方法,使用時注意(space)空格
screen -S 創建新窗口例:screen -S lnmp
screen -ls 列出所有窗口,直接輸入。
screen -r 恢復窗口例:screen -r lnmp 或者是 通過-ls命令獲取的窗口前數字列:screen -r 1234

#There is no screen to be resumed matching
#解決方法:
screen -D -r 18352
#解釋:-D -r 先刪除前一用戶再登陸。

24.安裝Firewalld 

sudo apt-get install firewalld -y
#使用方法
  1.查看所有開放的端口 (服務器已開放的端口)
    firewall-cmd --zone=public --list-ports
    firewall-cmd --list-ports
  2.查詢是否開啟80端口
    firewall-cmd --query-port=80/tcp
  3.開放端口
    3.1臨時放行,服務器重啟后失效
      firewall-cmd --zone=public --add-port=80/tcp
    3.2在public中放行,永久生效,服務器重啟后不會失效
      firewall-cmd --zone=public --add-port=80/tcp --permanent
    3.3永久 放行連續的端口 1000-2000
      firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent
    3.4永久放行不連續的端口 9000,9001
      firewall-cmd --zone=public --add-port=9000/tcp --add-port=9001/tcp --permanent
  4.刪除端口
    4.1臨時刪除,服務器重啟后自動添加
      firewall-cmd --zone=public --remove-port=80/tcp
    4.2在public中刪除,永久生效,服務器重啟后不會自動添加
      firewall-cmd --zone=public --remove-port=80/tcp --permanent
    4.3永久刪除 連續的端口(1000-2000
      firewall-cmd --zone=public --remove-port=1000-2000/tcp --permanent
    4.4永久刪除不連續的端口(9000,9001
      firewall-cmd --zone=public --remove-port=9000/tcp --remove-port=9001/tcp --permanent
  5.禁Ping設置規則
    5.1臨時 禁Ping規則
      firewall-cmd --add-rich-rule='rule protocol value=icmp drop'
    5.2永久 禁Ping規則
      firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop'
    5.3臨時 刪除禁Ping規則
      firewall-cmd --remove-rich-rule='rule protocol value=icmp drop'
    5.4永久 刪除禁Ping規則
      firewall-cmd --permanent --remove-rich-rule='rule protocol value=icmp drop'
  6.http與https通訊
    6.1永久開放http
      firewall-cmd --permanent --add-service=http
    6.2永久允許http通信
      firewall-cmd --permanent --zone=public --add-service=http
    6.3永久允許https通信
      firewall-cmd --permanent --zone=public --add-service=https

  更新防火牆規則:firewall-cmd --reload

  重啟: systemctl restart firewalld

  啟動: systemctl start firewalld

  狀態: systemctl status firewalld

  停止: systemctl disable firewalld

  禁用: systemctl stop firewalld

  開機啟動:systemctl enable firewalld.service

  開機禁用:systemctl disable firewalld.service

  查看版本: firewall-cmd --version

  查看幫助: firewall-cmd --help

  顯示狀態: firewall-cmd --state

  查看所有打開的端口: firewall-cmd --zone=public --list-ports

  查看區域信息: firewall-cmd --get-active-zones

  查看指定接口所屬區域: firewall-cmd --get-zone-of-interface=eth0

  拒絕所有包:firewall-cmd --panic-on

  取消拒絕狀態: firewall-cmd --panic-off

  查看是否拒絕: firewall-cmd --query-panic

  重新加載配置 (不管是添加或是刪除端口都需要重新加載配置並重啟firewall)

 25.安裝unzip

apt-get install unzip

#把文件解壓到當前目錄下
unzip file.zip

#把文件解壓到指定的目錄下,需要用到-d參數
unzip -d ./tmp/ file.zip

#解壓的時候,有時候不想覆蓋已經存在的文件,那么可以加上-n參數
unzip -n file.zip
unzip -n -d ./tmp/ file.zip

#只看一下zip壓縮包中包含哪些文件,不進行解壓縮
unzip -l file.zip

#查看顯示的文件列表還包含壓縮比率
unzip -v file.zip

#檢查zip文件是否損壞
unzip -t file.zip

#將壓縮文件file.zip在指定目錄tmp下解壓縮,如果已有相同的文件存在,要求unzip命令覆蓋原先的文件
unzip -o file.zip -d ./tmp

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM