Linux cat more less head tail

Source: Internet
Author: User
Tags syslog

Cat command:

Cat filename View the contents of a file
cat[options [File] ...

-B numbers non-blank lines, line numbers starting with 1
-N and NL commands are similar, numbered output displays for all rows (including blank lines)
-e Append $ sign at the end of each line

Cat filename1 filename2 Display the contents of multiple files simultaneously

For files with great content, cat can be piped | Transfer to the more tool, and then page-by-page view
such as [[email protected] ~]# Cat/etc/fstab/etc/profile | More

Cat has the ability to create files, after creating the file, to end with EOF; (> Change to >> Append)
such as [[email protected] ~]# cat > Test << EOF Create test file with EOF as end of file input
>test1 This is the input content
>test2 This is the input content
>eof Exit Edit State

For files with great content, cat can be piped | Transfer to the more tool, and then page-by-page view
such as [[email protected] ~]# Cat/etc/fstab/etc/profile | More


More
More is one of our most commonly used tools, the most common is to display the content of the output, and then according to the size of the window to display the page, and then you can also indicate the percentage of the file

More [parameter options] [file]


+num starting from Num line;
-num defines the screen size for NUM lines;
+/pattern starts from the first two lines of the pattern;





More Action commands:

When we look at a larger file, we use more action instructions, such as ctrl+f (or SPACEBAR) is to display a screen down, Ctrl+b is to return to the previous screen, the ENTER key can scroll down to display n rows, to pass the default is 1 rows;

Enter down n rows, need to be defined, default to 1 rows;
CTRL+F scroll down one screen;
The space bar scrolls down one screen;
Ctrl+b return to the previous screen;
= Output the line number of the current line;
: F output File name and line number of the current line;
V Call VI Editor;
command to invoke the shell and execute the command;
Q exit




Less
After entering less, we have to learn a few actions, so that it is more convenient for us to check the contents of the file, the most should remember the command is Q, which allows less to terminate the view file exit;

Action:
The ENTER key moves down one line;
Y move up one line;
The space bar scrolls down one screen;
b scroll up one screen;
D scroll down half screen;
H less's help;
U move up the half screen;
W can specify which line to start displaying, which is displayed from the next line of the specified number, for example, 6, which is displayed from line 7th;
G jumps to the first line;
G jumps to the last line;
P n% jumps to n%, such as 10%, which means that it starts at 10% of the entire file content;
/pattern searches for pattern, such as/mail, to search for mail words in a file;
V Call VI Editor;
Q Exit Less
!command Call the shell, you can run the command, such as!ls display the current column in the current directory of all files;



The Head tool, which displays the first few lines of the file contents

Head is the number of lines that appear before the contents of a file;

The usage is relatively simple;
Head-n the value file name of the row;

For example, we show the first 10 lines of/etc/profile, which should be:
[Email protected] ~]# head-n 10/etc/profile

V. Tail tool that displays the last few lines of the file contents

Tail is the last number of lines that display the contents of a file;

The usage is relatively simple;
Tail-n the value file name of the row;

For example, we show the last 5 lines of/etc/profile, which should be:
[Email protected] ~]# tail-n 5/etc/profile

Tail-f/var/log/syslog Displays the following 10 lines of the file syslog and automatically displays the new file contents after the file contents have been increased.

Note: The last command tail is very useful, especially when monitoring log files, you can always display the new log information on the screen.

Linux cat more less head tail

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: info-contact@alibabacloud.com 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.