使用 'less' 命令时在 Unix 中显示特殊字符 [英] Show special characters in Unix while using 'less' Command

查看:14
本文介绍了使用 'less' 命令时在 Unix 中显示特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在使用less"命令时查看特殊字符.例如,我想查看带有特殊符号的不可打印字符.例如,在vi"编辑器中,我使用set list on"来查看由美元$"字符表示的行终止字符.同样,我想使用less"命令来做到这一点.

I would like to know how to view special characters while using 'less' command. For instance I want to see the non-printable characters with a special notation. For instance in 'vi' editor I use "set list on" to see the line termination characters represented by dollar '$' character. Similarly I would want to do this using 'less' command.

我参考了 Unix 少手册,但无济于事.

I referred Unix less manual, but to no avail.

推荐答案

less会在它的环境中查找是否有一个名为LESS的变量

less will look in its environment to see if there is a variable named LESS

您可以在 ~/.profile(.bash_rc 等)之一中设置 LESS,然后无论何时从命令行运行 less,它都会找到 LESS.

You can set LESS in one of your ~/.profile (.bash_rc, etc, etc) and then anytime you run less from the comand line, it will find the LESS.

尝试添加这个

export LESS="-CQaix4"

这是我使用的设置,其中嵌入了一些行为可能会让您感到困惑,因此您可以通过 less 中的帮助功能了解所有这些行为的含义,只需点击"h' 键和鼻子,或运行 less --help.

This is the setup I use, there are some behaviors embedded in that may confuse you, so you can find out about what all of these mean from the help function in less, just tap the 'h' key and nose around, or run less --help.

查看帮助,发现还有一个-r选项

I looked at the help, and noticed there is also an -r option

-r  -R  ....  --raw-control-chars  --RAW-CONTROL-CHARS
                Output "raw" control characters.

我同意 cat 可能最符合您的需求.

I agree that cat may be the most exact match to your stated needs.

cat -vet file | less

将在每行末尾添加$"并将制表符转换为可视的^I".

Will add '$' at end of each line and convert tab char to visual '^I'.

cat --help
   (edited)
    -e                       equivalent to -vE
    -E, --show-ends          display $ at end of each line
    -t                       equivalent to -vT
    -T, --show-tabs          display TAB characters as ^I
    -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB

我希望这会有所帮助.

这篇关于使用 'less' 命令时在 Unix 中显示特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆