Blog

  • time命令

    time命令用于计算一个命令执行的时间

    例如sleep 2运行时间是2秒钟

    /usr/bin/time sleep 2
    0.00user 0.00system 0:02.00elapsed 0%CPU (0avgtext+0avgdata 2656maxresident)k
    0inputs+0outputs (0major+211minor)pagefaults 0swaps

    time后面可以加很多参数,如-o output.txt将结果输出到文件

    /usr/bin/time -o output.txt sleep 2

    -f “%P” command 可以按需求输出cpu使用率

    /usr/bin/time -f "%P cpu percentage" find ./ -name abc

     -f “%M” command 可以按需求输出内存使用率,

    /usr/bin/time -f "%M Max Resident Set Size (Kb)" find ./ -name abc

    -f “%e” command 按秒输出命令执行的时间

    /usr/bin/time -f "%e running time (sec)" find ./ -name abc

    参考

    12 UNIX / Linux Time Command Output Format Option Examples

  • python安装simplejson

    没有安装simplejson时报错

    >>> import simplejson

    Traceback (most recent call last):

      File “<stdin>”, line 1, in <module>

    ImportError: No module named simplejson

    simplejson是ansible一个很重要的依赖,经测试在python 2.4.3及以上版本都可以用python setup.py install 安装成功。

    方法一:

    yum install python-simplejson -y

    方法二:

    wget https://pypi.python.org/packages/source/s/simplejson/simplejson-3.5.2.tar.gz#md5=10ff73aa857b01472a51acb4848fcf8b --no-check-certificate
    tar vxzf simplejson-3.5.2.tar.gz
    cd simplejson-3.5.2
    python setup.py install

    方法三:

    pip install simplejson

    方法四:

    easy_install simplejson
  • 番茄工作法笔记

    如果一项任务的估测值大于 5 到 7 个番茄,那么就打散它。
    如果一项任务的估测值小于一个番茄,就把几个小任务组合成一个大任务。

  • python查看已经安装的模块

    方法一:

    
    >>> help('modules')
    
    Please wait a moment while I gather a list of all available modules...
    
    ....
    
    Enter any module name to get more help.  Or, type "modules spam" to search
    
    for modules whose descriptions contain the word "spam".
    

    方法二:

    >>> import sys
    
    >>> sys.modules
    
  • vim插入当前日期

    在normal模式下,直接执行

    !!date

    如果要显示YYYY-MM-DD,需要跟%F,%需要用\转义

    !!date +\%F

    也可以使用:r!读取date命令

    :r! date "+\%Y-\%m-\%d \%H:\%M:\%S"

    区别是!!date会将当前行替换成当前日期,:r!date会新建一行并插入当前日期。

  • mac linux usb console线连交换机

    一般usb转console线的参数如下

     波特率 9600
     数据位 8
     奇偶校验None
     停止位 1

    osx自带screen命令,usb console线插在mac上之后,在/dev/下会认到这个线的编号。

    /dev/cu.usbserial-xxxxxx
    /dev/tty.usbserial-xxxxxx

    接下来执行下面的命令即可,9600是波特率

    screen /dev/tty.usbserial-A4006Jvo 9600

    补充:

    linux 下使用 screen 连接 console

    通过 lsusb 查看插上去的线能被识别到,然后默认到 com1 口连接,如 /etc/ttyS0 ,使用如下命令接到交换机。

    screen /dev/ttyS0