获取指定时间相对当前时间的时间差的文字描述

#!/bin/sh rt() { time=$(date -d "${1}" +%s) curr=$(date +%s) shift=$(($curr - $time)); if [ $shift -lt 45 ]; then diff="$shift" term="second" # 45 秒前 elif [ $shift -lt 2700 ]; then diff="$(($shift / 60))" term="minute" # 45 分钟前 elif [ $shift -lt 64800 ]; then diff="$(($shift / 60 / 60))" term="hour" # 18 小时前 elif [ $shift -lt 518400 ]; then diff="$(($shift / 60 / 60 / 24))" term="day" # 6 天前 elif [ $shift -lt 1814400 ]; then diff="$(($shift / 60 / 60 / 24))" term="week" # 3 周前 (21 天前) fi if [ $diff -gt 1 ]; then term=$term"s"; else diff="1"; fi echo "$diff $term ago"; }

2010-12-10 · wuan

about &

RT @http://www.ibm.com/developerworks/cn/linux/l-cn-nohup/ 这里还有一个关于 subshell 的小技巧。我们知道,将一个或多个命名包含在 “()” 中就 能让这些命令在子 shell中运行中,从而扩展出很多有趣的功能,我们现在要讨论的就是 其中之一。当我们将 “&” 也放入 “()” 内之后,我们就会发现所提交的作业并不在作业列 表中,也就是说,是无法通过 jobs 来查看的。让我们来看看为什么...

2009-08-19 · wuan

sh脚本中if条件

文件 含义 -r True if file exists and is readable -w True if file exists and is writable -x True if file exists and is executable -f True if file exists and is a regular file -d True if file exists and is a directory -c True if file exists and is a character special file -b True if file exists and is a block special file -p True if file exists and is a named pipe (FIFO) -u True if file exists and is a SETUID file -g True if file exists and is a SETGID file -k True if file exists and the sticky bit is set -s True if file exists and has a size greater than zero 逻辑 含义 ! Not -a And -o Or (has lower precedence that -a) ( )...

2007-03-03 · wuan

在fish里用find命令的 exec参数时

find -type f -exec dpkg -c "{}" \; | grep iso 为{}添加一对双引号,以前在 bash 下没有这个习惯

2007-02-07 · wuan

bash的快捷键

Ctrl+p 重复上一次命令 Ctrl+a 跳到第一个字符前 Ctrl+x 同上但再按一次会从新回到原位置 Ctrl+b 前移一个字符不删除字符情况下 Ctrl+h 删除前一个字符 Ctrl+u 删除提示符前的所有字符 Ctrl+w 同上 Ctrl+d 删除提示符后一个字符或exit或logout Ctrl+e 转到字符尾部 Ctrl+f 后移一个字符 Ctrl+k 删除提示符后全部字符 Ctrl+k 取消 Ctrl+r 向前查找用过的命令

2006-12-09 · wuan