一、字符串:
1.求字符串长度:
STRING="Noah's Ark"
# echo ${#STRING}
10
2.截取子字符串:
# echo ${STRING:7:3}
Ark
3.模式匹配
# : 删除最小匹配前缀
## : 删除最大匹配前缀
% : 删除最小匹配后缀
%% :删除最大匹配后缀
# FILENAME=/opt/osmu/goodluck.txt
# echo ${FILENAME#*/}
opt/osmu/goodluck.txt
# echo ${FILENAME##*/}
goodluck.txt
# echo ${FILENAME%/*}
/opt/osmu
# echo ${FILENAME%%/*}
# FILENAME=opt/osmu/goodluck.txt
# echo ${FILENAME%%/*}
opt
二、时间:
1.时间装换为秒(seconds since 1970-01-01 00:00:00 UTC):
# date -d "2012-12-20 00:00:00" +%s
1355932800
2.秒转换回可读时间格式
# date -d @1355932800 "+%Y-%m-%d %H:%M:%S"
2012-12-20 00:00:00
3.指定时间上增加N秒
# date -d'20121219 23:59:57 3 sec' "+%Y-%m-%d %H:%M:%S"
2012-12-20 00:00:00
4.指定时间上,减少N秒
# date -d'20121220 00:00:03 3 sec ago' "+%Y-%m-%d %H:%M:%S"
2012-12-20 00:00:00