文章

linux 下 cat 命令替代品

在 linux 下常常会用到 cat 命令,但是 cat 命令不带颜色且不能前后滚动或者翻页,下面推荐一个 cat 的平替 — bat 。

安装

安装 batcat

1
sudo apt install bat

给 batcat 设置别名

1
2
3
4
5
6
# 打开配置文件
vim ~/.bashrc
# 在最后添加下面这一句
alias "bat=batcat"
# 保存退出后使命令生效
source  ~/.zshrc

使用

使用和 vim 类似

1、查看文件内容

1
bat <filename>

2、停止查看

1
:q

3、向前翻滚

1
ctrl + f

4、向后翻滚

1
ctrl + b

5、搜索关键字

1
/关键字

6、其他用法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
bat 0.19.0
A cat(1) clone with syntax highlighting and Git integration.

USAGE:
    batcat [OPTIONS] [FILE]...
    batcat <SUBCOMMAND>

OPTIONS:
    -A, --show-all                       Show non-printable characters (space, tab, newline, ..).
    -p, --plain                          Show plain style (alias for '--style=plain').
    -l, --language <language>            Set the language for syntax highlighting.
    -H, --highlight-line <N:M>...        Highlight lines N through M.
        --file-name <name>...            Specify the name to display for a file.
    -d, --diff                           Only show lines that have been added/removed/modified.
        --tabs <T>                       Set the tab width to T spaces.
        --wrap <mode>                    Specify the text-wrapping mode (*auto*, never, character).
    -n, --number                         Show line numbers (alias for '--style=numbers').
        --color <when>                   When to use colors (*auto*, never, always).
        --italic-text <when>             Use italics in output (always, *never*)
        --decorations <when>             When to show the decorations (*auto*, never, always).
        --paging <when>
            Specify when to use the pager, or use `-P` to disable (*auto*, never, always).

    -m, --map-syntax <glob:syntax>...
            Use the specified syntax for files matching the glob pattern ('*.cpp:C++').

        --theme <theme>                  Set the color theme for syntax highlighting.
        --list-themes                    Display all supported highlighting themes.
        --style <components>
            Comma-separated list of style elements to display (*auto*, full, plain, changes, header,
            grid, rule, numbers, snip).
    -r, --line-range <N:M>...            Only print the lines from N to M.
    -L, --list-languages                 Display all supported languages.
    -h, --help                           Print this help message.
    -V, --version                        Show version information.

ARGS:
    <FILE>...    File(s) to print / concatenate. Use '-' for standard input.

SUBCOMMANDS:
    cache    Modify the syntax-definition and theme cache

效果展示

batcat

本文由作者按照 CC BY 4.0 进行授权

© ziqing. 保留部分权利。

纸上得来终觉浅,绝知此事要躬行!