Get the App
SLTechnology News&Howtos  ›  Servers  › 

Linux file viewing and redirection

Shulou Source: shulou.com Published: 2022-06-03 01:59:46 10月27日 Update

Experimental objectives:

Through this experiment, we can master the use of head, tail, cat, more, less and other file viewing commands, understand the concept of redirection, and master the use of two redirection methods.

The steps of the experiment:

1. View the file / usr/bin/clean-binary-files through five different commands: head, tail, cat, more and less, and observe the similarities and differences of each tool.

2. Write the first 12 lines of / usr/bin/clean-binary-files to the file headtail.txt

3. Write the last 9 lines of / usr/bin/clean-binary-files to the file headtail.txt, which cannot overwrite the previous content.

Reference commands: 1. Five uses of view commands

Cat, displaying all the contents of the file at once

More/less, paged to display the contents of the file, more can only be turned down, less can be flipped up and down

Head/tail, write the first few lines or the last few lines of the poem file, use tail more, you can view the file update

2. The first 12 lines of / usr/bin/clean-binary-files, write to the file headtail.txt

Head-n 12 / usr/bin/clean-binary-files > / home/student/headtail.txt

Head-n 12, showing the first 12 lines of the file

Input the output of the haed command into the following file, and the > action is also called "redirect".

Note: if you report an error and do not have a directory, you need to create a student directory with mkdir first.

[root@localhost home] # vi / home/student/headtail.txt opens the file to see if 12 lines have been written to the file.

The last line mode of vi (that is, esc then:) enter set nu to view the line number, as shown in the figure

3. Write the last 9 lines of / usr/bin/clean-binary-files to the file headtail.txt, which cannot overwrite the previous content.

Tail-n 9 / usr/bin/clean-binary-files > > / home/student/headtail.txt

Tail-n 9, showing the last 9 lines of the file

The two angle brackets are appended to the following file for the contents of the tail display If you use >, the following file will be overwritten, that is, the previous head input will disappear.

Tags: File content command experiment input directory different up and down two that is actions angle brackets that is tools similarities and differences methods results concepts patterns steps Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Tech Info Huawei vpn Shulou Technology