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

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.

主站蜘蛛池模板: 临沭县| 太仓市| 文水县| 资溪县| 南安市| 分宜县| 滨海县| 白山市| 曲麻莱县| 聂拉木县| 南投县| 阳春市| 常山县| 左权县| 渝北区| 石柱| 江津市| 华坪县| 河津市| 呼伦贝尔市| 清新县| 独山县| 临夏市| 庆元县| 临颍县| 剑河县| 江华| 天长市| 海南省| 个旧市| 合肥市| 湖口县| 青浦区| 柳河县| 军事| 安国市| 盖州市| 兴安盟| 和平区| 甘肃省| 尉犁县|