File display commands: CAT, more, less, tail, and touch

Source: Internet
Author: User
Tags touch command

More + 200 Catalina. Out??CTRL + B on the previous screen; Ctrl + F on the next screen; V calls the editor??


Cat command
The cat command connects the file and prints it to the standard output device. Cat is often used to display file content, similar to the type command below.

General Format: CAT [Option] File
Note: This command has two functions: one is to display the file content, which reads the Files specified by the parameter file in turn and outputs their content to the standard output; the second is to connect two or more files. For example, cat FL F2> F3 combines the FL and several files, and then outputs the redirection ">, put them in file F3.
Common options:
-B, -- number-noblank: numbers all non-empty output rows starting from 1.
-N, -- number indicates the number of all output rows starting from 1.
-S, -- Squeeze-blank combines multiple adjacent empty rows into one empty row.
-Help: print the command usage and exit. The return code indicates that the command is successful.
Note: When the file size is large, the text will flash quickly on the screen (scrolling), and you may not see the displayed content clearly. Therefore, the more command is usually used for screen display. To control scrolling, press Ctrl + S to stop scrolling. Press Ctrl + Q to restore scrolling. Press Ctrl + C (Interrupt) to terminate the command execution and return the shell prompt status.
Example: (set ml and M2 to the two files in the current directory)
# Cat M1 (display ml content of the file on the screen)
# Cat M 1 m2 (displaying both ml and M2 content)
# Cat M 1 m2> file (merge the ml and M2 files into the file)

More command
The more command displays the file content, one screen at a time.

General Format: more [Option] File
Note: This command displays a screen of text at a time, stops when the screen is full, and a prompt message is displayed at the bottom of the screen, showing the percentage of the file displayed so far: -- more -- (XX %) You can use the following methods to answer the prompt:
① Press the Space key to display the content of the next screen of the text.
② Press the enier key to display only the content of the next line of the text.
③ Press the slash (L) and enter a pattern to find the next matching pattern in the text.
④ Press the H key to display the help screen, which contains related help information.
⑤ Press the B key to display the content of the previous screen.
6. Press the Q key to exit the rnore command.
Common options:
-Num. This option specifies an integer indicating the number of rows displayed on a screen.
-D: displays the following friendly prompts at the bottom of each screen:
-- More -- (XX %) [Press space to continue, 'q' to quit.]
If an error occurs when you press the button, the [Press 'h', for instructions.] information is displayed, instead of a simple alarm.
-C or-P, without scrolling, clear the screen before displaying the next screen.
-S: compresses consecutive blank lines in the file into a blank line for display.
+/, Pattem after this option specifies the string to be searched before each file is displayed.
+ Num, starting from the row number num.
Some interactive commands Based on the VI editor are also used during the execution of the more command, which is not described here.
Example:
① Display the file content, but clear the screen before display, and display the percentage of cores at the bottom of the screen.
# More-DC File
② Display the file content, which is displayed once every 10 rows, and clear the screen before display.
# More-C-10 File

Less command
Like the more command, the less command is also used to display the file content on a split screen. However, there is a difference between the two: the less command allows users to browse files forward or backward, while the more command can only browse files forward. When you use the less command to display files, use the Pageup key to flip the page up and the Pagedown key to flip the page down. To exit the less program, press the Q key. Less has several formats and many options, which are not described here.

Head command
Command to display several lines at the beginning of a specified file on the screen.

General Format: head [Option] File
Note: The head command displays several lines at the beginning of a specified file on the screen. The number of lines is determined by the parameter value. The default value of the number of displayed rows is 10.
Option:
-C,-bytes = size indicates the first size bytes.
-N,-lines = Number specifies the number of rows in front of the display. The default value is 10.
-Q,-quiet, -- silent does not display the title of the given file.
-V,-verbose always displays the title of the given file.
Example:
# Head-5 file (display the first five lines of file)
# Head-V file (display the file content and give the file name title)
# Head-Q file (the file content is displayed, but the file name title is not listed)

Tail command
The tail command displays thousands of lines at the end of a specified file on the screen.

General Format: tail [Options] [file]…
Note: The tail command displays 10 lines at the end of the specified file on the screen. If more than one file is specified, add a file name title before each file. If no file is specified or the file name is "-", the standard input is read.
Option:
-C, -- bytes = N output the last n Bytes.
-F output additional data when the file grows.
-N,-lines = N: output the last n rows instead of the default 10 rows.
-Q,-quiet, -- silent does not output the title containing the given file name.
-V,-verbose always outputs the title containing the given file name.
Note: if there is a "+" sign before the N value of the byte or number of rows, it will be displayed from the nth entry at the beginning of the file, rather than the last n items of the file. There can be a suffix after the N value: B Indicates 512, K indicates 1024, and M indicates 1 048576 (1 m ).
Example:
# Tail file (display the last 10 lines of file)
# Tail + 20 file (the content of the file is displayed, from row 20th to the end of the file)
# Tail-C 10 file (display the last 10 characters of the file)

Touch command
You can modify the time tag of a specified file or create an empty file.

General Format: Touch [Option] file name...
Note: The touch command will modify the time tag of a specified file and update the time tag of an existing file to the current time (by default) of the system. Their data will remain intact. If the file does not exist, an empty new file is created.
Option:
-A only changes the access time of the specified object.
-C does not create any files.
-M only changes the modification time of the specified file.
-T stamp uses the time tag specified by stamp, instead of the current time of the system. The stamp format is [[CC] YY] mmddhhmm [. SS]. CC indicates the first two digits of the Year, YY indicates the last two digits of the Year, MM indicates the month, DD indicates the date, HH indicates the hour, MM indicates the minute, and SS indicates the second.
Example:
# Touch ex2 creates an empty file ex2 in the current directory.
Then, the LS-l command can be used to find that the size of the file ex2 is 0, indicating that it is a null file.


File display commands: CAT, more, less, tail, and touch

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: [email protected] and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.