Linux工具-tcpdump
参考文献
https://wizardzines.com/zines/tcpdump/
https://www.tcpdump.org/manpages/tcpdump.1.html
https://www.tcpdump.org/manpages/pcap-filter.7.html
tcpdump
tcpdump抓包使用的是libpacp这种机制.它的大致原理是:在收发包时,如果该包符合tcpdump设置的规则(BPF filter),那么该网络包就会被拷贝一份到tcpdump的内核缓冲区,然后以PACKET_MMAP的方式将这部分内存映射到tcpdump用户空间,解析后就会把这些内容给输出了
123456789101112root@root:/home/root# tcpdump -htcpdump version 4.9.3libpcap version 1.9.1 (with TPACKET_V3)OpenSSL 1.1.1f 31 Mar 2020Usage: tcpdump [-aAbdDefhHIJKlLnNOpqStuUvxX#] [ -B size ] [ ...
Linux工具-wget
参考文献
wget
1wget [参数] [URL地址]
命令参数
启动参数:
-V, –version 显示wget的版本后退出
-h, –help 打印语法帮助
-b, –background 启动后转入后台执行
-e, –execute=COMMAND 执行’.wgetrc’格式的命令,wgetrc格式参见/etc/wgetrc或~/.wgetrc
记录和输入文件参数
-o, –output-file=FILE 把记录写到FILE文件中
-a, –append-output=FILE 把记录追加到FILE文件中
-d, –debug 打印调试输出
-q, –quiet 安静模式(没有输出)
-v, –verbose 冗长模式(这是缺省设置)
-nv, –non-verbose 关掉冗长模式,但不是安静模式
-i, –input-file=FILE 下载在FILE文件中出现的URLs
-F, –force-html 把输入文件当作HTML格式文件对待
-B, –base=URL 将URL作为在-F -i参数指定的文件中出现的相对链接的前缀
–sslcertfile=FIL ...
Linux工具-top
参考文献
top linux下的任务管理器
top命令说明
1234567891011top - 16:30:42 up 308 days, 19:08, 1 user, load average: 0.00, 0.02, 0.00Tasks: 120 total, 1 running, 119 sleeping, 0 stopped, 0 zombie%Cpu(s): 0.5 us, 1.0 sy, 0.0 ni, 98.2 id, 0.0 wa, 0.3 hi, 0.0 si, 0.0 stMiB Mem : 3591.0 total, 158.4 free, 2741.9 used, 690.7 buff/cacheMiB Swap: 0.0 total, 0.0 free, 0.0 used. 565.8 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND ...
Linux-ssh
参考文献
如何愉快地将 linux 作为开发环境: ssh 隧道
如何配置SSH别名
SSH
12345678910ssh [options] [user@]host [command]usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port ...
Linux工具-cURL
参考文献
https://www.bilibili.com/video/BV1n94y1U7Eu/?spm_id_from=333.788
https://www.ruanyifeng.com/blog/2019/09/curl-reference.html
https://catonmat.net/cookbooks/curl
cURL
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162# 基础用法curl URL# POSTcurl -X -POST URLcurl -XPOST URLcurl -XPOST URL -d '{}'# --data-urlencode参数等同于-d,发送 POST 请求的数据体,区别在于会自动将发送的数据进行 URL 编码。curl --data-urlencode 'comment=hello world' ...
Linux-shell编程-变量
参考文献
https://github.com/52fhy/shell-book/blob/master/chapter1.md
定义变量
定义变量时,变量名不加美元符号($)
1variableName="value"
注意,变量名和等号之间不能有空格
变量名的命令遵循如下规则:
首字母必须为字母(A-Z,a-z)
中间不能有空格,可以使用下划线(_)
不能使用标点符号
不能使用bash里的关键字
在变量前面加readonly 命令可以将变量定义为只读变量,只读变量的值不能被改变。
使用 unset 命令可以删除变量。语法:
1unset variable_name
变量被删除后不能再次使用;unset 命令不能删除只读变量。
使用变量
使用一个定义过的变量,只要在变量名前面加美元符号($)
123name="holelin"echo $nameecho ${name}
变量名外面的花括号时可选的,加不加都行,加花括号是为了帮助解释器识别变量的边界
变量类型
局部变量 局部变量 ...
Linux-shell脚本编程(二)
用cat进行拼接
cat: (concatenate)拼接,cat命令不仅可以读取文件和拼接数据,它还能够从标准输入中进行读取。要从标准输入中读取,就要使用管道操作符:
123OUTPUT_FROM_SOME COMMANDS | catehco 'Text through stdin' | cat - file.txt- 被作为来自stdin文本的文件名
cat file1 file2 file3
压缩空白行
cat -s file.txt
cat file.txt | tr -s '\n'
将制表符显示为^|
cat -T file.txt
显示行号:cat -n file.txt
录制和回放终端
script -t 2> timing.log -a output.session 输入exit退出
timing.log文件用于存储时序信息,描述每个命令在何时运行
out.session文件用于存储命令输出。
-t 选项用于将时序数据stderr
2>则用于stderr重定向到timing.log
...
Linux-shell脚本编程(一)
参考文献
Linux Shell脚本攻略
脚本开头
1# !/bin/bash
查看环境变量
查看所有环境变量env
查看单个程序的环境变量
pgrep <程序名称>
cat /proc/$PID/environ
示例
12345678910111213[root@holelin ~]# pgrep java2375829629[root@holelin ~]# cat /proc/23758/environ | tr '\0' '\n'SHELL=/bin/bashUSER=jenkinsPATH=/sbin:/usr/sbin:/bin:/usr/binPWD=/LANG=en_US.UTF-8HOME=/var/lib/jenkinsSHLVL=2LOGNAME=jenkins_=/usr/local/jdk1.8/bin/java
获取字符串长度
12[root@holelin ~]# echo ${#USER}4
识别当前的shell版本
1234[root@holeli ...
Linux-用户管理
参考文献
用户管理
useradd
新建用户
12345678910111213-c<备注>: 加上备注文字.备注文字会保存在passwd的备注栏位中;-d<登入目录>: 指定用户登入时的启始目录;-D: 变更预设值;-e<有效期限>: 指定帐号的有效期限;-f<缓冲天数>: 指定在密码过期后多少天即关闭该帐号;-g<群组>: 指定用户所属的群组;-G<群组>: 指定用户所属的附加群组;-m: 自动建立用户的登入目录;-M: 不要自动建立用户的登入目录;-n: 取消建立以用户名称为名的群组;-r: 建立系统帐号;-s<shell>: 指定用户登入后所使用的shell;-u<uid>: 指定用户id.
12345678910111213#-g: 加入主要组、-G: 加入次要组useradd –g sales jack –G company,employees # 新建用户并创建同名用户组,创建home目录,使用/bin/bash作为初始bash useradd -U -m -s /bi ...
Linux工具-VIM
参考文献
精通 VIM ,此文就够了
多模式文本编辑器
四种模式
正常模式(Normal-mode) 默认
正常模式一般用于浏览文件,也包括一些复制、粘贴、删除等操作.这时击键时,一些组合键就是 vim 的功能键,而不会在文本中键入对应的字符.
在这个模式下,我们可以通过键盘在文本中快速移动光标,光标范围从小到大是字符、单词、行、句子、段落和屏幕.启动 VIM 后默认位于正常模式.不论是什么模式,按一下 <Esc> 键 ( 有时可能需要按两下,插入模式按一下 Esc ,就会切换到正常模式,命令模式或者可视模式下执行完操作以后,就会自动进入正常模式,如果进入命令模式或者可视模式没有执行任何操作,按两下 Esc 即可 )都会进入正常模式.
插入模式(Insert-mode)
该模式下可以输入内容
按下i,l,o,O,a,A,R等任何一个字母之后才会进入插入模式
命令模式(Command-mode)
在正常模式中,按下:(冒号)键或者/ (斜杠),会进入命令模式.在命令模式中可以执行一些输入并执行一些 VIM 或插件提供的指令,就像在shell里一样.这些指令 ...