文章目录 1.命令格式2.命令功能3.命令参数4.按键操作5.示例1、查看文件内容2、ps查看进程信息并通过less分页显示3、查看命令历史使用记录并通过less分页显示5、浏览多个文件
less命令也是对文件或其它输出进行分页显示的工具,功能极其强大。less 的用法比起 more 更加有弹性。前面more介绍中,按b可以向前翻页, 按空格向后翻页, less 可以使用 [pageup] [pagedown] 等按键的功能来往前往后翻看文件,更容易用来查看一个文件的内容!除此之外,在 less 里头可以拥有更多的搜索功能,不止可以向下搜,也可以向上搜。最主要的区别:less 在查看之前不会加载整个文件。
less [参数] 文件
less 与 more 类似,但使用 less 可以随意浏览文件,而且 less 在查看之前不会加载整个文件。显示方面,显示内容方式不是输出到窗口,而是类似vi打开的文件一样,退出按q。
命令:
less test1.txt
输出:
ubuntu@VM-4-14-ubuntu:~/less$ less test1.txt123456789101111314151617181920
如果显示END了 按 q退出,没有的情况下可以按page up page down 上下翻页,也可用上下键一行行上下翻动。
命令:
ps -ef |less
输出:
UID PID PPID C STIME TTY TIME CMDroot 2 0 0 13:42 ? 00:00:00 [kthreadd]root 3 2 0 13:42 ? 00:00:00 [rcu_gp]root 4 2 0 13:42 ? 00:00:00 [rcu_par_gp]root 5 2 0 13:42 ? 00:00:00 [kworker/0:0-events]root 6 2 0 13:42 ? 00:00:00 [kworker/0:0H-kblockd]root 7 2 0 13:42 ? 00:00:00 [kworker/0:1-events]root 9 2 0 13:42 ? 00:00:00 [mm_percpu_wq]root 10 2 0 13:42 ? 00:00:00 [ksoftirqd/0]root 11 2 0 13:42 ? 00:00:00 [rcu_sched]root 12 2 0 13:42 ? 00:00:00 [migration/0]root 13 2 0 13:42 ? 00:00:00 [idle_inject/0]root 14 2 0 13:42 ? 00:00:00 [cpuhp/0]root 15 2 0 13:42 ? 00:00:00 [cpuhp/1]root 16 2 0 13:42 ? 00:00:00 [idle_inject/1]root 17 2 0 13:42 ? 00:00:00 [migration/1]root 18 2 0 13:42 ? 00:00:00 [ksoftirqd/1]root 20 2 0 13:42 ? 00:00:00 [kworker/1:0H-kblockd]root 21 2 0 13:42 ? 00:00:00 [kdevtmpfs]root 22 2 0 13:42 ? 00:00:00 [netns]root 23 2 0 13:42 ? 00:00:00 [rcu_tasks_kthre]root 24 2 0 13:42 ? 00:00:00 [kauditd]root 25 2 0 13:42 ? 00:00:00 [khungtaskd]root 26 2 0 13:42 ? 00:00:00 [oom_reaper]root 27 2 0 13:42 ? 00:00:00 [writeback]root 28 2 0 13:42 ? 00:00:00 [kcompactd0]root 29 2 0 13:42 ? 00:00:00 [ksmd]root 30 2 0 13:42 ? 00:00:00 [khugepaged]root 76 2 0 13:42 ? 00:00:00 [kintegrityd]root 77 2 0 13:42 ? 00:00:00 [kblockd]root 78 2 0 13:42 ? 00:00:00 [blkcg_punt_bio]root 80 2 0 13:42 ? 00:00:00 [tpm_dev_wq]root 81 2 0 13:42 ? 00:00:00 [ata_sff]root 82 2 0 13:42 ? 00:00:00 [md]root 83 2 0 13:42 ? 00:00:00 [edac-poller]root 84 2 0 13:42 ? 00:00:00 [devfreq_wq]:
命令:
history | less
输出:
1 2 ls 3 cd .. 4 ls 5 cd home/ 6 ls 7 cd lighthouse/ 8 ls 9 cd ~ 10 cd ../b 11 cd ../../boot/ 12 ls 13 cd ~ 14 cd - 15 ls 16 1.15.78.2011.15.78.2011.15.78.2011.15.78.201/boot$ cd - 17 cd ../../boot/ 18 file or directory 19 ntu:/$ cd .. 20 ubuntu@VM-4-14-ubuntu:/$ ls 21 bin boot cdrom data dev etc home lib lib32 lib64 libx32 lost+found media mnt opt proc root run sbin srv sys tmp usr var 22 ubuntu@VM-4-14-ubuntu:/$ cd home/ 23 ubuntu@VM-4-14-ubuntu:/home$ ls 24 lighthouse ubuntu 25 ubuntu@VM-4-14-ubuntu:/home$ cd lighthouse/ 26 ubuntu@VM-4-14-ubuntu:/home/lighthouse$ ls 27 cat linux-mv more mv test test1 touch 28 ubuntu@VM-4-14-ubuntu:/home/lighthouse$ cd ~ 29 ubuntu@VM-4-14-ubuntu:~$ cd ../b 30 -bash: cd: ../b: No such file or directory 31 ubuntu@VM-4-14-ubuntu:~$ cd ../../boot/ 32 ubuntu@VM-4-14-ubuntu:/boot$ ls 33 config-5.4.0-109-generic grub initrd.img initrd.img-5.4.0-109-generic initrd.img.old System.map-5.4.0-109-generic vmlinuz vmlinuz-5.4.0-109-generic vmlinuz.old 34 ubuntu@VM-4-14-ubuntu:/boot$ cd ~ 35 ubuntu@VM-4-14-ubuntu:~$ cd -:
命令:
less test1.txt test2.txt
执行结果
123456789101111314151617181920test1.txt (file 1 of 2) (END) - Next: test2.txt
说明:
输入 :n
后,切换到test2.txt,之后输入 :p
后,切换到test1.txt
来源地址:https://blog.csdn.net/lanlangaogao/article/details/125539792
--结束END--
本文标题: Linux less 命令使用介绍
本文链接: https://www.lsjlt.com/news/407504.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0