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

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.
主站蜘蛛池模板: 隆安县| 石楼县| 浠水县| 寻乌县| 都安| 镇原县| 江川县| 都兰县| 兴义市| 武隆县| 罗平县| 洛川县| 南木林县| 邛崃市| 古丈县| 德江县| 邵东县| 大悟县| 新建县| 和林格尔县| 肥东县| 伊春市| 阿拉善右旗| 桓仁| 昌江| 织金县| 巫山县| 瓦房店市| 运城市| 盐津县| 大名县| 彭山县| 樟树市| 祥云县| 景德镇市| 长治市| 余江县| 陆丰市| 西城区| 蒲城县| 静安区|