bash 学习

 

1. HISTTIMEFORMAT 变量:bash3.0推出的新变量,记录历史命令的执行时间

    譬如:HISTTIMEFORMAT="[%F %T]"

    执行history,显示:

    490  [2008-07-16 15:12:23]HISTTIMEFORMAT="[%F %T]"
    491  [2008-07-16 15:12:25]history
    492  [2008-07-16 15:12:32]man date

 

2. date 命令和strftime 函数,扩展clock、hwclock

     date命令:print or set the system date and time

     strftime函数:awk调用了类型为time_t的c函数库  strftime([format [, timestamp]])

            功能:Formats  timestamp  according to the specification in format.

     systime函数:同上,Returns the current time of day  as  the  number  of  seconds since the Epoch   systime()

     譬如:设置系统时间:date -s "12/29/2008 18:00:00"

             display系统时间:date -d  "+3 day" + "%F %T"   date -d  "-3 years" + "%F %T"

             毫秒级时间戳->格式化时间:echo 12879350 | awk '{print strftime("%F %T", $0)}'

             格 式化时间->毫秒级时间戳:date -s把当前时间设置成special time,然后 awk '{print systime()}'即可 如:echo "05/05/2008" |awk '{print systime()}'

 

3.扩展的正则表达式- extended expression

     包括:    ()    |    +    ?         譬如:(a|b|c)+d?

     grep只支持basic regexp,egrep支持extended regexp,所以() | + ?只在egrep中有效,或者grep -E
     sed无效,sed -r有效;awk有效。看man手册即可
 
4. ps命令中的status状态 bash3.0以上支持(kernel 2.6以上)
    D Uninterruptible sleep (usually IO) 
    R Running or runnable (on run queue) 运行中
    S Interruptible sleep (waiting for an event to complete) 可打断的后台进程,类似守护进程httpd、ntpd、crond等
    T Stopped, either by a job control signal or because it is being traced. 
    W paging (not valid since the 2.6.xx kernel) 
    X dead (should never be seen) 
    Z Defunct ("zombie") process, terminated but not reaped by its parent. 

    For BSD formats and when the stat keyword is used, additional characters may be displayed: 
    < high-priority (not nice to other users) 高优先级
    N low-priority (nice to other users) 低优先级
    L has pages locked into memory (for real-time and custom IO) 
    s is a session leader 主进程
    l  is multi-threaded (using CLONE_THREAD, like NPTL pthreads do) 表示线程
    + is in the foreground process group 前台运行
 
    譬如:ps -axuf后status column中:Ss表示父进程、R+正在前台运行的进程、SN表示低优先级的进程,S+、Sl表示线程、SL等

5. su和login shell
    login shell会执行/etc/profile和.bash_profile,/etc/bashrc和.bashrc
    non-login shell则仅执行/etc/bashrc和.bashrc
    查看su的man手册,su - 切换用户将会使用login shell;不带-的话,则会使用non-login shell
    PS:在RHEL下,辨别login和non-login shell另外一种方法是:exit命令后如果会清屏则是login shell,反之则是non-login shell

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值