linux 命令

本文分享了多个Shell脚本的实用技巧,包括如何检查端口使用情况,使用特殊变量进行参数处理,以及通过awk命令进行变量匹配。还介绍了如何判断文件修改时间是否超过指定时间,并给出具体实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

netstat -anpt | grep port   # 查看端口使用情况

$n        $1 the first parameter,$2 the second...
$#        The number of command-line parameters.
$0        The name of current program.
$?        Last command or function's return value.
$$        The program's PID.
$!        Last program's PID.
$@        Save all the parameters.

 

cd $(dirname "$0")  切换目录到脚本所在地

cd `dirname $0` 其中反引号··等同于$()。

 

a=`stat -c %Y tmp.txt`;
4 b=`date +%s`;
5 echo $b
6 expiration_time=`echo $EXPIRATION_TIME | awk '{print int($0)}'`
7 echo $expiration_time
8 if [ $[ $b - $a ] -gt $expiration_time ]
9 then
10 echo 'change time great than 180'
11 else
12 echo 'change time not great than 180'
13 fi

 

awk命令变量匹配

awk -v str1="AA" '$0 ~  str1 {print $2}' myfile

 `awk -v str1=$CITY_NAME '$0 ~ str1 {print $1}' $city_id_file_path` 根据字段相同获取改行

转载于:https://www.cnblogs.com/ChenAlong/p/4835556.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值