• Linux 命令行的配置


    Linux terminal 或许是Linux 上最频繁用到的工具之一。有个用的顺手的命令行,大大提高工作生活效率。

    下面来看看:

    1. 命令行提示符号

       通过定义一组预先定义好的一组值,以及控制PS1 和PS2 环境变量来控制提示符号.

       echo $PS1

      通过修改直接生效。比如让命令行来显示命令的行号。  

        export PS1="\#" 来显示命令行号

      可以通过man bash 开查看,搜key world: PS1

    2. tab 补全

       补全文集名,补全命令,补全环境变量都支持。 double press Tab key.

    3. 命令行的中位置跳转和编辑

        比如从当前位置(光标)返回到行头或者行尾,向前跳转一个单词或者向后,如果vim 里面的快捷键。

        有很多功能支持,可以通过bind -p 来查看。 同时也可以修改到.bash.rc 文件中保存。

     常用的: 获得上次运行的参数,比如C-1, M-.(也就是上一次运行命令的第一个参数)

      M-. 缺省获得上次运行的最后一个参数。

      M-#( Alt-Shift-3) 可以将该命令给注释掉。

      C-a / C-e 移动到行头或者行尾。

      C-w 删掉之前一个单词。 当然这些都可以设置成适合自己的键。

       还有命令行扩展 : M-*'(insert-completions)

       可以将 ls t* 扩展为 ls test.txt test.cpp.(假设当前目录有连个以test开头的我文件名)

        'C-x*'(先按ctrl-x,然后按*) 也可以补全(glob-expand-word)

       ls *.txt  将扩展为 ls test.txt log.txt (假设当前目录只有连个以txt为后缀的文件名)

    "\C-g": abort
    "\C-x\C-g": abort
    "\e\C-g": abort
    "\C-j": accept-line
    "\C-m": accept-line
    # alias-expand-line (not bound)
    # arrow-key-prefix (not bound)
    # backward-byte (not bound)
    "\C-b": backward-char
    "\eOD": backward-char
    "\e[D": backward-char
    "\C-h": backward-delete-char
    "\C-?": backward-delete-char
    "\C-x\C-?": backward-kill-line
    "\e\C-h": backward-kill-word
    "\e\C-?": backward-kill-word
    "\eb": backward-word
    "\e<": beginning-of-history
    "\C-a": beginning-of-line
    "\eOH": beginning-of-line
    "\e[H": beginning-of-line
    "\C-xe": call-last-kbd-macro
    "\ec": capitalize-word
    "\C-]": character-search
    "\e\C-]": character-search-backward
    "\C-l": clear-screen
    "\C-i": complete
    "\e\e": complete
    "\e!": complete-command
    "\e/": complete-filename
    "\e@": complete-hostname
    "\e{": complete-into-braces
    "\e~": complete-username
    "\e$": complete-variable
    # copy-backward-word (not bound)
    # copy-forward-word (not bound)
    # copy-region-as-kill (not bound)
    # dabbrev-expand (not bound)
    "\C-d": delete-char
    "\e[3~": delete-char
    # delete-char-or-list (not bound)
    "\e\\": delete-horizontal-space
    "\e-": digit-argument
    "\e0": digit-argument
    "\e1": digit-argument
    "\e2": digit-argument
    "\e3": digit-argument
    "\e4": digit-argument
    "\e5": digit-argument
    "\e6": digit-argument
    "\e7": digit-argument
    "\e8": digit-argument
    "\e9": digit-argument
    "\C-x\C-v": display-shell-version
    "\C-xA": do-lowercase-version
    "\C-xB": do-lowercase-version
    "\C-xC": do-lowercase-version
    "\C-xD": do-lowercase-version
    "\C-xE": do-lowercase-version
    "\C-xF": do-lowercase-version
    "\C-xG": do-lowercase-version
    "\C-xH": do-lowercase-version
    "\C-xI": do-lowercase-version
    "\C-xJ": do-lowercase-version
    "\C-xK": do-lowercase-version
    "\C-xL": do-lowercase-version
    "\C-xM": do-lowercase-version
    "\C-xN": do-lowercase-version
    "\C-xO": do-lowercase-version
    "\C-xP": do-lowercase-version
    "\C-xQ": do-lowercase-version
    "\C-xR": do-lowercase-version
    "\C-xS": do-lowercase-version
    "\C-xT": do-lowercase-version
    "\C-xU": do-lowercase-version
    "\C-xV": do-lowercase-version
    "\C-xW": do-lowercase-version
    "\C-xX": do-lowercase-version
    "\C-xY": do-lowercase-version
    "\C-xZ": do-lowercase-version
    "\eA": do-lowercase-version
    "\eB": do-lowercase-version
    "\eC": do-lowercase-version
    "\eD": do-lowercase-version
    "\eE": do-lowercase-version
    "\eF": do-lowercase-version
    "\eG": do-lowercase-version
    "\eH": do-lowercase-version
    "\eI": do-lowercase-version
    "\eJ": do-lowercase-version
    "\eK": do-lowercase-version
    "\eL": do-lowercase-version
    "\eM": do-lowercase-version
    "\eN": do-lowercase-version
    "\eP": do-lowercase-version
    "\eQ": do-lowercase-version
    "\eR": do-lowercase-version
    "\eS": do-lowercase-version
    "\eT": do-lowercase-version
    "\eU": do-lowercase-version
    "\eV": do-lowercase-version
    "\eW": do-lowercase-version
    "\eX": do-lowercase-version
    "\eY": do-lowercase-version
    "\eZ": do-lowercase-version
    "\el": downcase-word
    # dump-functions (not bound)
    # dump-macros (not bound)
    # dump-variables (not bound)
    "\e\C-i": dynamic-complete-history
    "\C-x\C-e": edit-and-execute-command
    # emacs-editing-mode (not bound)
    "\C-x)": end-kbd-macro
    "\e>": end-of-history
    "\C-e": end-of-line
    "\eOF": end-of-line
    "\e[F": end-of-line
    "\C-x\C-x": exchange-point-and-mark
    # forward-backward-delete-char (not bound)
    # forward-byte (not bound)
    "\C-f": forward-char
    "\eOC": forward-char
    "\e[C": forward-char
    "\C-s": forward-search-history
    "\ef": forward-word
    "\eg": glob-complete-word
    "\C-x*": glob-expand-word
    "\C-xg": glob-list-expansions
    # history-and-alias-expand-line (not bound)
    "\e^": history-expand-line
    # history-search-backward (not bound)
    # history-search-forward (not bound)
    "\e#": insert-comment
    "\e*": insert-completions
    "\e.": insert-last-argument
    "\e_": insert-last-argument
    # kill-line (not bound)
    "\C-k": kill-region
    # kill-whole-line (not bound)
    "\ed": kill-word
    # magic-space (not bound)
    # menu-complete (not bound)
    # menu-complete-backward (not bound)
    "\C-n": next-history
    "\eOB": next-history
    "\e[B": next-history
    "\en": non-incremental-forward-search-history
    # non-incremental-forward-search-history-again (not bound)
    "\ep": non-incremental-reverse-search-history
    # non-incremental-reverse-search-history-again (not bound)
    # old-menu-complete (not bound)
    "\C-o": operate-and-get-next
    # overwrite-mode (not bound)
    "\C-x!": possible-command-completions
    "\e=": possible-completions
    "\e?": possible-completions
    "\C-x/": possible-filename-completions
    "\C-x@": possible-hostname-completions
    "\C-x~": possible-username-completions
    "\C-x$": possible-variable-completions
    "\C-p": previous-history
    "\eOA": previous-history
    "\e[A": previous-history
    "\C-q": quoted-insert
    "\C-v": quoted-insert
    # redraw-current-line (not bound)
    "\C-x\C-r": re-read-init-file
    "\C-r": reverse-search-history
    "\e\C-r": revert-line
    "\er": revert-line
    " ": self-insert
    "!": self-insert
    "\"": self-insert
    "#": self-insert
    "$": self-insert
    "%": self-insert
    "&": self-insert
    "'": self-insert
    "(": self-insert
    ")": self-insert
    "*": self-insert
    "+": self-insert
    ",": self-insert
    "-": self-insert
    ".": self-insert
    "/": self-insert
    "0": self-insert
    "1": self-insert
    "2": self-insert
    "3": self-insert
    "4": self-insert
    "5": self-insert
    "6": self-insert
    "7": self-insert
    "8": self-insert
    "9": self-insert
    ":": self-insert
    ";": self-insert
    "<": self-insert
    "=": self-insert
    ">": self-insert
    "?": self-insert
    "@": self-insert
    "A": self-insert
    "B": self-insert
    "C": self-insert
    "D": self-insert
    "E": self-insert
    "F": self-insert
    "G": self-insert
    "H": self-insert
    "I": self-insert
    "J": self-insert
    "K": self-insert
    "L": self-insert
    "M": self-insert
    "N": self-insert
    "O": self-insert
    "P": self-insert
    "Q": self-insert
    "R": self-insert
    "S": self-insert
    "T": self-insert
    "U": self-insert
    "V": self-insert
    "W": self-insert
    "X": self-insert
    "Y": self-insert
    "Z": self-insert
    "[": self-insert
    "\\": self-insert
    "]": self-insert
    "^": self-insert
    "_": self-insert
    "`": self-insert
    "a": self-insert
    "b": self-insert
    "c": self-insert
    "d": self-insert
    "e": self-insert
    "f": self-insert
    "g": self-insert
    "h": self-insert
    "i": self-insert
    "j": self-insert
    "k": self-insert
    "l": self-insert
    "m": self-insert
    "n": self-insert
    "o": self-insert
    "p": self-insert
    "q": self-insert
    "r": self-insert
    "s": self-insert
    "t": self-insert
    "u": self-insert
    "v": self-insert
    "w": self-insert
    "x": self-insert
    "y": self-insert
    "z": self-insert
    "{": self-insert
    "|": self-insert
    "}": self-insert
    "~": self-insert
    "\200": self-insert
    "\201": self-insert
    "\202": self-insert
    "\203": self-insert
    "\204": self-insert
    "\205": self-insert
    "\206": self-insert
    "\207": self-insert
    "\210": self-insert
    "\211": self-insert
    "\212": self-insert
    "\213": self-insert
    "\214": self-insert
    "\215": self-insert
    "\216": self-insert
    "\217": self-insert
    "\220": self-insert
    "\221": self-insert
    "\222": self-insert
    "\223": self-insert
    "\224": self-insert
    "\225": self-insert
    "\226": self-insert
    "\227": self-insert
    "\230": self-insert
    "\231": self-insert
    "\232": self-insert
    "\233": self-insert
    "\234": self-insert
    "\235": self-insert
    "\236": self-insert
    "\237": self-insert
    " ": self-insert
    "¡": self-insert
    "¢": self-insert
    "£": self-insert
    "€": self-insert
    "¥": self-insert
    "Š": self-insert
    "§": self-insert
    "š": self-insert
    "©": self-insert
    "ª": self-insert
    "«": self-insert
    "¬": self-insert
    "­": self-insert
    "®": self-insert
    "¯": self-insert
    "°": self-insert
    "±": self-insert
    "²": self-insert
    "³": self-insert
    "Ž": self-insert
    "µ": self-insert
    "¶": self-insert
    "·": self-insert
    "ž": self-insert
    "¹": self-insert
    "º": self-insert
    "»": self-insert
    "Œ": self-insert
    "œ": self-insert
    "Ÿ": self-insert
    "¿": self-insert
    "À": self-insert
    "Á": self-insert
    "Â": self-insert
    "Ã": self-insert
    "Ä": self-insert
    "Å": self-insert
    "Æ": self-insert
    "Ç": self-insert
    "È": self-insert
    "É": self-insert
    "Ê": self-insert
    "Ë": self-insert
    "Ì": self-insert
    "Í": self-insert
    "Î": self-insert
    "Ï": self-insert
    "Ð": self-insert
    "Ñ": self-insert
    "Ò": self-insert
    "Ó": self-insert
    "Ô": self-insert
    "Õ": self-insert
    "Ö": self-insert
    "×": self-insert
    "Ø": self-insert
    "Ù": self-insert
    "Ú": self-insert
    "Û": self-insert
    "Ü": self-insert
    "Ý": self-insert
    "Þ": self-insert
    "ß": self-insert
    "à": self-insert
    "á": self-insert
    "â": self-insert
    "ã": self-insert
    "ä": self-insert
    "å": self-insert
    "æ": self-insert
    "ç": self-insert
    "è": self-insert
    "é": self-insert
    "ê": self-insert
    "ë": self-insert
    "ì": self-insert
    "í": self-insert
    "î": self-insert
    "ï": self-insert
    "ð": self-insert
    "ñ": self-insert
    "ò": self-insert
    "ó": self-insert
    "ô": self-insert
    "õ": self-insert
    "ö": self-insert
    "÷": self-insert
    "ø": self-insert
    "ù": self-insert
    "ú": self-insert
    "û": self-insert
    "ü": self-insert
    "ý": self-insert
    "þ": self-insert
    "ÿ": self-insert
    "\C-@": set-mark
    "\e ": set-mark
    # shell-backward-kill-word (not bound)
    # shell-backward-word (not bound)
    "\e\C-e": shell-expand-line
    # shell-forward-word (not bound)
    # shell-kill-word (not bound)
    # skip-csi-sequence (not bound)
    "\C-x(": start-kbd-macro
    # tab-insert (not bound)
    "\e&": tilde-expand
    "\C-t": transpose-chars
    "\et": transpose-words
    # tty-status (not bound)
    "\C-x\C-u": undo
    "\C-_": undo
    # universal-argument (not bound)
    # unix-filename-rubout (not bound)
    "\C-u": unix-line-discard
    "\C-w": unix-word-rubout
    "\eu": upcase-word
    # vi-append-eol (not bound)
    # vi-append-mode (not bound)
    # vi-arg-digit (not bound)
    # vi-back-to-indent (not bound)
    # vi-bword (not bound)
    # vi-bWord (not bound)
    # vi-change-case (not bound)
    # vi-change-char (not bound)
    # vi-change-to (not bound)
    # vi-char-search (not bound)
    # vi-column (not bound)
    # vi-complete (not bound)
    # vi-delete (not bound)
    # vi-delete-to (not bound)
    # vi-editing-mode (not bound)
    # vi-end-word (not bound)
    # vi-eof-maybe (not bound)
    # vi-eword (not bound)
    # vi-eWord (not bound)
    # vi-fetch-history (not bound)
    # vi-first-print (not bound)
    # vi-fword (not bound)
    # vi-fWord (not bound)
    # vi-goto-mark (not bound)
    # vi-insert-beg (not bound)
    # vi-insertion-mode (not bound)
    # vi-match (not bound)
    # vi-movement-mode (not bound)
    # vi-next-word (not bound)
    # vi-overstrike (not bound)
    # vi-overstrike-delete (not bound)
    # vi-prev-word (not bound)
    # vi-put (not bound)
    # vi-redo (not bound)
    # vi-replace (not bound)
    # vi-rubout (not bound)
    # vi-search (not bound)
    # vi-search-again (not bound)
    # vi-set-mark (not bound)
    # vi-subst (not bound)
    # vi-tilde-expand (not bound)
    # vi-yank-arg (not bound)
    # vi-yank-to (not bound)
    "\C-y": yank
    "\e.": yank-last-arg
    "\e_": yank-last-arg
    "\e\C-y": yank-nth-arg
    "\ey": yank-pop
    

    4. alias
      别名,对于经常用到的自定义命令可以用shellout方式封装一下,或者最简单的就是别名。

    5.  配置文件

       上面这些都个放到配置文件里,避免一次有一次的修改. 放在.bashrc 中,同时在.profile 文件里面调用bashrc.

       进一步可以把这个文件放到云上面去,通过One Ubuntu 来同步不同计算机之间被的配置文件。 这样所有的机器,即使从新装机,也不用怕配额之文件丢失,也不用再去修改。

    强烈建议做这么一次,公欲利其事必先利其器:)

    reference:

    http://www.kerneltravel.net/newbie/bash_readline.htm

  • 相关阅读:
    BZOJ
    BZOJ
    BZOJ
    BZOJ
    BZOJ
    BZOJ
    [知识点]平衡树之Splay
    [BZOJ1015/JSOI2008]星球大战
    [知识点]状态压缩DP
    [NOIP2011]聪明的质检员
  • 原文地址:https://www.cnblogs.com/zhyg6516/p/2026153.html
Copyright © 2020-2023  润新知