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

How it works...

Before proceeding, note that the contents of the loremipsum.txt file will be different for every instance downloaded. Lorem Ipsum is pseudo random text that is used in a variety of text-related duties, often as placeholder values because it looks to be a language of sorts and is useful where the human brain is disturbed by copy and paste stub text.

Great! Let's get started:

  1. In the first step, the commands should produce similar results to the following block (for brevity, we excluded much of the output to keep the recipe coherent), but notice that head begins at the beginning, or head, of loremipsum.txt, and tail begins at the end, or tail, of loremipsum.txt. When we specify the -n flag with a decimal number such as 1, both utilities will output a single line or whatever number of lines is entered:
$ cat loremipsum.txt

Feugiat orci massa inceptos proin adipiscing urna vestibulum
hendrerit morbi convallis commodo porta magna, auctor cras nulla ligula
sit vehicula primis ultrices duis rutrum cras feugiat sit facilisis
fusce placerat sociosqu amet cursus quisque praesent mauris facilisis,
egestas curabitur imperdiet sit elementum ornare sed class ante pharetra
in, nisi luctus sit accumsan iaculis eu platea sit ullamcorper platea
erat convallis orci volutpat curabitur nostra tellus erat non nisl
condimentum, cubilia lacinia eget rhoncus pharetra euismod sagittis
morbi risus, nisl scelerisque fringilla arcu auctor turpis ultricies
imperdiet nibh eget felis leo enim auctor sed netus ultricies sit fames
...
$ head loremipsum.txt
Feugiat orci massa inceptos proin adipiscing urna vestibulum
hendrerit morbi convallis commodo porta magna, auctor cras nulla ligula
sit vehicula primis ultrices duis rutrum cras feugiat sit facilisis
fusce placerat sociosqu amet cursus quisque praesent mauris facilisis,
egestas curabitur imperdiet sit elementum ornare sed class ante pharetra in
$ head -n 1 loremipsum.txt
Feugiat orci massa inceptos proin adipiscing urna vestibulum
$ tail loremipsum.txt
euismod torquent primis mattis velit aptent risus accumsan cubilia eros
justo ad sodales dapibus tempor, donec mauris erat at lacinia senectus
luctus venenatis mollis ullamcorper ante mollis nisl leo sollicitudin
felis congue tempus nam curabitur viverra venenatis quis, felis pretium
enim posuere elit bibendum dictumst, bibendum mattis blandit sociosqu
adipiscing cursus quisque augue facilisis vehicula metus taciti conubia
odio proin rutrum aliquam lorem, erat lobortis etiam eget risus lectus
sodales mauris blandit, curabitur velit risus litora tincidunt inceptos
nam ipsum platea felis mi arcu consequat velit viverra, facilisis
ulputate semper vitae suspendisse aliquam, amet proin potenti semper
$ tail -n 1 loremipsum.txt
ulputate semper vitae suspendisse aliquam, amet proin potenti semper
  1. In the second step, we discover a key difference between the head and tail commands. Tail is able to monitor a file while continuously dumping the tail contents of the file to standard out (stdout). If the file has a read error, or is moved/rotated out, -f (lowercase) will often stop outputting information, while -F will reopen the file and continue outputting the contents.
-F instead of -f is usually the desired option between the two if tailing system logs.
  1. With tail still running in continuous mode, several new entries should appear among the output. This sample is from when a system's wireless adapter was forced to reconnect to a standard access point (AP):
Dec 8 14:21:40 moon kernel: userif-2: sent link up event.
Dec 8 14:21:40 moon kernel: wlp3s0: authenticate with 18:d6:c7:fa:26:b0
Dec 8 14:21:40 moon kernel: wlp3s0: send auth to 18:d6:c7:fa:26:b0 (try 1/3)
Dec 8 14:21:40 moon kernel: wlp3s0: authenticated
Dec 8 14:21:40 moon kernel: wlp3s0: associate with 18:d6:c7:fa:26:b0 (try 1/3)
Dec 8 14:21:40 moon kernel: wlp3s0: RX AssocResp from 18:d6:c7:fa:26:b0 (capab=0x411 status=0 aid=1)
Dec 8 14:21:40 moon kernel: wlp3s0: associated
Dec 8 14:21:40 moon kernel: bridge-wlp3s0: device is wireless, enabling SMAC
Dec 8 14:21:40 moon kernel: userif-2: sent link down event.
Dec 8 14:21:40 moon kernel: userif-2: sent link up event.
  1. After killing the tail command, your console should be back at the prompt again: $.
  2. Running more and using the spacebar or Enter keys will progress output through the entire loremipsum.txt file. The more command is only able to view from beginning to end, and not back and forth.
  3. The less command is certainly more powerful and offers the user to be able to navigate through loremipsum.txt using several key combinations. It also offers search facilities among other features.
主站蜘蛛池模板: 汶上县| 应城市| 德化县| 朝阳区| 竹溪县| 遂宁市| 绥芬河市| 咸阳市| 瑞丽市| 汕头市| 西充县| 长兴县| 南雄市| 扎鲁特旗| 怀来县| 叶城县| 定南县| 永泰县| 滦平县| 临桂县| 永年县| 岳阳市| 海林市| 江油市| 太原市| 临颍县| 大丰市| 靖州| 巴彦县| 舞阳县| 郁南县| 石门县| 同仁县| 宜良县| 青铜峡市| 五台县| 成武县| 广元市| 巫溪县| 鹤庆县| 吴川市|