shell常用代码块

来源:互联网 发布:淘宝耐克正品店铺 贴吧 编辑:程序博客网 时间:2024/05/17 22:49

获取系统当前时间戳

current=`date "+%Y-%m-%d %H:%M:%S"`  timeStamp=`date -d "$current" +%s`   currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) #将current转换为时间戳,精确到毫秒  echo $currentTimeStamp  

将终端的输出重定向到文件

[Shell 输入/输出重定向](http://www.runoob.com/linux/linux-shell-io-redirections.html)

截取字符串中的数字

echo "2014年7月21日" | tr -cd "[0-9]"

shell的字符串和数字的转化(数字自动做字符串处理,变量名做字符串输出用单引号)

http://blog.csdn.net/longshenlmj/article/details/14166193

管道文件读取得坑

http://sunlujing.iteye.com/blog/1918907

Shell编程中的数组定义、遍历

http://blog.csdn.net/xujingzhong0077/article/details/53667279

expr,怎么老提示non-numeric argument错误

export 不支持浮点运算
https://zhidao.baidu.com/question/2118037328359190867.html

linux shell 实现 四则运算(整数及浮点) 简单方法

http://www.cnblogs.com/chengmo/archive/2010/09/30/1839556.html

如果文件存在 删除

if [ -e $FILE ]then    rm -f $FILEfi

shell休眠sleep

  1. 方法1. sleep 0.01
  2. 方法2.usleep 10000 (usleep为十的负六次方秒,详细见man usleep)

$# -lt 4

$# 取得shell脚本参数个数,-lt  即 less than,小于$0 取得脚本名称(包含路径)

if [ -z ${BASEDIR} ];then

判断变量是否为空

使用sh -x调试shell脚本

http://blog.chinaunix.net/uid-20564848-id-73502.html

sehll 获取文件锁

http://www.jb51.net/article/58757.htm

开启http服务

python -m SimpleHTTPServer 8004

检查参数个数

if [ $# -lt 7 ];then

shell 常用判断

-d :判断制定的是否为目录-z:判断制定的变量是否存在值-f:判断制定的是否为文件-L:判断制定的是否为符号链接-r:判断制定的是否可读-s:判断存在的对象长度是否为0-w:判断制定的是否可写-x:判断存在的对象是否可以执行!:测试条件的否定符号
原创粉丝点击