Shell命令笔记2

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

获取数组长度:

sh 复制代码
${#array_name[*]}

获取脚本相对路径

sh 复制代码
script_path=$(dirname "$0")

获取脚本的名字

sh 复制代码
script_name=$(basename "$0")

获取脚本的绝对路径

sh 复制代码
script_path=$(cd "$(dirname "$0")" && pwd)

获取脚本的绝对文件路径

sh 复制代码
script_file_path=$(cd "$(dirname "$0")" && pwd)/$(basename "$0")

获取后缀名字

sh 复制代码
test="example.txt"
filename="${test%.*}"
suffix="${test##*.}"
echo $fileanme $suffix
## 输出example txt

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

sh 复制代码
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,以此类推。

sh 复制代码
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
相关推荐
浮尘笔记2 小时前
Java Snowy框架CI/CD云效自动化部署流程
java·运维·服务器·阿里云·ci/cd·自动化
yyyyy_abc8 小时前
ceph学习笔记
笔记·ceph·学习
晓梦林8 小时前
ximai靶场学习笔记
android·笔记·学习
米高梅狮子9 小时前
03.网络类服务实践
linux·运维·服务器·网络·kubernetes·centos·openstack
IT19959 小时前
Dify笔记-创建自定义工具连接到自建的OpenAPI Schema服务
笔记
June`9 小时前
网络编程时内核究竟做了什么???
linux·服务器·网络
原来是猿9 小时前
腾讯云服务器端口开放完全指南
服务器·网络·腾讯云
一口吃俩胖子9 小时前
【脉宽调制DCDC功率变换学习笔记021】时域性能准则
笔记·学习
你的保护色9 小时前
【无标题】
java·服务器·网络
楼兰公子10 小时前
RK3588 + Linux7.0.3 网络工程调试错误速查手册
linux·网络·3588