每天一点新知识

shell命令 basename 用来去掉文件名中的路径(和后缀).
NAME
       basename - strip directory and suffix from filenames
SYNOPSIS
       basename NAME [SUFFIX]
       basename OPTION
DESCRIPTION
       Print NAME with any leading directory components removed.  If specified, also remove a trailing SUFFIX.
       --help display this help and exit
       --version
              output version information and exit
EXAMPLES
       basename /usr/bin/sort
              Output "sort"
       basename include/stdio.h .h
              Output "stdio"

[2011-11-14]sed修改配置文件
该配置文件格式为
[LOG_PARAM]
LogLevel = DEBUG_LEVEL
LogPath = ../log/
LogMaxSize= 1
LogMaxNum = 3
SysLogPrex = sys
BizLogPrex = biz
RadiusLogPrex = radius
WebLogPrex = web


修改语句:
sed -i '/LOG_PARAM/,/LogLevel/{/^LogLevel/{s/INFO_LEVEL/DEBUG_LEVEL/}}' ./sys.cfg
sed -i '/LOG_PARAM/,/LogLevel/{/^LogLevel/{s/DEBUG_LEVEL/INFO_LEVEL/}}' ./sys.cfg
改进,精确匹配
sed -i '/\<LOG_PARAM\>/,/\<LogLevel\>/{/^\<LogLevel\>/{s/INFO_LEVEL/DEBUG_LEVEL/}}' ./sys.cfg
sed -i '/\<LOG_PARAM\>/,/\<LogLevel\>/{/^\<LogLevel\>/{s/DEBUG_LEVEL/INFO_LEVEL/}}' ./sys.cfg
注意,在修改文件前,最好用dos2unix将文件转换一下,否则极有可能因为文件格式而产生多余的字符,
进而导致脚本执行失败。


date的用法
NAME
       date - print or set the system date and time
SYNOPSIS
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION
       -d, --date=STRING
              display time described by STRING, not ‘no
       -r, --reference=FILE
              display the last modification time of FILE

[root@test1 scripts]# date
2011年 11月 23日 星期三 16:23:35 CST
[root@test1 scripts]# date +"%Y-%m-%d %H:%M:%S"
2011-11-23 16:23:38
[root@test1 scripts]# date --date="-24 hour" +"%Y-%m-%d %H:%M:%S"
2011-11-22 16:23:41
[root@test1 scripts]# date --date="-20 hour" +"%Y-%m-%d %H:%M:%S"
2011-11-22 20:23:45
[root@test1 scripts]# date -d "-24 hour" +"%Y-%m-%d %H:%M:%S"
2011-11-22 16:23:50
[root@test1 scripts]# date -d "-1 week" +"%Y-%m-%d %H:%M:%S"
2011-11-16 16:23:53
[root@test1 scripts]# date -d "-60 minute" +"%Y-%m-%d %H:%M:%S"
2011-11-23 15:24:36
[root@test1 scripts]# date -d "-1 month" +"%Y-%m-%d %H:%M:%S"
2011-10-23 16:25:00


查看文件编码
NAME
       file - determine file type



#############################################################
#获取本机ip列表
ifconfig|grep -w "inet addr"|sed -e 's/ .*inet addr://' -e 's/ .*//'

#############################################################
#以多条command或者函数作为if条件(这样就不用自己判断返回值了)
if
    command1
    command2
    ...
then
    do sth.
else
    do other sth.
fi

#############################################################
#去掉行首空格和Tab
sed -e's/^[ ]*//' -e's/\t//'

#############################################################
#以指定域为关键域排序
sort
       -k, --key=POS1[,POS2]
              start a key at POS1, end it at POS2 (origin 1)
       -t, --field-separator=SEP
              use SEP instead of non-blank to blank transition
       +n
              忽略前n个域,按第n+1个域排序(有些服务器不可用)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值