随笔分类 - Shell
摘要:工作中经常在shell脚本中看到set的这两个用法,但就像生活中的很多事情,习惯导致忽视,直到出现问题才引起关注。1. set -eset命令的-e参数,linux自带的说明如下:"Exit immediately if a simple command exits with a non-zero
阅读全文
摘要:UNIX/Linux Commands You can use the following tools: dos2unix (also known as fromdos) – converts text files from the DOS format to the Unixformat unix
阅读全文
摘要:dd this to the beginning of the script: This will cause the shell to exit immediately if a simple command exits with a nonzero exit value. A simple co
阅读全文
摘要:第一种:〔 Python 与 Bash Shell 的结合 〕这个命令会让你输入一个字符串,然后会再输出一串加密了的数字。加密代码[照直输入]:python -c 'print reduce(lambda a,b: a*256+ord(b), raw_input("string: "), 0)'解密
阅读全文
摘要:https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash One way to do it is: As pointed out in the comments, this ha
阅读全文
摘要:You can use file redirection to redirected the sorted output: Or you can use the -o, --output=FILE option of sort to indicate the same input and outpu
阅读全文
摘要:shell下获取系统时间的方法直接调用系统变量 获取今天时期:`date +%Y%m%d` 或 `date +%F` 或 $(date +%y%m%d) 获取昨天时期:`date -d yesterday +%Y%m%d` 获取前天日期:`date -d -2day +%Y%m%d` 依次类推比如获
阅读全文
摘要:Linux Shell中写循环时,常常要用到变量的自增,现在总结一下整型变量自增的方法。我所知道的,bash中,目前有五种方法:1. i=`expr $i + 1`;2. let i+=1;3. ((i++));4. i=$[$i+1];5. i=$(( $i + 1 ))可以实践一下,简单的实例如
阅读全文
摘要:shell的逻辑运算符 涉及有以下几种类型,因此只要适当选择,可以解决我们很多复杂的判断,达到事半功倍效果。 一、逻辑运算符 二、逻辑表达式 test 命令 使用方法:test EXPRESSION 如: [root@localhost ~]# test 1 = 1 && echo 'ok'ok [
阅读全文
摘要:twoDayAgoTime=`date -d \`date -d "-2 day" +%Y%m%d\` +%s` sevenDayAgoTime=`date -d \`date -d "-7 day" +%Y%m%d\` +%s`
阅读全文
摘要:我使用过的Linux命令之basename - 去掉文件名的目录和后缀 本文链接:http://codingstandards.iteye.com/blog/840784 (转载请注明出处) 用途说明 basename命令用于去掉文件名的目录和后缀(strip directory and suffi
阅读全文
摘要:continue — Skip to the next iteration of a loop in a shell script
阅读全文
摘要:1 日期加减方法可实现当天的日期加减,指定日期的加减,天周月年。 只判断yymmdd的秒 twoDayAgoTime=`date -d \`date -d "-2 day" +%Y%m%d\` +%s`sevenDayAgoTime=`date -d \`date -d "-7 day" +%Y%m
阅读全文
摘要:Is there a TRY CATCH command in Bash? No. Bash doesn't have as many luxuries as one can find in many programming languages. There is no try/catch in b
阅读全文
摘要:tar命令详解 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个。 下面的参数是根据需要在压缩或解压档案时可选的。 -z:有gzip属性的 -j:有bz2属
阅读全文
摘要:sed -i '51,54d' filename
阅读全文
摘要:If you want to delete lines 5 through 10 and 12: This will print the results to the screen. If you want to save the results to the same file: This wil
阅读全文
摘要:2013-04-08 17:40:47 shell中&&和||的使用方法 &&运算符: command1 && command2 &&左边的命令(命令1)返回真(即返回0,成功被执行)后,&&右边的命令(命令2)才能够被执行;换句话说,“如果这个命令执行成功&&那么执行这个命令”。 语法格式如下:
阅读全文
摘要:You are using | (pipe) to direct the output of a command into another command. What you are looking for is && operator to execute the next command onl
阅读全文

浙公网安备 33010602011771号