Linux經常使用命令快查

1、讀取配置文件中某一個變量的值java

假若有一個配置文件dubbo.properties,須要讀取dubbo.application.name的值:mysql

dubbo.application.name=booking-api-consumer
dubbo.application.owner=yhouse
dubbo.reference.group=test
dubbo.registry.address=zookeeper://yhouse-zookeeper-1:2189?backup=yhouse-zookeeper-2:2189,yhouse-zookeeper-3:2189

有如下幾種方式:linux

1)  sed  '/dubbo.application.name/!d;s/.*=//'  dubbo.properties ios

2)  sed '/dubbo.reference.group/!d' dubbo.properties | sed 's/.*=//' web

3)  grep 'dubbo.reference' dubbo.properties | sed 's/.*=//'spring

控制檯輸出:sql

 

2、查看進程shell

 ps -ef | grep ?   //其中?表示想查找的進程所包含一部分,如服務名稱、pid等等apache

如查看tomcat進程  json

root@test-api:/ysconfig/booking_api# ps -ef | grep tomcat
root      1752     1  0 Apr17 ?        00:16:40 /usr/lib/jvm/jdk1.8.0_45/bin/java -Djava.util.logging.config.file=/opt/tomcat/tomcat_common/conf/logging.properties -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Xms512m -Xmx512m -XX:MaxPermSize=512m -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.security.egd=file:/./dev/urandom -Djava.endorsed.dirs=/opt/tomcat/tomcat_common/endorsed -classpath /opt/tomcat/tomcat_common/bin/bootstrap.jar:/opt/tomcat/tomcat_common/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat/tomcat_common -Dcatalina.home=/opt/tomcat/tomcat_common -Djava.io.tmpdir=/opt/tomcat/tomcat_common/temp org.apache.catalina.startup.Bootstrap start
root      6232     1  0 Apr14 ?        00:08:26 /usr/lib/jvm/jdk1.8.0_45/bin/java -Djava.util.logging.config.file=/opt/tomcat/tomcat_search/conf/logging.properties -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Xms512m -Xmx512m -XX:MaxPermSize=512m -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.security.egd=file:/./dev/urandom -Djava.endorsed.dirs=/opt/tomcat/tomcat_search/endorsed -classpath /opt/tomcat/tomcat_search/bin/bootstrap.jar:/opt/tomcat/tomcat_search/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat/tomcat_search -Dcatalina.home=/opt/tomcat/tomcat_search -Djava.io.tmpdir=/opt/tomcat/tomcat_search/temp org.apache.catalina.startup.Bootstrap start
root      6646     1  0 Apr19 ?        00:08:47 /usr/lib/jvm/java-8-oracle/bin/java -Djava.util.logging.config.file=/opt/tomcat/tomcat_test/conf/logging.properties -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Xms512m -Xmx512m -XX:MaxPermSize=512m -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.security.egd=file:/./dev/urandom -Djava.endorsed.dirs=/opt/tomcat/tomcat_test/endorsed -classpath /opt/tomcat/tomcat_test/bin/bootstrap.jar:/opt/tomcat/tomcat_test/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat/tomcat_test -Dcatalina.home=/opt/tomcat/tomcat_test -Djava.io.tmpdir=/opt/tomcat/tomcat_test/temp org.apache.catalina.startup.Bootstrap start
root     26205 17889  0 11:42 pts/0    00:00:00 grep --color=auto tomcat

如根據pid查找進程

root@test-api:/ysconfig/booking_api# ps -ef | grep 28917
root     26527 17889  0 11:47 pts/0    00:00:00 grep --color=auto 28917
root     28917 28913  0 Mar24 ?        00:30:32 java -cp /opt/elasticsearch-jdbc-1.7.3.0/bin/../lib/* -Dlog4j.configurationFile=/opt/elasticsearch-jdbc-1.7.3.0/bin/../bin/log4j2.xml org.xbib.tools.Runner org.xbib.tools.JDBCImporter

上面實際上是一個導數據的腳本,但爲何沒有看到是哪一個腳本呢,咱們發現它其實還有個父進程,再查:

root@test-api:/ysconfig/booking_api# ps -ef | grep 28913
root     26525 17889  0 11:47 pts/0    00:00:00 grep --color=auto 28913
root     28913     1  0 Mar24 ?        00:00:00 /bin/sh ./mysql-fullbiz-schedule.sh
root     28917 28913  0 Mar24 ?        00:30:32 java -cp /opt/elasticsearch-jdbc-1.7.3.0/bin/../lib/* -Dlog4j.configurationFile=/opt/elasticsearch-jdbc-1.7.3.0/bin/../bin/log4j2.xml org.xbib.tools.Runner org.xbib.tools.JDBCImporter

這才發現是mysql-fullbiz-schedule.sh這個腳本在運行,這纔是咱們想要的結果,因此若是要查進程鏈,只須要把?替換成父進程就能夠,這樣父進程與子進程都會查出來。

 

3、查看端口

netstat -nap | grep ?   //其中?表示進程號

有時咱們知道一個服務名稱,但不知道它佔用了什麼端口,能夠經過以下命令查找

如查看1752這個進程所佔用的端口:

root@test-api:/ysconfig/booking_api# netstat -nap | grep 1752
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      1752/java       
tcp6       0      0 :::8009                 :::*                    LISTEN      1752/java       
tcp6       0      0 :::8080                 :::*                    LISTEN      1752/java  

這個pid=1752能夠經過上面第二點中提到的命令經過服務名稱查找得出。

 

 4、查看CPU/MEM的使用狀況

top 命令,每3秒滾動一次

root@test-api:/ysconfig/booking_api# top
top - 11:59:28 up 75 days, 19:55,  1 user,  load average: 0.42, 0.33, 0.41
Tasks: 113 total,   2 running, 111 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.2 us,  0.7 sy,  0.0 ni, 98.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   8176956 total,  7052436 used,  1124520 free,   183032 buffers
KiB Swap:   524284 total,   523828 used,      456 free.   516884 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                                                 
22951 root      20   0 4570792 965424   5920 S   2.3 11.8   1152:11 java                                                                                                                                                                    
 6646 root      20   0 3211096 812368  11452 S   0.7  9.9   8:58.97 java                                                                                                                                                                    
 1752 root      20   0 3072464 590736  10192 S   0.3  7.2  16:44.56 java                                                                                                                                                                    
 6232 root      20   0 2984684 482596  10116 S   0.3  5.9   8:27.47 java                                                                                                                                                                    
17862 clonenc+  20   0  152684   2784   1404 S   0.3  0.0   0:00.42 sshd                                                                                                                                                                    
26013 root      20   0 3664424 1.144g  15772 S   0.3 14.7 294:58.64 java                                                                                                                                                                    
28917 root      20   0 4519380 763408   5848 S   0.3  9.3  30:33.16 java                                                                                                                                                                    
    1 root      20   0   28684   4340    396 S   0.0  0.1   0:13.23 init                                                                                                                                                                    
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.02 kthreadd                                                                                                                                                                
    3 root      20   0       0      0      0 S   0.0  0.0   0:32.06 ksoftirqd/0                                                                                                                                                             
    5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H                                                                                                                                                            
    7 root      20   0       0      0      0 S   0.0  0.0  86:02.57 rcu_sched                                                                                                                                                               
    8 root      20   0       0      0      0 R   0.0  0.0  37:32.98 rcuos/0                                                                                                                                                                 
    9 root      20   0       0      0      0 S   0.0  0.0  35:32.30 rcuos/1                                                                                                                                                                 
   10 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcu_bh                                                                                                                                                                  
   11 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/0                                                                                                                                                                 
   12 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/1                                                                                                                                                                 
   13 root      rt   0       0      0      0 S   0.0  0.0   0:39.40 migratio

還有一個單獨查內存佔用的命令:

free 命令

root@test-api:/ysconfig/booking_api# free
             total       used       free     shared    buffers     cached
Mem:       8176956    6981348    1195608        384     143260     486536
-/+ buffers/cache:    6351552    1825404
Swap:       524284     523932        352

從上面看出,總內存 8G,已使用6G多,剩餘1.1G,其實看可用內存,要加上緩衝區的內存,這一部分也是可用的,即:buffers+cached,實際上可用內存=1.8G,即

-/+ buffers/cache: 6351552 1825404

 

5、查看滾動日誌

tail -f filepath    //filepath是文件路徑   

tail -nf  filepath //-n表示結尾行數 

如 tail -f debug.log   

    tail -100f debug.log

    ....

root@test-api:/ysconfig/booking_api# tail -f /opt/logs/hbase.yhouse.com/debug.log 2015-11-30 16:02:11,767 INFO org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:510) - Refreshing WebApplicationContext for namespace 'hbaseServiceSpringMvc-servlet': startup date [Mon Nov 30 16:02:11 CST 2015]; parent: Root WebApplicationContext 2015-11-30 16:02:11,767 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:317) - Loading XML bean definitions from class path resource [configs/springMvc.xml] 2015-11-30 16:02:11,799 INFO org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.<init>(AutowiredAnnotationBeanPostProcessor.java:153) - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 2015-11-30 16:02:11,809 INFO org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:217) - Mapped "{[/dao],methods=[PUT],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public com.yhouse.hbase.common.vos.ResponseData com.yhouse.hbase.controllers.GenericController.updateDaoType() 2015-11-30 16:02:11,810 INFO org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:217) - Mapped "{[/queryRecommendList],methods=[GET],params=[srcContentType && srcContentId],headers=[],consumes=[],produces=[],custom=[]}" onto public com.yhouse.hbase.common.vos.ResponseData com.yhouse.hbase.controllers.RecommendController.queryRecommendList(com.yhouse.hbase.pojos.Recommend,com.yhouse.hbase.vos.BaseParam) 2015-11-30 16:02:11,828 INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache(RequestMappingHandlerAdapter.java:517) - Looking for @ControllerAdvice: WebApplicationContext for namespace 'hbaseServiceSpringMvc-servlet': startup date [Mon Nov 30 16:02:11 CST 2015]; parent: Root WebApplicationContext 2015-11-30 16:02:11,845 INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache(RequestMappingHandlerAdapter.java:517) - Looking for @ControllerAdvice: WebApplicationContext for namespace 'hbaseServiceSpringMvc-servlet': startup date [Mon Nov 30 16:02:11 CST 2015]; parent: Root WebApplicationContext 2015-11-30 16:02:11,895 INFO org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:503) - FrameworkServlet 'hbaseServiceSpringMvc': initialization completed in 132 ms 2015-11-30 16:02:11,939 INFO org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:862) - Closing WebApplicationContext for namespace 'hbaseServiceSpringMvc-servlet': startup date [Mon Nov 30 16:02:11 CST 2015]; parent: Root WebApplicationContext 2015-11-30 16:02:11,962 INFO org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:862) - Closing Root WebApplicationContext: startup date [Mon Nov 30 16:02:08 CST 2015]; root of context hierarchy

 

6、把腳本加入啓動服務

ln 命令

其實就是經過軟鏈的方式加入/etc/init.d下

root@test-api:/ysconfig/booking_api# ln -s /opt/tomcat/tomcat_test/bin/catalina.sh /etc/init.d/testService
root@test-api:/ysconfig/booking_api# 

查看服務

root@test-api:/ysconfig/booking_api# ls /etc/init.d/testService
/etc/init.d/testService
root@test-api:/ysconfig/booking_api# 

能夠經過service  testSerivce start/stop 來啓動與中止服務了。

 

7、開機自啓動腳本

一、方法一,編輯rc.loacl腳本 

Ubuntu開機以後會執行/etc/rc.local文件中的腳本,

因此咱們能夠直接在/etc/rc.local中添加啓動腳本。

固然要添加到語句:exit 0 前面才行。

如:sudo vi /etc/rc.local

而後在 exit 0 前面添加好腳本代碼。

 

二、方法二,添加一個Ubuntu的開機啓動服務。

若是要添加爲開機啓動執行的腳本文件,

可先將腳本複製或者軟鏈接到/etc/init.d/目錄下,

而後用:update-rc.d xxx defaults NN命令(NN爲啓動順序),

將腳本添加到初始化執行的隊列中去。

注意若是腳本須要用到網絡,則NN需設置一個比較大的數字,如99。

1) 將你的啓動腳本複製到 /etc/init.d目錄下
 如下假設你的腳本文件名爲 test。
 
2) 設置腳本文件的權限
 $ sudo chmod 755 /etc/init.d/test
 
3) 執行以下命令將腳本放到啓動腳本中去:
 $ cd /etc/init.d
 $ sudo update-rc.d test defaults 95
 注:其中數字95是腳本啓動的順序號,按照本身的須要相應修改便可。在你有多個啓動腳本,而它們之間又有前後啓動的依賴關係時你就知道這個數字的具體做用了。
 該命令的輸出信息參考以下:update-rc.d: warning: /etc/init.d/test missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Adding system startup for /etc/init.d/test ...
    /etc/rc0.d/K95test -> ../init.d/test
    /etc/rc1.d/K95test -> ../init.d/test
    /etc/rc6.d/K95test -> ../init.d/test
    /etc/rc2.d/S95test -> ../init.d/test
    /etc/rc3.d/S95test -> ../init.d/test
    /etc/rc4.d/S95test -> ../init.d/test
    /etc/rc5.d/S95test -> ../init.d/test
 
卸載啓動腳本的方法:
 $ cd /etc/init.d 
 $ sudo update-rc.d -f test remove
命令輸出的信息參考以下:
Removing any system startup links for /etc/init.d/test ...
    /etc/rc0.d/K95test
    /etc/rc1.d/K95test
    /etc/rc2.d/S95test
    /etc/rc3.d/S95test
    /etc/rc4.d/S95test
    /etc/rc5.d/S95test
    /etc/rc6.d/K95test

 8、用戶相關命令(紅字爲主命令,非紅字爲輔助查看命令)

1) 添加一個用戶

創建一個新用戶帳戶tomcat,並設置UID爲544,主目錄爲/usr/tomcat,屬於develop組:

root@test-api:/ysconfig/booking_api# useradd -u 544 -d /home/tomcat -g develop -m tomcat
root@test-api:/ysconfig/booking_api# cat /etc/passwd
.....
.....
tomcat:x:544:100::/home/tomcat:

加-m 若是主目錄不存在則自動建立。

 

2) 提高用戶權限,使用戶擁有sudo權限

root@test-api:/ysconfig/booking_api# usermod tomcat -G sudo 
root@test-api:/ysconfig/booking_api# cat /etc/group
....
sudo:x:27:ubuntu,tomcat

 

3) 修改用戶密碼

root@test-api:/ysconfig/booking_api# passwd tomcat
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

 

4) 修改用戶名

usermod -l  新用戶名稱   原來用戶名稱

root@test-api:/ysconfig/booking_api# usermod -l test tomcat

 

5)用戶密碼鎖定與解鎖

鎖定:

root@test-api:/ysconfig/booking_api# sed -n '$p' /etc/shadow 
test:$6$EtlZZdjX$2rrz.tGFwylaUWQeD4of4yu.x2IA6q4/SKl5N0yqHrVxN2r.3wO5pv0zktecsvPf8uvUjtQRYaJkS53rRsAdR/:17276:0:99999:7:::
root@test-api:/ysconfig/booking_api# usermod -L test
root@test-api:/ysconfig/booking_api# sed -n '$p' /etc/shadow 
test:!$6$EtlZZdjX$2rrz.tGFwylaUWQeD4of4yu.x2IA6q4/SKl5N0yqHrVxN2r.3wO5pv0zktecsvPf8uvUjtQRYaJkS53rRsAdR/:17276:0:99999:7:::

解鎖:

root@test-api:/ysconfig/booking_api# usermod -U test
root@test-api:/ysconfig/booking_api# sed -n '$p' /etc/shadow 
test:$6$6A/gD4Ku$Xc9rTRhdpRJTMcDGzjwLdX77x1BGS32abn50U9hN2qddQWcsXU1eORQ98Z7MnLbLti36AH0/ntaRo8oUMt2zf1:17276:0:99999:7:::

passwd也能夠用來鎖定與解鎖,不過有些區別:

passwd是用來鎖定用戶口令的

usermod是用來鎖定用戶賬號的

passwd -l hide 後shadow中hide的密碼前增長2個」!」 

passwd -u hide 將去除shadow中hide密碼前的2個」!」 

usermod -L hide 後shadow中hide的密碼前增長1個」!」 

usermod -U hide 將去除shadow中hide密碼前的1個」!」 

所以使用passwd -l hide鎖定用戶後,須要執行兩次usermod -U hide或者執行一次passwd -u hide 

 

6) 修改用戶的shell

root@test-api:/ysconfig/booking_api# sed '$!d' /etc/passwd
test:x:544:100::/home/test:
root@test-api:/ysconfig/booking_api# usermod -s /bin/sh test
root@test-api:/ysconfig/booking_api# sed -n '$p' /etc/passwd
test:x:544:100::/home/test:/bin/sh

 

7) 指定用戶過時

root@test-api:/ysconfig/booking_api# sed -n '$p' /etc/shadow 
test:$6$6A/gD4Ku$Xc9rTRhdpRJTMcDGzjwLdX77x1BGS32abn50U9hN2qddQWcsXU1eORQ98Z7MnLbLti36AH0/ntaRo8oUMt2zf1:17276:0:99999:7:::
root@test-api:/ysconfig/booking_api# usermod -e 2017-10-01 test
root@test-api:/ysconfig/booking_api# sed -n '$p' /etc/shadow 
test:$6$6A/gD4Ku$Xc9rTRhdpRJTMcDGzjwLdX77x1BGS32abn50U9hN2qddQWcsXU1eORQ98Z7MnLbLti36AH0/ntaRo8oUMt2zf1:17276:0:99999:7::17440:

 

9、查看路徑下的文件大小

root@test-api:/ysconfig/booking_api# du -sh ./*
4.0K    ./acp_sdk.properties
4.0K    ./authSignature.properties
4.0K    ./cache.properties
8.0K    ./common.properties
4.0K    ./dubbo.properties
24K     ./filter_en_39.json
16K     ./filter_en_42.json.bak
16K     ./filter_en.json
20K     ./filter_en_new.json
28K     ./filter_zh_39.json
24K     ./filter_zh_42.json
16K     ./filter_zh_42.json.bak
16K     ./filter_zh.json
20K     ./filter_zh_new.json
8.0K    ./ipay.properties
8.0K    ./log4j_api.xml
8.0K    ./log4j_ipay.xml
4.0K    ./msg.properties
4.0K    ./payLimitMax.properties
4.0K    ./reserveDefault.properties
8.0K    ./secrecy.properties
16K     ./unionpay
8.0K    ./wx
12K     ./ysserver.properties

 

10、查看硬盤空間

root@test-api:/ysconfig/booking_api# df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/vda1       20509308 12166056   7278396  63% /
none                   4        0         4   0% /sys/fs/cgroup
udev             4077644        4   4077640   1% /dev
tmpfs             817696      872    816824   1% /run
none                5120        0      5120   0% /run/lock
none             4088476        0   4088476   0% /run/shm
none              102400        0    102400   0% /run/user
/dev/vdb        61796348  8675684  49958552  15% /data

 

11、壓縮與解壓命令

1) zip

unzip remypv.zip -d remypv                                 //解壓remypv.zip至remypv文件夾

zip tmp.zip tmp/                                                 //壓縮tmp文件夾至tmp.zip

ls localhost_access_log.201* | xargs zip test.zip     //將localhost_access_log.201開頭的日誌文件打包壓縮成 test.zip

2) tar

tar -zcvf  log.tar.gz  localhost_access_log.2017-04-01.06.txt     //將localhost_access_log.2017-04-01.06.txt壓縮至log.tar.gz , 以 gzip 壓縮

tar -ztvf  log1.tar.gz                                                              //查看log1.tar.gz 下有哪些內容

tar -xzvf  log1.tar.gz   -C  ./log1                                            //將log1.tar.gz解壓至log1目錄下

 

12、上傳下載文件

通常來講,linux服務器大可能是經過ssh客戶端來進行遠程的登錄和管理的,使用ssh登錄Linux主機之後,如何可以快速的和本地機器進行文件的交互呢,也就是上傳和下載文件到服務器和本地;

與ssh有關的兩個命令能夠提供很方便的操做:

   sz:將選定的文件發送(send)到本地機器

   rz:運行該命令會彈出一個文件選擇窗口,從本地選擇文件上傳到服務器(receive)

rz,sz是即是Linux/Unix同Windows進行ZModem文件傳輸的命令行工具

windows端須要支持ZModem的telnet/ssh客戶端(好比SecureCRT)

運行命令rz,便是接收文件,SecureCRT就會彈出文件選擇對話框,選好文件以後關閉

 

十3、遠程文件複製

scp [-r]  A服務器文件或目錄  B服務器目錄      //若是是目錄複製,必定要加上 -r 參數

假如用戶目前在A服務器上操做

1) A複製到B:

複製時須要身份認證,輸入登陸到B的密碼便可。

示例:把A服務器的configs目錄複製到B服務器的/home/ubuntu目錄下

root@dev-api:/opt# scp -r configs/ ubuntu@192.168.15.7:/home/ubuntu
The authenticity of host '192.168.15.7 (192.168.15.7)' can't be established.
ECDSA key fingerprint is cd:05:48:77:2f:cb:2d:cc:81:05:f5:9a:e3:95:a9:f3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.15.7' (ECDSA) to the list of known hosts.
ubuntu@192.168.15.7's password: 
hbase.properties                                                                                                                                                                                          100%  241     0.2KB/s   00:00    
log4j.xml                                                                                                                                                                                                 100% 2458     2.4KB/s   00:00    
env.properties                                                                                                                                                                                            100%   30     0.0KB/s   00:00    
jdbc.properties                                                                                                                                                                                           100%  478     0.5KB/s   00:00    
log4j.xml                                                                                                                                                                                                 100% 3992     3.9KB/s   00:00    
purse.properties                                                                                                                                                                                          100%  611     0.6KB/s   00:00    
ysserver.properties                                                                                                                                                                                       100% 8845     8.6KB/s   00:00    
filter_zh.json                                                                                                                                                                                            100%   16KB  15.5KB/s   00:00    
log4j.xml                                                                                                                                                                                                 100% 5362     5.2KB/s   00:00    
filter_en_39.json                                                                                                                                                                                         100%   26KB  26.0KB/s   00:00    
.ysserver.properties.swo                                                                                                                                                                                  100%   16KB  16.0KB/s   00:00    
filter_en.json                                                                                                                                                                                            100%   15KB  15.2KB/s   00:00    
filter_zh_new.json                                                                                                                                                                                        100%   17KB  16.8KB/s   00:00    
ysserver.properties20151010_bak             

2) B複製到A (反過來便可)

複製時須要身份認證,輸入登陸到B的密碼便可。

示例:把B服務器的app_config目錄複製至A服務器的/home/ubuntu目錄下

root@dev-api:/opt# scp -r ubuntu@192.168.15.7:/opt/app_config/ /home/ubuntu
ubuntu@192.168.15.7's password: 
invitationSpecialStyles                                                                                                                                                                                   100% 1581     1.5KB/s   00:00    
homeNav.m                                                                                                                                                                                                 100% 6982     6.8KB/s   00:00    
invitationStyles                                                                                                                                                                                          100%   17KB  16.6KB/s   00:00    
init                                                                                                                                                                                                      100%   12KB  11.9KB/s   00:00    
procityList      

 

 

十4、網絡相關命令

1) ifconfig

這個命令一般用來查看和更改網絡接口的地址和參數。使用方法爲:

ifconfig -interface [options] address;

ifconfig是手工配置網絡必須用到的命令也是網絡命令中很經常使用的一個命令,直接在終端下輸入ifconfig會回顯機器的網絡設置狀況,包括網卡信息,ip信息等等;若是要給網卡eth0配置ip地址x.x.x.x,掩碼x.x.x.x,能夠輸入:

ifconfig eth0 x.x.x.x netmask x.x.x.x

ifconfig eth0 down

ifconfig eth0 up

 

2) ping

這個命令也很經常使用,一般用來檢測主機網絡接口狀態;測試網絡的連通性、簡單測試網絡性能的好壞等;能夠經過輸入ping 127.0.0.1來測試局域網的聯通狀況,ping 後跟外網地址能夠測試是否聯網以及網絡性能(時延等);

這是最經常使用的狀況,ping的各類複雜參數通常不經常使用;

 

3) netstat

檢查整個Linux網絡狀態。

netstat [-acCeFghilMnNoprstuvVwx][-A][--ip]

netstat 主要用於Linux察看自身的網絡情況,如開啓的端口、在爲哪些用戶服務,以及服務的狀態等。此外,它還顯示系統路由表、網絡接口狀態等。它是一個綜合性的網絡狀態的察看工具。

netstat只顯示已創建鏈接的端口,若是要顯示處於監聽狀態的全部端口,使用-a參數便可;

netstat -nr --顯示路由表

4) Tracert

跟蹤路由信息,使用此命令能夠查出數據從本地機器傳輸到目標主機所通過的全部途徑,這對咱們瞭解網絡佈局和結構頗有幫助。   

用法:tracert IPaddress

5) nslookup

查詢域名和IP地址的對應

如nslookup www.baidu.com

這個命令有時候能夠代替ping來查看網絡連通性,由於ping用的是有時候會被禁止。

6) route

查看路由信息

route -n --顯示本機路由表,通常計算機路由表就兩三條,去掉環迴路由,只剩默認路由,通常下一條爲網關。

手工增長/刪除一條路由

sudo route add -net x.x.x.x netmask x.x.x.x gw x.x.x.x

7) 探測arp綁定(動態和靜態)列表,顯示全部鏈接了個人計算機,顯示對方IP和MAC地址

arp -a

8) 探測對方對方計算機名,所在的組、域及當前用戶名 

ping -a IP -t ,只顯示NetBios名

相關文章
相關標籤/搜索