Category: Life

  • vim打开文件

    vim 打开文件并跳到最后一行

    vim + filename

    vim 打开文件并跳到指定行

    vim +n filename

    vim 打开两个文件,并以 vsplit 显示

    vim -O file1 file2

    vim 打开两个文件,并以 split 显示

    vim -o file1 file2

    save all

    :wqa
    

    vim can open .zip, .tar.gz files, to prview the filenames in side the package.

  • 查看nfs的挂载情况

    对于 nfs server ,查看有哪些客户端连过来

    showmount -a
  • linux desktop reboot shutdown hang处理

    linux desktop 当点击重启或关机,或通过命令,都会卡在

    restarting system
    shutting down system

    解决办法:

    centos 7 为例

    编辑

    sudo vim /etc/grub2.cfg

    在启动项一行最后添加 reboot=bios

    inux16 /boot/vmlinuz-3.10.0-123.el7.x86_64 root=UUID=e27de799-ef92-4a09-99cf-dde69fe13e88 ro vconsole.keymap=us crashkernel=auto vconsole.font=latarcyrheb-sun16 rhgb quiet reboot=bios

    参考:http://linux.koolsolutions.com/2009/08/04/howto-fix-linux-hangfreeze-during-reboots-and-restarts/

  • git clone很大的 repo

    如果一个 git 库有太长的 history,clone 一份需要好长时间,那么可以考虑不 clone 太长的 history.

    git clone --depth depth remote-url

    例如

    git clone --depth 2 https://github.com/torvalds/linux.git

    这样git log 只会看到两条记录

    参考:http://blogs.atlassian.com/2014/05/handle-big-repositories-git/

  • 多节点梯子择优脚本

    [jpuyy@jpuyy-laptop allconf]$ cat tizi.sh 
    #/bin/bash
    
    suffix='.heredance.com'
    
    locations='jp1 jp2 jp3 us1 us2 us3 us4 us5 sg1 sg2 hk1 hk2 tw1 uk1'
    
    result_file='/tmp/.result_array'
    
    > $result_file
    for location in $locations;
    do
        result=`ping -q -A -c 10 $location$suffix | grep received`
        echo "$location$suffix $result" >> $result_file
    done
    
    cat $result_file | sort -r -n -k 5 -k 11
    
  • vim删除空行和注释

    删除空行

    :g/^$/d

    删除空行以及只有空格的行

    :g/^\s*$/d

    删除以 # 开头或 空格# 或 tab#开头的行

    :g/^\s*#/d

    对于 php.ini 配置文件,注释为 ; 开头

    :g/^\s*;/d

    使用正则表达式删除行

    如果当前行包含 bbs ,则删除当前行

    :/bbs/d

    删除从第二行到包含 bbs 的区间行

    :2,/bbs/d

    删除从包含 bbs 的行到最后一行区间的行

    :/bbs/,$d

    删除所有包含 bbs 的行

    :g/bbs/d

    删除匹配 bbs 且前面只有一个字符的行

    :g/.bbs/d

    删除匹配 bbs 且以它开头的行

    :g/^bbs/d

    删除匹配 bbs 且以它结尾的行

    :g/bbs$/d

    .ini 的注释是以 ; 开始的,如果注释不在行开头,那么删除 ; 及以后的字符

    :%s/\;.\+//g

    删除 # 之后所有字符

    %s/\#.*//g

    删除行尾多余的空格

    %s/ \s*$//g