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

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.

主站蜘蛛池模板: 横峰县| 龙游县| 张家港市| 鹤山市| 津南区| 洛阳市| 丹凤县| 福州市| 大邑县| 通道| 仙游县| 望谟县| 彭阳县| 栾城县| 蚌埠市| 海丰县| 东乌| 阜平县| 宣城市| 霞浦县| 油尖旺区| 怀宁县| 望奎县| 金山区| 阿图什市| 威宁| 平果县| 尤溪县| 银川市| 桐柏县| 万荣县| 贵州省| 泰和县| 玛多县| 庆安县| 怀宁县| 尖扎县| 阜阳市| 长武县| 信阳市| 金堂县|