美文网首页shell程序员
Shell使用技巧和常用命令

Shell使用技巧和常用命令

作者: swapmem | 来源:发表于2017-02-03 21:22 被阅读24次

shell usage tips

  • ctrl + w
    delete a word before cursor

  • ctrl + a
    cursor move to beginning

  • ctrl + r
    search for history command

  • ctrl + k
    delete characters after cursor

  • ctrl + u
    delete the whole line

  • ctrl + e
    move to the end of line

  • ctrl + b
    move back one character

  • ctrl + f
    move forward one character

  • use bash -x scriptname to debug and see what is under going

shell command

  • find
    commonly used switches:
    [ -name , -iname] -iname ignoring case sensitive
    [-size] +20M, -5G
    [-atime, -ctime, -mtime] unit is day +2 1 -3
    [-amin, -cmin, -mmin] unit is minute +2 1 -3
    [-type] f: regular file d: directory
    [-print0] process with filename contains null character
    [-maxdepth, -mindepth] find at most/least level

  • xargs
    [-0] process with filename contains null character
    [-Ireplace_str] eg: xargs -Ifile ls -l file
    [-P] how many processed to execute command, if specified with 0, run as many process as possible to deal with.
    [-r] don't exec command if standard input is empty

  • combine find and xargs
    eg:
    find /tmp -maxdepth 1 -type f -name \* -print0 | xargs -0 -P 0 -Ifile cp file ~/jk
    descrption:
    find all regular files in /tmp(not include subdirs) and copy them to jk directory as fast as possible

  • grep
    [-r] search recursively(include subdirs)
    [-i] ignore case sensitive
    [-w] match the whole world
    [-n] print the line number that matches
    [-v] invert match
    [-c] count how many matches

  • lsof

[-u] list all files that a user opened
[-i] list all processes that use a specific port. eg: ls -i TCP:22
[-p] list all opened files by process ID
[-c] find out files opened by some particular daemon
[lsof /path/to/file] list processes opened by specific file

  • netstat
    [-a] list all connections
    [-t] list tcp connections
    [-u] list udp connections
    [-l] list sockets in listening state
    [-p] show the PID and name of the program to which each socket belongs.
    [netstat -tulpn] frequently used combinations
  • du
    [-sh] the size of a file. eg: du -sh Documents

reference:

  1. http://www.thegeekstuff.com/2012/08/lsof-command-examples
  2. http://www.ibm.com/developerworks/aix/library/au-lsof.html
  3. http://webcache.googleusercontent.com/search?q=cache:http://www.unixmantra.com/2013/12/xargs-all-in-one-tutorial-guide.html

相关文章

  • Shell使用技巧和常用命令

    shell usage tips ctrl + wdelete a word before cursor ctrl...

  • Shell参考资料

    shell 目录 Shell简介 Shell常用命令 Shell里面的括号 Shell里面的单引号和双引号 She...

  • Shell命令汇总

    1、一般常用命令 (1)Shell 常用命令总结 (2)Shell的18条常用命令整理 2、文件操作常用命令 (1...

  • HBASE SHELL常用命令

    HBASE SHELL常用命令 标签: HBase Shell 1. 进入hbase shell console ...

  • Shell 的基本使用

    这里使用的是Bash 概要语法 小技巧 当前执行shell文件的位置 参考 shell教程

  • Linux Shell: 各种tips

    通用Linux中执行shell脚本的4种方法总结hbase shell基础和常用命令详解 2.字符串Shell脚本...

  • Linux shell基本功

    使用Linux shell是我每天的基本工作,但我经常会忘记一些有用的shell命令和l技巧。当然,命令我能记住,...

  • Shell脚本

    shell脚本学习笔记 shell命令的组合运用 常用命令组合

  • shell 使用技巧

    Ctrl +a :跳至命令首Ctrl +e:跳至命令尾Ctrl+ 左右键:以单词为单元跳Ctrl+u:删除光标前命...

  • Linux Shell 动态生成 数组系列 Seq 使用技巧

    Linux Shell 动态生成 数组系列 Seq 使用技巧 如果对linux shell 数组不是很熟悉的话,请...

网友评论

    本文标题:Shell使用技巧和常用命令

    本文链接:https://www.haomeiwen.com/subject/rhhvpttx.html