【Linux常用命令】之less命令

Linux常用命令之less命令

文章目录

作者简介

听雨:一名在一线从事多年研发的程序员,从事网站后台开发,熟悉java技术栈,对前端技术也有研究,同时也是一名骑行爱好者。
Darren:一个工作经验用了N年的,资深划水人士,除了工作无其他爱好

口号:记录在开发中遇到日常问题、棘手问题的解法和思路

常用命令之less

背景介绍

less 是分页显示文本文件内容,less命令分页显示和more有几分相似,但more只能从前往后,less不仅可以从前往后还可以从后往前,相对更加灵活。(PageDown和PageUp按键)

常用参数

参数 解释
-e 当文件显示结束后自动退出
-m 显示阅读进度百分比
-N 显示文件内容时带行号
-Q 不使用警告音
-s 将连续多个空行视为一行
-S 显示较多的内容而不换行
-x数字 将tab字符显示为指定个数的空格字符

例如

展示分页信息最后不退出,需要按q键退出

shell 复制代码
root@master:~/temp/less# less lesstest.txt 

显示结束后自动退出

shell 复制代码
root@master:~/temp/less# less -e lesstest.txt 

打开文件后显示行数

shell 复制代码
root@master:~/temp/less# less -N lesstest.txt  

忽略告警音

shell 复制代码
root@master:~/temp/less# less -Q lesstest.txt

多个空行视为一行

shell 复制代码
root@master:~/temp/less# less -s lesstest.txt 
And as I gave it to him my heart was torn. 当我递给他时,我的心里千愁万绪。
        Tab
    space       

"You have plans that I do not know about," I said. "你有一些我不知道的计划,"我说。

But he did not answer me. 但他没回答。

每行显示多行时不换行显示,这个注意观察,很多行时最后有>注意观察

shell 复制代码
root@master:~/temp/less# less -S lesstest.txt 
And as I gave it to him my heart was torn. 当我递给他时,我的心里千愁万绪。
        Tab
    space       









"You have plans that I do not know about," I said. "你有一些我不知道的计划,"我说。

But he did not answer me. 但他没回答。

He said to me, instead: "You know, my descent to the earth... 他对我说,"你知道,从我落到地球上······

Tomorrow will be its anniversary." Then, after a silence, he went on: "I came down very near here." And he flushed. 到明天就满一年了。"他沉默了一阵,又接着说:"我就落在这儿附近 >

And once again, without understanding why, I had a queer sense of sorrow. 我再一次意识到,我为什么感受到一种莫名的愁绪。

One question, however, occurred to me: "Then it was not by chance that on the morning when I first met you --- a week ago --- you were strolling along like that, all alone, a thousa>

You were on the your way back to the place where you landed?" 你是想回到你降落的地方对吗?"

The little prince flushed again. 小王子的脸又红了。

将tab字符显示为指定个数的空格字符,注意使用方法和直观感受

shell 复制代码
root@master:~/temp/less# less -x2 lesstest.txt
And as I gave it to him my heart was torn. 当我递给他时,我的心里千愁万绪。
  Tab
    space 

基本命令导航

↓ 或 j:向下滚动一行

↑ 或 k:向上滚动一行

Space:向下滚动一页

b(PgUp):向上滚动一页

f(PgDn):向下滚动一页

g:跳转到文件的开头

G:跳转到文件的结尾

q:退出 less

less 提供强大的搜索功能

/pattern:向前搜索 pattern

?pattern:向后搜索 pattern

n:重复前一个搜索(同方向)

N:重复前一个搜索(反方向)

例如,搜索文件中的单词 "remember":

shell 复制代码
/remember
?remember

总结

less虽然是查看文件命令,主要是分页使用,个人认为比more相对来说好用一些,一定程度上和vi编辑器有一些相同的快捷键

参考:《Linux常用命令自学手册》

相关推荐
m0_6530313614 分钟前
腾讯云认证考试报名 - TDSQL数据库交付运维专家(TCCE PostgreSQL版)
运维·数据库·腾讯云
IC 见路不走21 分钟前
LeetCode 第91题:解码方法
linux·运维·服务器
没有名字的小羊30 分钟前
8.Docker镜像讲解
运维·docker·容器·tomcat
翻滚吧键盘34 分钟前
查看linux中steam游戏的兼容性
linux·运维·游戏
小能喵38 分钟前
Kali Linux Wifi 伪造热点
linux·安全·kali·kali linux
Code季风1 小时前
深入理解微服务中的服务注册与发现(Consul)
java·运维·微服务·zookeeper·架构·go·consul
java1234_小锋1 小时前
解释一下NGINX的反向代理和正向代理的区别?
运维·nginx
汀沿河1 小时前
8.1 prefix Tunning与Prompt Tunning模型微调方法
linux·运维·服务器·人工智能
zly35001 小时前
centos7 ping127.0.0.1不通
linux·运维·服务器
小哥山水之间2 小时前
基于dropbear实现嵌入式系统ssh服务端与客户端完整交互
linux