0. 常用命令 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 ps -elf|grep lte ps aux ps -T -p `pidof lte_agent` ss -lpn |grep pidof lspci lscpu shutdown -r -t 1 set -enb ifconfig | more kill -9 `pidof lte_daemon` free -h -w -s 3 du -sh {filename} du -h -d 1 df -h free whereis {filename} find -name {filename} file {filename} true > {filename} > $filename >> $filename scp [filename] root@192.169.46.230:{path} tail -f [filename] |grep lte_agent ip addr add 10.11.1.130/24 dev eth1 ip addr del 10.11.1.130/24 dev eth1 ip route del 192.168.200.28/30 via 192.168.10.1 dev eth1 ip route add 192.168.200.28/30 via 192.168.10.1 dev eth1 metric 10 ip tuntap add eth1 mode tap ip tuntap add vnet1 mode tun ip link add link eth0 name eth0.2 type vlan id 2 ip link set eth0.1 up ip link set dev eth2 mtu 9000 ethtool -n eno1 ethtool --config-ntuple eno2 flow-type ip4 src-ip 192.168.112.118 dst-ip 192.168.112.32 action 0x0 loc 5 ssh root@10.11.1.131 scp {srcfilename} root@192.169.46.230:{path} env export unset modprobe vfio-pci lsmod | grep vfio rmmod vfio-pci strings lte_oam | grep VERSION objdump -d --start-addres=0x428790 --stop-address=0x4287b0 lte_ncp readelf -s libcspl_interface.so.0.0.1 | grep CSPL_Get_McbIp grep -rin "char" ./ gcc -E hello.c -o hello.i gcc -S hello.c gcc -c hello.c gcc hello.c gcc -E hello.c -o hello.i gcc -S hello.i -o hello.s gcc -c hello.s -o hello.o gcc hello.o -o hello
1. 变量 $X 的含义 1 2 3 4 5 6 7 8 9 $$ $! $? $- $* $@ $# $0 $1 ~$n
2. 符号 ${}、## 和 %% 的使用方法 1 2 3 4 5 6 7 8 9 10 file=/dir1/dir2/dir3/my.file.txt ${file#*/} :删掉第一个 / 及其左边的字符串 :dir1/dir2/dir3/my.file.txt${file##*/} :删掉最后一个 / 及其左边的字符串 :my.file.txt${file#*.} :删掉第一个 . 及其左边的字符串 :file.txt${file##*.} :删掉最后一个 . 及其左边的字符串 :txt${file%/*} :删掉最后一个 / 及其右边的字符串 :/dir1/dir2/dir3${file%%/*} :删掉第一个 / 及其右边的字符串 :(空值)${file%.*} :删掉最后一个 . 及其右边的字符串 :/dir1/dir2/dir3/my.file${file%%.*} :删掉第一个 . 及其右边的字符串 :/dir1/dir2/dir3/my
记忆的方法为: # 是 去掉左边(键盘上#在 $ 的左边); %是去掉右边(键盘上% 在$ 的右边); 单一符号是最小匹配;两个符号是最大匹配。
3. 符号 : 的使用方法 1 2 ${file:0:5} :提取最左边的 5 个字节:/dir1${file:5:5} :提取第 5 个字节右边的连续5个字节:/dir2
4. 符号 / 的使用方法 1 2 ${file/dir/path} :将第一个 dir 替换为 path :/path1/dir2/dir3/my.file.txt${file//dir/path} :将全部 dir 替换为 path :/path1/path2/path3/my.file.txt
5. 使用参数判断 1 2 3 4 5 6 7 8 9 -d :判断制定的是否为目录 -z :判断制定的变量是否存在值 -f :判断制定的是否为文件 -L : 判断制定的是否为符号链接 -r :判断制定的是否可读 -s : 判断存在的对象长度是否为0 -w : 判断制定的是否可写 -x :判断存在的对象是否可以执行 ! :测试条件的否定符号
6. 子shell 1、执行脚本时是在一个子shell环境运行的,脚本执行完后该子shell自动退出; 2、一个shell中的系统环境变量怎样才会被复制到子shell中(用export定义的变量); 3、一个shell中的系统环境变量只对该shell或者它的子shell有效,该shell结束时变量消失(并不能返回到父shell中); 4、不用export定义的变量只对该shell有效,对子shell是无效的。