280篇 Default中的文章

tcpdump常用命令

监视指定主机的数据包

打印所有进入或离开sundown的数据包.

tcpdump host sundown

也可以指定ip,例如截获所有210.27.48.1 的主机收到的和发出的所有的数据包

tcpdump host 210.27.48.1 

打印helios 与 hot 或者与 ace 之间通信的数据包

tcpdump host helios and ( hot or ace )

截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信

tcpdump host 210.27.48.1 and (210.27.48.2 or 210.27.48.3 ) 

打印ace与任何其他主机之间通信的IP 数据包, 但不包括与helios之间的数据包.

tcpdump ip host ace and not helios

如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包,使用命令:

tcpdump ip host 210.27.48.1 and ! 210.27.48.2

截获主机hostname发送的所有数据

tcpdump -i eth0 src host hostname

监视所有送到主机hostname的数据包

tcpdump -i eth0 dst host hostname
More ~

shell去除重复行

去除重复行

sort file.txt |uniq

查找非重复行

sort file.txt |uniq -u

查找重复行

sort file.txt |uniq -d

统计

sort file.txt| uniq -c
More ~

ansible yum 安装慢的问题解决

使用ansible yum 模块安装软件时,可能会碰到执行非常慢的情况。

- name: install rpms
  yum:
    name:
      - etcd
    state: latest
    disablerepo: "*"
    enablerepo: some

原因可能是/etc/yum.conf配置的默认yum源响应非常慢,甚至不可达。

More ~

Delete lines with sed command

Sed Command to Delete Lines: Sed command can be used to delete or remove specific lines which matches a given pattern or in a particular position in a file. Here we will see how to delete lines using sed command with various examples.

More ~

How to Check if a File or Directory Exists in Bash

Many times when writing Shell scripts, you may find yourself in a situation where you need to perform an action based on whether a file exists or not.

In Bash, you can use the test command to check whether a file exists and determine the type of the file.

The test command takes one of the following syntax forms:

test EXPRESSION
[ EXPRESSION ]
[[ EXPRESSION ]]
More ~

是时间将CentOS8 升级为CentOS Stream了

CentOS8 的生命周期到2021年12月31日截止,CentOS7是到2024年6月30日。还有使用CentOS8的注意了,官方可能不再更新,需要将系统升级到CentOS Stream.

升级也很简单:

dnf swap centos-linux-repos centos-stream-repos
dnf distro-sync

附 CentOS Stream 下截地址:

http://mirrors.cqu.edu.cn/CentOS/8-stream/isos/x86_64/
http://mirrors.aliyun.com/centos/8-stream/isos/x86_64/
http://mirrors.neusoft.edu.cn/centos/8-stream/isos/x86_64/
http://mirrors.163.com/centos/8-stream/isos/x86_64/
http://mirrors.tuna.tsinghua.edu.cn/centos/8-stream/isos/x86_64/
http://mirrors.ustc.edu.cn/centos/8-stream/isos/x86_64/
http://ftp.sjtu.edu.cn/centos/8-stream/isos/x86_64/
http://mirrors.nju.edu.cn/centos/8-stream/isos/x86_64/
http://mirrors.bfsu.edu.cn/centos/8-stream/isos/x86_64/

More ~

linux命令: awk

awk

文本和数据进行处理的编程语言

补充说明

awk 是一种编程语言,用于在 linux/unix 下对文本和数据进行处理。数据可以来自标准输入(stdin)、一个或多个文件,或其它命令的输出。它支持用户自定义函数和动态正则表达式等先进功能,是 linux/unix 下的一个强大编程工具。它在命令行中使用,但更多是作为脚本来使用。awk 有很多内建的功能,比如数组、函数等,这是它和 C 语言的相同之处,灵活性是 awk 最大的优势。

awk 命令格式和选项

语法形式

awk [options] 'script' var=value file(s)
awk [options] -f scriptfile var=value file(s)
More ~

修改docker镜像

若有个名为nginx的容器:

docker run -it nginx bash

修改内容后退出,使用docker commit命令提交修改。

Usage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Create a new image from a container's changes

Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change list      Apply Dockerfile instruction to the created image
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)

如 :

docker commit -a "John Click" -m "add extra plugins" 2ff7f15ca033 nginx:latest

2ff7f15ca033 为刚才修改的docker容器id。

More ~

go test 覆盖率报告

go test -coverprofile=coverage.out
go tool cover -html=coverage.out

对指定目录

go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
More ~