侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Memo

2023-12-07 星期四 / 0 评论 / 0 点赞 / 121 阅读 / 6807 字

文本处理# 统计file1中没有,file2中有的行grep -vwf file1 file2#抓取IPgrep -oP "(/d+/.){3}/d+"#抓取主机名(长)grep -oP --colo

文本处理

# 统计file1中没有,file2中有的行grep -vwf file1 file2#抓取IPgrep -oP "(/d+/.){3}/d+"#抓取主机名(长)grep -oP --color=auto "([a-z]+[0-9]+/.)([a-z]+/.)([a-z]+)"#抓取主机名(短)(适合短主机名为字母加数字)grep -oP --color=auto "([a-z]+[0-9]+)"#两行变一行sed 'N;s//n/ /'# tail -f 过滤tail -f file|grep --line-buffered 'key words' # n行变一行 n>1awk 'NR%n{printf "%s ",$0;next;}1'# 小写转大写并每隔2个字符加:echo e947a256d474c3f18fbb7b6ab30750f3e6706914|tr 'a-z' 'A-Z'|sed -e 's//(../)//1:/g'E9:47:A2:56:D4:74:C3:F1:8F:BB:7B:6A:B3:07:50:F3:E6:70:69:14:# awk 按指定列统计awk '{a[$1]+=1}END{for (i in a)print i,a[i]}' file# sort 按列排序sort -u -t, -k1,1# awk转换txt为csvawk '{for(i=1;i<=NF;i++) {if(i<NF) printf $i",";else print $i}}'# 多行变一行awk BEGIN{RS=EOF}'{gsub(//n/," ");print}' file

JSON处理

# jq https://stedolan.github.io/jq/#test.json{    "id": 1,    "details": {        "username": "jamesbrown",        "name": "James Brown"    }}#filtercat test.json |jq 'select(.details.name == "James Brown")|.id'#取keysjq -r "keys[]"
  • https://stackoverflow.com/questions/38689645/jq-how-do-i-print-a-parent-value-of-an-object-when-i-am-already-deep-into-the

进程查看

#查看进程启动时间ps -p $(ps -ef|grep process_name |grep -v grep|awk '{print $2}') -o lstart# 查看进程cgroupps xawf -eo pid,user,cgroup,args# 查看占用内存前5进程ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5

bash

#bash更改sudoersudo bash -c 'echo "foobar ALL=(ALL:ALL) ALL" | (EDITOR="tee -a" visudo)'#date获取上个月date '+%Y %m' | awk '{if($2==1){$1--;$2=12}else $2--;printf "%d%02d/n",$1,$2}'#wget 下载jrewget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jre-8u111-linux-x64.rpm#wget下载目录wget  -e robots=off -r -nH --cut-dirs=目录层级 --no-parent --reject="index.html*"  url# cd忽略大小写shopt -s cdspell# 查找可执行文件find <dir> -executablefind <dir> -executable -type f# 删除7天前的文件find /cache  -type f -atime +7 -print0 | xargs -0 rm# rsync over sshrsync --progress -ave ssh  user@remoteserver:/src_dir /dest_dir# 删除大量小文件rsync -a --delete blanktest/ test/# 配置代理# cat /etc/profile.d/proxy.shexport http_proxy="http://proxy:3128"export https_proxy="http://proxy:3128"export no_proxy="127.0.0.1, localhost, *.example.com"

Network

# 查看广播包tcpdump -e -i eth1 ip    broadcasttcpdump -e -i eth1 ether broadcast# 统计指定端口tcp连接数netstat -atn|grep "ES"|grep 端口|awk '{print $5}'|cut -d : -f 1|sort -n|uniq -c# tcp端口检查nc -tvz [ ip or hostname] port# udp端口检查nc -uvz [ ip or hostsname ] port# iptables 限制连接数-A INPUT -p tcp -m state --state NEW -m connlimit --connlimit-above 1000 --connlimit-mask 32 -j LOG_REJECT-A LOG_REJECT -j LOG --log-prefix "LOG_REJECT:" --log-level 6-A LOG_REJECT -p tcp -j REJECT --reject-with tcp-reset# .iftoprc# config file for iftopdns-resolution: noport-resolution: noshow-bars: yespromiscuous: yesport-display: onhide-source: nohide-destination: nouse-bytes: yesline-display: one-line-bothshow-totals: yeslog-scale: yes

Disk

# 清空分区dd if=/dev/urandom of=/dev/sdb bs=512 count=64

ssh

#C可以ssh访问B B可以访问A的3389端口 现在C要访问A的3389端口,ssh远程转发A的3389端口至C的7001端口(在C上执行)ssh -L 7001:A:3389 root@B# .ssh/configHost BHostName BLocalForward 7001 A:338#socks5 proxyDynamicForward 8080# A通过跳板机B scp C上的文件到本地 在A上执行scp -o ProxyCommand="ssh root@B nc C 22" -r root@C:/tmp/xxx /tmp/xxx

tools

# tmuxhttps://github.com/gpakosz/.tmux.git# vimhttp://vimawesome.com/https://github.com/amix/vimrc# cygwin 包管理https://github.com/transcode-open/apt-cyg# google driverhttps://github.com/prasmussen/gdrive# backuphttps://github.com/borgbackup/borg# monitor toolsatop

For fun

#星球大战telnet towel.blinkenlights.nl#命令行生成二维码# http://qrenco.de#命令行录像# https://asciinema.org

mac 必装

# https://github.com/sindresorhus/quick-look-pluginsbrew cask install qlcolorcode qlstephen qlmarkdown quicklook-json qlprettypatch quicklook-csv betterzipql qlimagesize webpquicklook suspicious-package quicklookase qlvideobrew install git bash-completion aria2

debug

strace

ssl 证书

https://letsencrypt.org/getting-started/https://certbot.eff.org/# rhel 安装自制证书cp *.crt /etc/pki/ca-trust/source/anchors/update-ca-trust# 签发通配符证书certbot-auto certonly  -d "*.xxx.com" --manual --preferred-challenges dns-01  --server https://acme-v02.api.letsencrypt.org/directory

Docker

# 获取容器IPdocker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id# 清除build失败产生的imagesdocker rmi $(docker images -f 'dangling=true' -q) -f

Windows

# 查看serialnumberwmic bios get serialnumber

selinux

#查看本地定义的策略semanage fcontext -C -l#删除策略semanage fcontext -d rule_name#restore file(s) default SELinux security contexts.restorecon -vR  xxx# get the default SELinux security context for the specified path from the file contexts configurationmatchpathcon xxx

ubuntu

# 解决vnc问题gsettings set org.gnome.Vino require-encryption 'false'

Nginx

# 记录request header到Access log. $http_headernamelog_format addHeaderlog '$remote_addr - $remote_user [$time_local] '                 '"$request" $status $body_bytes_sent '                 '"$http_referer" "$http_user_agent" "$http_x_forwarded_for" "$request_body" "$http_Authorization"';access_log  /var/log/nginx/s3-access.log addHeaderlog;

git

#自定义commit时间git commit --date="10 day ago" -m "Your commit message" git commit --date="10 hour ago" -m "Your commit message" 

广告 广告

评论区