官术网_书友最值得收藏!

Text filtering tools

Normally, shell scripting involves report generation, which will include processing various text files and filtering their output to finally produce the desired results. Let's start discussing the two Linux commands, namely more and less:

  • more: Sometimes we get a very large output on the screen for certain commands, which cannot be viewed completely in one screen. In such cases, we can use the more command to view the output text one page at a time. Add | more after the command, as follows:
    $ ll /dev | more

The | is called a pipe. You will learn more about it in the next chapters. In this command, pressing the spacebar will move the output on the screen one page at a time, or pressing Enter will move the screen one line at a time.

  • less: Instead of more, if you use less, it will show a screen containing the full text all at once. We can move forward as well as backward. This is a very useful text-filtering tool.

The syntax usage is as follows:

    $ command |  less
    e.g. $ ll /proc | less

This command will show a long directory listing of the /proc folder. Let's say that we want to see whether the cpuinfo file is present in the directory. Just press the arrow key up or down to scroll through the display. With the more command, you cannot scroll backward. You can move forward only. With page up and down key presses, you can move forward or backward one page at a time, which is very fast. In addition to scrolling forward or backward, you can search for a pattern using /for forward search and ? for backward search. You can use N for repeating the search in a forward or backward direction.

主站蜘蛛池模板: 彰武县| 山丹县| 疏附县| 阿城市| 嘉祥县| 镇赉县| 马边| 长沙县| 满洲里市| 蓬安县| 济南市| 同仁县| 九台市| 鲁山县| 大石桥市| 新昌县| 色达县| 巴马| 大庆市| 乳山市| 犍为县| 韶关市| 上林县| 班戈县| 怀集县| 肇庆市| 莲花县| 南投市| 深州市| 息烽县| 田林县| 公安县| 渑池县| 卢龙县| 花莲市| 商城县| 静海县| 盐亭县| 湘潭市| 扬中市| 登封市|