企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
许多 Linux 发行版使用 BASH Shell,BSD 使用的是 tcsh,Bourne Shell 仅用于脚本。过滤器(Filter)非常有用并且可用于管道(pipe): - `grep`    模式匹配 - `sed`     查找并替换字符串或字符 - `cut`     从一个标记开始打印所指定列数据 - `sort`    按字母或数字排序 - `uniq`    删除一个文件中重复行 举个例子,一次使用所有命令: # ifconfig | sed 's/  / /g' | cut -d" " -f1 | uniq | grep -E "[a-z0-9]+" | sort -r # ifconfig | sed '/.*inet addr:/!d;s///;s/ .*//'|sort -t. -k1,1n -k2,2n -k3,3n -k4,4n sed 的模式字符串中的第一个字符是一个 tab。要在命令控制台中输入 tab,可以使用 ctrl-v ctrl-tab。 ## bash Bash、sh 的重定向和管道: # cmd 1> file                         # 重定向标准输出到 file。 # cmd 2> file                         # 重定向标准错误输出到 file。 # cmd 1>> file                        # 重定向标准输出并追加到 file。 # cmd &> file                         # 重定向标准输出和标准错误输出到 file。 # cmd >file 2>&1                      # 重定向标准错误输出到标准输出然后重定向到 file。 # cmd1 | cmd2                         # cmd1 的输出通过管道连接到 cmd2 的输入 # cmd1 2>&1 | cmd2                    # cmd1 的输出和错误输出通过管道连接到 cmd2 的输入 修改你的配置文件 ~/.bashrc (也可以是 ~/.bash_profile)。下列条目非常有用,使用". .bashrc"重新加载。 # in .bashrc bind '"\e[A"':history-search-backward # 使用上下键查找 bind '"\e[B"':history-search-forward  # 历史命令。无价之宝! set -o emacs                          # Set emacs mode in bash (看下面) set bell-style visible                # Do not beep, inverse colors     # 设置一个漂亮的提示符像 [user@host]/path/todir> PS1="\[\033[1;30m\][\[\033[1;34m\]\u\[\033[1;30m\]" PS1="$PS1@\[\033[0;33m\]\h\[\033[1;30m\]]\[\033[0;37m\]" PS1="$PS1\w\[\033[1;30m\]>\[\033[0m\]" # 要检查当前可用别名(alias),只需简单输入命令 aliasalias  ls='ls -aF'                     # 添加指示符(*/=>@| 其中之一)alias  ll='ls -aFls'                   # 清单alias  la='ls -all' alias ..='cd ..' alias ...='cd ../..' export HISTFILESIZE=5000              # 巨大的历史记录 export CLICOLOR=1                     # 使用颜色(如果可用) export LSCOLORS=ExGxFxdxCxDxDxBxBxExEx ## tcsh Tcsh、csh 的重定向和管道(> 和 >> 同 sh 中一样): # cmd >& file                         # 重定向标准输出和标准错误输出到 file。 # cmd >>& file                        # 追加标准输出和标准错误输出到 file。 # cmd1 | cmd2                         # cmd1 的输出通过管道连接到 cmd2 的输入 # cmd1 |& cmd2                        # cmd1 的输出和错误输出通过管道连接到 cmd2 的输入 Csh/tcsh 的设置在 `~/.cshrc` 中,使用"source .cshrc"来重新加载。例子: # in .cshrc alias  ls      'ls -aF' alias  ll      'ls -aFls' alias  la      'ls -all' alias  ..      'cd ..' alias  ...     'cd ../..' set   prompt    = "%B%n%b@%B%m%b%/> " # 像 user@host/path/todir>set   history   =  5000 set   savehist  = ( 6000 merge ) set   autolist                        # 控制命令补全和变量补全 set   visiblebell                     # 使用闪动屏幕的方式来取代蜂鸣器鸣叫 # Bindkey 和颜色bindkey -e     Select Emacs bindings  # 将命令行编辑器切换到emacs模式bindkey -k up history-search-backward # 使用上下键来搜索bindkey -k down history-search-forward setenv CLICOLOR 1                     # 使用颜色(可能的话)setenv LSCOLORS ExGxFxdxCxDxDxBxBxExEx 该 emacs 模式将使用 emacs 快捷键来修改命令提示行。这是非常有用的(不单为 Emacs 用户)。最常用的命令如下: - C-a       移动光标到行头 - C-e       移动光标到行尾 - M-b       移动光标到前一个单词 - M-f       移动光标到后一个单词 - M-d       剪切下一个单词 - C-w       剪切最后一个单词 - C-u       剪切光标前所有字符 - C-k       剪切光标后所有字符 - C-y       粘帖最后剪切的字符(简易的粘帖) - C-_       重做 _注意:_ C- = 按住 control 键,M- = 按住 meta (它通常为 alt 或者 escape)键。