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个域排序(有些服务器不可用)
NAME
SYNOPSIS
DESCRIPTION
EXAMPLES
[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
SYNOPSIS
DESCRIPTION
[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
#############################################################
#获取本机ip列表
ifconfig|grep -w "inet addr"|sed -e 's/ .*inet addr://' -e 's/ .*//'
#############################################################
#以多条command或者函数作为if条件(这样就不用自己判断返回值了)
if
then
else
fi
#############################################################
#去掉行首空格和Tab
sed -e's/^[ ]*//' -e's/\t//'
#############################################################
#以指定域为关键域排序
sort