Linux常用命令記錄
阿新 • • 發佈:2019-01-08
apache===================== 1. 啟動apache /opt/sudytech/apache2/bin/apachectl start apache 2. 重啟apache /opt/sudytech/apache2/bin/apachectl restart 3. 停止apache /opt/sudytech/apache2/bin/apachectl stop 0如果Apache已經安裝成Linux服務0 1. 啟動apache service httpd start 2. 重啟apache service httpd restart 3. 停止apache service httpd stop tar======================== 1. 將檔案解壓到指定目錄(指定的解壓目錄結尾可以沒有"/") tar -zxvf WebplusPro.tar.gz -C /opt/sudytech/apache-tomcat/webapps/ 2. 將檔案壓縮到指定目錄(壓縮的目標檔案如果用絕對路徑/opt/sudytech/WebplusPro的形式,壓縮檔案會帶有opt,sudytech的目錄) tar -zcvf /opt/sudytech/WebplusPro.tar.gz WebplusPro 3. 打包檔案,排除指定資料夾(排除_upload,在upload後面不能加"/") tar -zcvf ROOT20170510.tar.gz --exclude=ROOT/_upload ROOT zip======================== 1. 壓縮並指定目錄(壓縮的目標檔案如果用絕對路徑/opt/test/_web的形式,壓縮檔案會帶有opt,test的目錄) zip -r /opt/test/a.zip /opt/test/_web 2. 解壓並指定目錄 unzip /opt/test/a.zip -d /opt/test/ unzip /opt/test/a.zip //如果解壓在當前目錄,直接使用unzip MySQL====================== 1. 檢視MySQL是否啟動 ps aux|grep mysqld 2. 執行MySQL的sql指令碼(匯入) /opt/sudytech/mysql/bin/mysql -uroot -p12344 webplus3_v1_4_7_5 < /opt/webplus3_v1_4_7_5.sql; use database; source /opt/sudytech/aaa.sql; 3. 匯出資料庫到指令碼(匯出) /opt/sudytech/mysql/binmysqldump -uroot -p12344 dabaseName > fileName.sql /opt/sudytech/mysql/binmysqldump -uroot -p12344 dabaseName tableName > fileName.sql (1匯出某個表的資料1) 4. 查看錶結構 desc T_MO_APPSTRATEGY; 5. 清空表資料 truncate table t_mo_microapp;//刪除表資料,釋放空間,不刪除定義 delete from t_mo_microapp;//刪除表資料,不釋放空間,不刪除定義 drop table t_mo_microapp;//刪除表資料,釋放空間,刪除定義 6. 授權語句 GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.18.10.122' IDENTIFIED BY '12344' WITH GRANT OPTION; iptables==================== 1. 檢視防火牆狀態 service iptables status 2. 關閉防火牆 service iptables stop 3. 啟動防火牆 service iptables start 4. 從防火牆開放80埠 /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /etc/rc.d/init.d/iptables save /etc/rc.d/init.d/iptables restart 5. centos7 開伺服器防火牆埠 firewall-cmd --add -port=80/tcp --permanent firewall-cmd --reload firewall-cmd --query-port=80/tcp 6. centos7 關閉防火牆 systemctl stop firewalld.service //停止 systemctl disable firewalld.service //禁用 wget======================= 1. (內網)伺服器下載檔案(以a.zip命名,下載到當前目錄) wget -o a.zip http://170.18.10.46:4690/opt/sudytech/redis-2.8.17.tar.gz scp======================== 1. (內網)從伺服器 59.76.83.72 拷貝檔案到當前伺服器的目錄(root是另一臺伺服器使用者,會提示輸入另一臺伺服器的密碼) scp
[email protected]:/opt/sudytech/apache-tomcat-6.0.35/webapps/ROOT20170621.tar.gz /opt/sudytech/apache-tomcat-6.0.35/webapps/ 2. 從本地伺服器拷貝到遠端伺服器 scp /opt/sudytech/apache-tomcat-6.0.35/webapps/ [email protected]:/opt/sudytech/apache-tomcat-6.0.35/webapps/ROOT20170621.tar.gz mount====================== 1. 伺服器掛載,2臺伺服器連結同一個資料庫,當前伺服器執行語句,圖片資源從另一臺伺服器獲得 mount -o rw 59.76.83.72:/opt/sudytech/apache-tomcat-6.0.35/webapps/ROOT/_upload /opt/sudytech/apache-tomcat-6.0.35/webapps/ROOT/_upload netstat==================== 1. 檢視端口占用情況 netstat -apn|grep 8080 telnet===================== 1. 檢視埠是否可以訪問 telnet www.baidu.com 80 | telnet 127.0.0.1 8080 date======================= 1. date -s "2017-05-26 13:27:50" 修改完後要 "clock -w" 命令,否則重啟後會還原 vi========================= 1. vi /usr/local/file.js 2. 使用a,A,o,O,i,I進入編輯模式 3. 編輯完成,按esc返回命令模式 4. 命令模式下,(以下常用) :w 儲存不退出vi :q 退出vi :w! 強制儲存 :q! 強制退出vi,當文字改變,卻不想儲存 :wq 儲存並退出 touch======================= 1. 建立一個file.js檔案 touch /usr/local/file.js df========================== 1. 檢視磁碟記憶體 df -hl chmod======================= 1. 給/opt/sudytech/WebplusPro的資料夾賦許可權,-R遞迴子資料夾 chmod -R 777 /opt/sudytech/WebplusPro 2. 給當前目錄下的.sh檔案的所有者增加可執行許可權(在tomcat啟動時,執行startup.sh遇到沒有許可權的情況,進入bin目錄,執行語句) chmod u+x *.sh (u代表所有者,x代表執行許可權。 + 表示增加許可權) tail======================== 語法:tail [ -f ] [ -c Number | -n Number | -m Number | -b Number | -k Number ] [ File ] 1. 檢視檔案webplus.log的最後100行 tail -n 100 webplus.log