Shell命令笔记2

  大家好,分享下最近工作中用得比较多的shell命令,希望对大家有帮助。

获取数组长度:

${#array_name[*]}

获取脚本相对路径

script_path=$(dirname "$0")

获取脚本的名字

script_name=$(basename "$0")

获取脚本的绝对路径

script_path=$(cd "$(dirname "$0")" && pwd)

获取脚本的绝对文件路径

script_file_path=$(cd "$(dirname "$0")" && pwd)/$(basename "$0")

获取后缀名字

test="example.txt"
filename="${test%.*}"
suffix="${test##*.}"
echo $fileanme $suffix
## 输出example txt

获取当前目录的最大序号的文件

ls | sort -n | tail -n 1 

1.txt
2.txt
11.txt
22.txt
28.txt
33.txt
输出 33.txt

单网卡配置多个ip

  分别eth0网卡为两个ip,eth0的虚拟网卡为eth0:0 eth0:1,以此类推。

ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
route add default gw 192.168.1.1

ifconfig eth0:0 192.168.2.100 netmask 255.255.255.0 up
route add default gw 192.168.2.1 dev eth0:0

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>