shell 常用命令

tools

1
2
tldr #man
cloc #统计

rpm

1
2
3
4
5
6
rpmbuild -ba *.spec  #编译打包rpm
rpm -ivh *.rpm #安装rpm包
rpm -qpR *.rpm #列出包依赖的库
rpm -ql *.rpm #列出安装的内容
rpm -qpl *.rpm #列出未安装的包里内容
rpm -qa | grep #查找安装的相关包

scp

1
2
scp [-P port] file usr@x.x.x.x:~/dir  #local to remote
scp [-P port] usr@x.x.x.x:~/dir/file ./dir #remote to local

cp

1
cp -d or -P symbolic-link dir/   #复制软连接而不是文件本身

ssh

1
ssh [-p port] usr@x.x.x.x  #ssh登录远端

user

1
2
adduser <username>  #添加新用户
usermod -aG sudo/wheel <username> #用户添加到sudo组

系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
lsb_release -a #查看系统版本信息的命令
cat /etc/redhat-release
uname -a
hostnamectl
uptime
cat /proc/version #查看系统版本信息的命令
cat /proc/sys/fs/inotify/max_user_watches #最大文件监控数
# The limit can be increased to its maximum by editing /etc/sysctl.conf (except on Arch Linux, read below) and adding this line to the end of the file:
# fs.inotify.max_user_watches=524288
# The new value can then be loaded in by running sudo sysctl -p.
# While 524,288 is the maximum number of files that can be watched, if you're in an environment that is particularly memory constrained, you may wish to lower the number. Each file watch takes up 1080 bytes, so assuming that all 524,288 watches are consumed, that results in an upper bound of around 540 MiB.

ls /proc[pid] #查看进程信息
watch -n 1 "nstat | grep Tcp" #查看机器网络变化信息, 排错可用
df -lhT #查看文件系统类型

du -h --max-depth=1 #查看当前目录文件夹大小

who

who -Hu #查看谁可以访问

grep sh$ /etc/passwd #查看谁有shell访问权限

# 查看是否物理机
dmidecode -s system-manufacturer
dmidecode -s system-product-name
lshw -c system | grep product | head -1
cat /sys/class/dmi/id/product_name
cat /sys/class/dmi/id/sys_vendo

# 查看硬件信息
lscpu or cat /proc/cpuinfo
lsmem or cat /proc/meminfo
ifconfig -a
ethtool <devname>
lshw
lspci
dmidecode

# 查看进程和服务
pstree -pa 1
ps -ef
ps auxf
systemctl

# 网路
netstat -tulpn
netstat -anp
lsof -i
ss
iptables -L -n
cat /etc/resolv.conf
ss -ln | head -n1 ;ss -ln | grep 8000

# 内核
[https://www.oreilly.com/library/view/red-hat-enterprise/9781785283550/ch10s05.html](https://www.oreilly.com/library/view/red-hat-enterprise/9781785283550/ch10s05.html)
uname -r
cat /proc/cmdline
lsmod
modinfo <module>
sysctl -a
cat /boot/grub2/grub.cfg

# 日志
dmesg
tail -f /var/log/messages
journalctl


strace# 追踪

lspci -k | grep -A 2 -i "VGA" #查看显卡

git

1
2
git archive --prefix=output/ -o "../output.tar.gz" develop  #git库打包
git reflog # 查看本地记录

yum

1
2
yum reinstall packagename  #可以在/var/cache/yum目录下找到包
yum provides *.so.version #查询哪个包提供这个库

pkg-config

1
pkg-config --variable pc_path pkg-config #查看pc路径

make

1
make V=1 #展示出具体编译命令

code

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
# get all filename in specified path

path=$1
files=$(ls $path)
for file in $files
do
mv $file 'bad-'$file
done

rename
for i in `ls *.wav`;do mv $i `echo $i| sed 's/-cmd//g'`; done;

firewall

1
2
3
4
5
sudo ufw status
sudo ufw enable
sudo ufw allow 22
sudo ufw reload
sudo ufw delete allow 21

file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
in ext4
1:找到文件或目录的索引节点号

ls -i filename

2:找到文件所在的分区或VG

df -T

3:使用debugfs找到文件的创建时间(crtime)

debugfs -R 'stat <xxx>' /dev/xxxx

4:批量修改文件大小写
for file in * ;

do mv $file `echo $file | tr 'A-Z' 'a-z'`;

done

docker

1
sudo docker exec -it docker-compose_minio2_1 /bin/sh  #进入docker容器

PMS

1
2
3
4
5
6
7
8
9
10
11
将包(ebms.tar.gz) scp到本地分成7z包

7z a SR300088.代码.[媒体业务产品部].MS.7z ebms.tar.gz -v9m

(0) 将文档目录打成7z包

7z a 'SR300150.文档.[媒体业务产品部].MS'.7z 'SR300150.文档.[媒体业务产品部].MS'

(1) 将文档目录打成zip包

zip -r 'SR300175.文档.[媒体业务产品部].MRF.transcode'.zip 'SR300175.文档.[媒体业务产品部].MRF.transcode'