Linux file Operation Cat, more, less, head, tail, WC commands

Source: Internet
Author: User

one, thecat command

1, optional parameters

-A,--show-all equivalent to -vet

-B,--number-nonblank number of non-null output lines

-e equivalent to -ve

-E,--show-ends displays at the end of each line

-N,--number all line numbers for the output

-S,--squeeze-blank does not output multiple lines of blank lines

-T vs .-VT Equivalence

-T,--show-tabs to display the jump character as ^i

-U ( ignored )

-V,--show-nonprinting uses ^ and m -references, except LFD and TAB

2,cat generally as a view File command, can also be used to create files

[[email protected] test]# Cat > Test.txt Here is the first line here is the third row, the second row is a blank line here is the fourth row ^c[[email protected] test]# cat Test.txt Here is the first line here is the third Line, the second line is empty, this is line fourth.
[[email protected] test]# cat test.txt/etc/passwd >test2.txt[[email protected] test]# cat test2.txt Here is the first line here is the third row, The second line is empty line here is the fourth row root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologin ... #此处省略


3, use cat to view files

[[email protected] test]# cat Test.txt Here is the first line here is the third row, the second row is a blank line here is the fourth row, here is a TAB key here is the 7th row, 5th, 6 behavior blank line
[Email protected] test]# cat-nt test.txt #对每行均显示编号 1 Here is the first row 2 3 here is the third row, ^i the second row is a blank line 4 here is line fourth, ^i there is a TAB key 5 6 7 Here is line 7th, 5th, 6 behavior blank line
[[email protected] test]# CAT-BT test.txt Ignore blank line number 1 Here is the first line 2 here is the third row, ^i the second row is a blank line 3 here is the fourth row, ^i here is a tab 4 here is the 7 lines, 5th, 6 behavior blank line
[[email protected] test]# cat-st test.txt #-s multiple empty rows only show a single empty row here is the first line here is the third row, ^i the second row is a blank line here is the fourth row, ^i here is a TAB key here is the 7th row, 5th, 6 behavior blank line
[[email protected] test]# cat-snt Test.txt 1 Here is the first line 2 3 here is the third row, ^i the second row is a blank line 4 here is the fourth row, ^i here has a TAB key 5 6 here is   Line 7th, 5th, 6 behavior blank line [[email protected] test]# CAT-BNT Test.txt 1 Here is the first line 2 here is the third row, ^i the second row is a blank line 3 here is the fourth line, ^i here has a TAB key 4 Here is Line 7th, 5th, 6 behavior blank line


ii.more commands

1, common optional parameters

[[email protected] test]# more-2 test.txt #-n custom screen size n rows, that is, n rows n rows of pagination display here is the first line here is the third row, the second row is a blank line here is the fourth row, here is a TAB key here is the 7th row, 5th, 6 behavior Empty Yes
[[email protected] test]# more +3-s test.txt#+n starting from the nth line,-s multiple empty rows display a row. Here is the third row, the second line is a blank line here is the fourth row, here is a TAB key here is the 7th row, 5th, 6 behavior blank line


-C: Clear the screen from the bottom, and then display,-p is similar to the effect.

2, the common operation, and the cat difference is thatmore can be paged display, the progress of a page by page, and Cat is all-in-one print out. So more read through the keyboard control. If you need more, you'll remember.

1)Enter : down one line, in fact, can be customized, but by default every time you press Enter to turn the line.

2)ctrl+f: Scroll down one screen, key combinations,F is not case sensitive. You can also directly press the "spase" key to achieve.

3)ctrl+b: With Ctrl +f opposite, turn up a screen.

4)v : Call the VI editor directly.

5)! Command: See half is a Shell command.

6)Q: Do not want to look down, press the Q key to exit. As with the man command,man exits by Q . Of course, you can also use CTRL + C direct violence.

3, the actual use or use more commonly used operations, for example, the general is directly press "Spase" key page, rarely press ctrl+f to page, and press the Eneter key line to turn.

It is also convenient to use the pipeline with other commands

#查看/etc/file, but more, you can achieve the page display by more [[email protected] test]# ll/etc/|more +2-4# read from the second line, read 4 lines at a time. Drwxr-xr-x. 3 root root 4096 Sep 3 05:42 abrtdrwxr-xr-x. 4 root root 4096 Sep 3 05:55 acpi-rw-r--r--. 1 root root 3 Sep 22:25 adjtime-rw-r--r--. 1 root root 1512 Jan aliases--more-

third,less command

1,the less command is similar to the more command by turning the page to view the file.

-E: Automatically exits when the file display finishes. The default exit is the need to press Q to exit.

-M: Displays the progress percentage.

[[email protected] test]# less-me/etc/shadow#-me combination can get the effect of more commands.

-N: Displays line numbers, which are implemented using -N in Cat .

-S: A row is displayed infront of cat, More, and multiple consecutive empty rows.

-X Number: Displays the "tab" key as a specified number space.

2, common operation

/ string: Search down

? string: Search up

D: Turn back half page, Lenovo down. With the corresponding u, up turn up half a page.

F: Turn back one page.

B: Turn one page forward, Lenovo back, and turn the page backwards.

Q: Exit,manandmore are common.

U: Turn up half page, up meaning.

SPACEBAR: Turn back one page.

Enter: Scrolls one line.

3, Example

Pagination display through pipeline technology

[Email protected] test]# ll-l/etc/|less–enm

iv.Head command

1, first man under head.

-N display number of rows

-C display of bytes

-Q Hide file names

2, common examples

[[email protected] test]# head-n 3 test.txt #只打印前3行这里是第一行 This is the third row, the second line is a blank line
[Email protected] test]# head-n-3 test.txt# print start to the 4th line, is to cut down the last 3 lines. Here is the first line here is the third row, the second row is a blank line here is the fourth row, there is a TAB key
[[email protected] test]# head-c test.txt# also print only the first 10 bytes. Here is [email protected] test]#[[email protected] test]# head-c -10 test.txt# cut down the last 10 bytes. Here is the first line here is the third row, the second row is a blank line here is the fourth row, here is a TAB key here is the 7th row, 5th, 6 lines [[email protected] test]#

v.tail Command

1,the tail command corresponds to the head command, the usage is similar, but the tail parameter is more,tail reads the reciprocal

-N: calculated by row

-C: by byte position

-M: Multi-byte computing

-K: calculated by file size K

-F: Cyclic reading for real-time update display

-S: Used with -F to indicate each update time

2, Example

#读取倒数4行 [[email protected] test]# Tail-n 4 test.txt Here is line fourth, here is a TAB key here is 7th row, 5th, 6 behavior blank line
#从第4行开始读到最后 [[email protected] test]# tail-n +4 test.txt Here is line fourth, here is a TAB key here is 7th row, 5th, 6 behavior blank line
#实现实时读取并且更新时间为每2s一次 [[email protected] test]# ping 192.168.1.1>ping.log &[1] 8835[[email protected] test]# tail-f -S 2ping.log64 bytes from 192.168.1.1:icmp_seq=6ttl=64 time=1.90 ms64 bytes from 192.168.1.1:icmp_seq=7ttl=64 time=2.77  Ms64 bytes from 192.168.1.1:icmp_seq=8ttl=64 time=1.92 ms64 bytes from 192.168.1.1:icmp_seq=9ttl=64 time=1.91 ms64 bytes From 192.168.1.1:icmp_seq=10ttl=64 time=2.42 ms64 bytes from 192.168.1.1:icmp_seq=11ttl=64 time=2.68 ms

vi. WC:print newline, word, and byte counts for each file. That is, statistics file bytes, Word count, line number.

1, optional parameters

-C count bytes.

-L counts the number of rows.

-M counts the number of characters, notes the difference from-C, and cannot be used in conjunction with -C .

-W count words, "word" means a string that is split by a blank, jump, or newline character.

-L Prints the length of the longest line.

2, Example

[[email protected] test]# cat test5.txt1 A23 bc456 def7890 hijk[[email protected] test]# WC test5.txt 4 8 28test5.txt#4 indicated Number of rows, 8 words (words), 28 bytes.
#对比-c,-m and-w differences [[email protected] test]# less test7.txt 1234567890 [[email protected] test]# wc-c test7.txt34 test7.txt[[ Email protected] test]# wc-m test7.txt14 test7.txt[[email protected] test]# wc-w TEST7.TXT4 test7.txt
#不想显示文件名的实现 [[email protected] test]# wc-m test.txt |cut-d '-f 158[[email protected] test]# cat Test.txt |wc-m58
 #统计目录下文件数 [[email protected] test]# lltotal 48- Rw-r--r--.  1 root root  6065 sep 8 09:16 ping.log-rw-r--r--.  1 root root  2196 sep 7 10:52 test2.txt-rw-r--r--.  1  Root root  3561 sep 7 11:28 test3.txt-rw-r--r--.  1 root root  14341 sep  7 11:57 test4.txt-rw-r--r--.  1 root root     28 sep 8 09:50 test5.txt-rw-r--r--.  1 root root      6 sep 8 09:53 test6.txt-rw-r--r--.  1 root root     34 sep 8 09:58 test7.txt-rw-r--r--.  1 root root    140 sep 7 14:03 test.txt[[email protected] test]# ll |sed   ' 1d '  |wc -l8 

Summarize:

Cat,More,Lesscan read the contents of the file, butCatpaged display is not supported. Morewith theLesssupport pagination Display,Morecan also pass-N(-number) to customize eachNrow Paging,Morecan be the sameCtrl+b,fpage up and down,Lessyou can directly pressB,f,d,ukey to page directly. Lessyou can also pass-E(show exit),-M(show percent progress) implementationMoresimilar effects. Want to display line numbersLess–n,Cat–n. Lessthrough/,?followed by a string implementation to find the top and bottom.

Head and tail usage are similar, can read the number of rows through the-n parameter, but head–3 and head–n 3 Read the first 3 lines,head– N-3 is the last three lines cut off. tail–n 3 means reading the last three lines,tai–n +3 means starting from Line 3 to the end.


This article is from the "Ding classmate 1990" blog, please be sure to keep this source http://dingtongxue1990.blog.51cto.com/4959501/1699326

Linux file Operation Cat, more, less, head, tail, WC commands

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.