缘起
shell快捷键
快捷键 | 用处 |
---|---|
ctrl+a | 光标移动至行首 |
ctrl+e | 光标移动至行尾 |
Esc b | 左移一个单词(back) |
Esc f | 右移一个单词(forward) |
linux Commands
从服务器上下载和上传文件
安装:yum install lrzsz
下载:sz filename
上传文件到服务端:rz
查看核心数
新建用户
sudo adduser username
删除用户
sudo userdel username
将用户添加到sudo组
sudo adduser username sudo
显示端口占用
sudo netstat -tlpn
根据pid杀死进程
kill -9 pid
配置密匙
TODO
禁用22端口
TODO
df
df -h
和df -kh
的区别是什么
1 | (base) [root@izuf66ctwpabqmq17tt0r3z ~]# df -kh |
添加软链
ln -s [源文件或目录] [目标文件或目录]
zip文件
将 /home/html/ 这个目录下所有文件和文件夹打包为当前目录下的 html.zip:
1 | zip -q -r html.zip /home/html |
screen
添加一个新的screen
1 | screen -S session_name |
重新attach进之前的session
1 | screen -r |
关闭某个session
1 | screen -XS [session # you want to quit] quit |
tar
解压tar.xz
: tar -xf
解压*.tar.gz
: tar -zxvf 压缩文件名.tar.gz
查看文件夹大小
1 | du -sh |
echo
1 | 追加内容 |
rm
1 | 删除指定后缀的文件 |
grep
如果对应日志过于长,想要了解匹配内容的概览,可以使用正则截断grep -noE '你想匹配的内容.{100}' xxxx.log
-n
显示行号-o
只显示匹配到的内容-E
支持正则表达式.
匹配任意字符{100}
匹配规则出现100次
如果特定的行过于长,可以管道到less
来翻页查看
grep '匹配到这一行的内容非常长' xxxx.log | less
b
向上翻一页d
向后翻半页h
显示帮助界面Q
退出less 命令u
向前滚动半页y
向前滚动一行G
- 移动到最后一行g
- 移动到第一行
grep文件带通配符,同时grep多个文件
grep -R '关键字' ./20230215-* | grep '关键字2'
grep -v
剔除某个关键字
grep -v “需要被排除的关键字”
zgrep
如果日志被打包成gz
格式之后,如果想要查询对应的日志可以通过zgrep xxx.gz
zcat
Zcat是一个命令行实用程序,用于查看压缩文件的内容。它将压缩文件扩展为标准输出,允许您查看内容。
代码详情
1 | $ zcat /var/log/syslog.2.gz | tail -1 |
centos相关
屏蔽ip
总有脚本小子到处扫端口,把应用都扫坏了,所以有了这个需求
1 | firewall-cmd --list-rich-rules # 查看屏蔽的ip |
添加ip
1 | firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=43.229.53.61 reject" |
重启防火墙生效
1 | firewall-cmd --reload |
一条长命令整合上面的操作
1 | firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=162.142.125.54 reject" && firewall-cmd --reload && firewall-cmd --list-rich-rules |
ubuntu相关
很多机器学习的环境都是基于ubuntu的,所以把一台云服务器的系统换成了ubuntu
文件颜色的意义
- 蓝色:文件夹
- 绿色:表示可执行文件
- 红色:表示tar压缩文件
- 黄色:表示设备文件,在/dev下全是这类文件
- 浅蓝色:表示链接文件
- 白色文件:一般性文件,如文本文件,配置文件,源码文件
查看ubuntu版本
在ubuntu上安装v2ray
tx云的网络太拉跨了,装包和git clone什么的都要半天,没有proxy根本过不去日子
去repo的release下载并放到服务器解压
支线1:v2ray.service启动(systemctl start v2ray不起来)不起来
出现了两个bug
cp: cannot create regular file '/usr/lib/systemd/v2ray.service': Permission deni
Unit v2ray.service could not be found.
解决cannot create regular file
cp命令前加sudo
解决Unit v2ray.service could not be found.
将v2ray.service复制到/etc/systemd/system/
文件夹下
支线2:v2ray启动不起来
TODO
service文件里面写的v2ray和json地址和我之前写的bash小脚本的位置不太一样
ubuntu添加service
clash for linux
群晖
配置使用密匙登录
设置开机自启
sed、grep和awk之间的区别
What are the differences among grep, awk & sed?
What is the difference between sed and awk?
sed
:Readability of scripts can be difficult. Mathematical operations are extraordinarily awkward at best.I would tend to use sed
where there are patterns
in the text.
awk
:I would use awk
when the text looks more like rows
and columns
or, as awk refers to them “records” and “fields”.
For me the rule to separate them is: Use sed
to automate tasks you would do otherwise in a text editor manually. That’s why it is called stream editor. (You can use the same commands to edit text in vim). Use awk
if you want to analyze text, meaning counting fields, calculate totals, extract and reorganize structures etc.