Linux基礎命令 106 120

2021-09-24 22:37:30 字數 4485 閱讀 3879

目錄:diff 用於比較檔案或目錄的內容

vimdiff 視覺化的比較工具

tr 轉換刪除字串

tee 多重定向

dig 解析網域名稱

nslookup dns服務診斷工具

host 網域名稱解析工具

ping 網路服務診斷工具

route 配置預設閘道器和網路靜態路由

ifconfig 顯示網絡卡資訊

ip 檢視網絡卡資訊

netstat 檢視程序或者埠

lsof 檢視埠

traceroute 路由追蹤

tcpdump 抓包工具

特別是比較兩個版本不同的檔案以找到改動的地方

提示符:

a add 增加

c chage 改變

d delate 刪除

主要選項:-u 顯示行修改的上下文,預設為上下3行

示例:

[root@localhost etc]# diff -u networks networks.bak 

--- networks 2018-10-31 06:57:05.000000000 +0800

+++ networks.bak 2019-07-03 11:53:07.952357892 +0800

@@ -1,3 +1,4 @@

default 0.0.0.0

loopback 127.0.0.0

link-local 169.254.0.0

+test

和diff一樣,就是多了vim視覺化(可以比較4個檔案)

示例:

[root@localhost etc]# vimdiff networks networks.bak

主要選項:

-d 刪除

示例:

轉換 tr 'abc' 'xyz' < jeff.txt (a-x,b-y,c-z)
回到目錄

主要選項:

-a 追加重定向

示例:

ls|tee /tmp/ls.txt  # 相當於 ls > /tmp.ls.txt

cat /etc/passwd|tee /tmp/passwd.txt|tr 『a-z』 『a-z』

把cat的資料通過管道輸入到tr命令並且儲存到/tmp/passwd.txt檔案中

主要選項:

-t 正向解析,直接跳過本地的hosts檔案,解析dns配置的ip

-x 反向解析

示例:

dig www.baidu.com (這樣解析不是很完美)	

dig @8.8.8.8 www.baidu.com +trace (完美解析)

dig -t a www.baidu.com # 檢視a記錄

示例:

示例:

回到目錄

主要選項:

-c 指定傳送的ping包個數

-w 指定ping命令超時時長

-w 一次ping操作中,等待對方響應的超時時長

-s 指定ping包報文大小

示例:

ping www.baidu.com
主要選項:

-n 檢視閘道器資訊

-net 到乙個網路的路由表

示例:

route add default gw 閘道器(新增閘道器,但是是臨時生效)

route del default gw 閘道器(刪除閘道器)

route add -net 192.168.0.0/24 gw 10.10.10.2 (新增192.168.0.0這個網段,並從10.10.10.2這個閘道器出去)

主要選項:

-a 顯示所有介面

示例:

ifconfig eth0 10.0.0.100/24 up  

ifconfig eth0 (只檢視一塊網絡卡)

ifconfig eth0:0 192.168.1.1/24 up(配置在一塊網絡卡上配置多個ip,網絡卡或者系統重啟失效)

ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up

ifconfig eth0:0 down (刪除ip)

回到目錄

主要選項:

示例:

ip addr add 10.0.0.13/24 dev eth0:3(配置在一塊網絡卡上配置多個ip,網絡卡或者系統重啟失效)

ip addr del 10.0.0.13/24 dev eth0:3 (刪除ip)

ip link show eth1 #指定檢視介面的資訊

ip address show #檢視ip位址(同ifconfig)

ip address flush dev eth0 #清空eth0的ip位址

ip route add 192.168.0.0/24 via 10.0.0.2 dev eth1

ip route add default via 10.0.0.2

注:配置子介面,需要在/etc/sysconfig/network-scripts/裡配置乙個ifcfg-eth0:0,這樣才能永久有效

主要引數:

-a 檢視所有

-p 顯示正在執行的程序

-u 顯示udp協議相關的程序或者埠

-t 顯示tcp協議相關的程序或者埠

-n 已數字顯示

-l 僅列出有在 listen (監聽) 的服務狀態

-r 顯示路由表

示例:

netstat -tulnp | grep 80

netstat -rn

主要引數:

-i 列出符合條件的程序。(4、6、協議、:埠、 @ip )

示例:

[root@localhost ~]# lsof -i :22

command pid user fd type device size/off node name

sshd 4555 root 3u ipv4 47560 0t0 tcp *:ssh (listen)

sshd 4555 root 4u ipv6 47562 0t0 tcp *:ssh (listen)

sshd 10249 root 3u ipv4 8033090 0t0 tcp 172.31.1.201:ssh->172.31.3.65:50014 (established)

lsof |grep del # 檢視被刪除的程序

注:lsof /mnt 當umount /mnt無法解除安裝的時候,可以使用這個命令,來檢視是否有程序在使用中

回到目錄

示例:

traceroute www.baidu.com
主要引數:

-i 指定埠

-n 指定協議

-t 在輸出的每一行不列印時間戳

-s 將tcp的序列號以絕對值形式輸出,而不是相對值

-c 在收到指定的數量的分組後,tcpdump就會停止

示例:

tcpdump -n icmp -i eth0

tcpdump tcp -i eth1 -t -s 0 -c 100 and dst port ! 22 and src net 192.168.1.0/24 -w ./target.cap

tcp: ip icmp arp rarp 和 tcp、udp、icmp這些選項等都要放到第乙個引數的位置,用來過濾資料報的型別

-i eth1 : 只抓經過介面eth1的包

-t : 不顯示時間戳

-s 0 : 抓取資料報時預設抓取長度為68位元組。加上-s 0 後可以抓到完整的資料報

-c 100 : 只抓取100個資料報

dst port ! 22 : 不抓取目標埠是22的資料報

src net 192.168.1.0/24 : 資料報的源網路位址為192.168.1.0/24

-w ./target.cap : 儲存成cap檔案,方便用ethereal(即wireshark)分析

回到目錄

Linux基礎命令

eg man ls 就可以檢視ls相關的用法 注 按q鍵或者ctrl c退出,在linux下可以使用ctrl c終止當前程式執行。2.ls檢視目錄或者檔案的屬 列舉出任一目錄下面的檔案 eg ls usr man ls l a.d表示目錄 directory 如果是乙個 表示是檔案,如果是l則表示是...

linux基礎 命令

命令自動補全 help幫助 幫助文件 鳥哥linux私房菜 linux命令大全 工具書 man ls useradd utest useradd g group2 utest 建立utesty使用者屬於group2組 usermod g group3 utest 將utest所在的組改為group3...

linux 命令基礎

本週學習知識點 一 linux作業系統的目錄結構 在linux作業系統中,沒有 c d e等這些碟符的概念 只有乙個 代表根目錄。home 使用者的家 media 裝置 掛載 的映象檔案 root 最高許可權使用者 一般情況下不需要使用root 使用者 bin 所有的操作都是通過 命令實現的,這些命...