In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to view the contents of files in Linux. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Cat
The cat command sends the entire contents of the text file to the terminal window for viewing. In fact, if you type cat and then enter a file name that contains thousands of lines, those lines will scroll through your window so fast that you won't be able to see any text other than the last screen. The cat command is familiar to Linux users, but even this basic command provides many useful options, such as numbering lines in the output that many of us may have never used before. Further, you can not only number the lines, but also choose how to number them.
Number each line like this:
$cat-n msg 1 Hello-2 3 I hope you are having a wonderful day! 4 5 6 That's it for. Now 7 8 bye! 9 10 s.
You can also number only lines with content. Note that for this command, lines that contain only spaces are not considered "empty" but are numbered.
$cat-b msg 1 Hello-2 I hope you are having a wonderful day! 3 That's it for. Now 4 bye! 5 s.
The cat command allows you to ignore duplicate blank lines using the-s option, but you must add another command to completely ignore blank lines.
$cat-s msg Hello-I hope you are having a wonderful day! That's it for... Now bye! s.
To ignore all blank lines, simply pipe the output of cat to the grep command as follows. Point (.) Matches text that contains any character, so it will display any non-empty line, which will be used to match the carriage return at the end of the line to match. (LCTT)
$cat msg | grep. Hello-I hope you are having a wonderful day! That's it for... Now bye! s.
The-E option shows whether there are any extra spaces at the end of each line by adding a $symbol at the end of each line to provide a visual hint.
$cat-E msg Hello-- $I hope you are having a wonderful day! $That's it for. Now$ $byebirds $$s.$
With-A, the $character can be displayed at the end of each line, and the tab will be displayed as ^ I instead of white space.
$cat-A msg Hello-- $$I hope you are having a wonderful daylight $That's it for... ^ Inow$ $byegrass $$s.$
Use head and tail to display parts of the file
Head and tail display the head or tail of the file, which defaults to ten lines. You can use strings such as-3 (display 3 lines) or-11 (display 11 lines) to specify the number of other lines to view. The tail command works the same way as head, but displays the tail of the file instead of the header.
$head-3 msg Hello-- I hope you are having a wonderful day! $tail-3 msg bye! s.
You can also use a combination of head and tail commands to view the text in the middle of the file. You just need to select the starting point and want to see the number of rows. In this example, the command displays the second hundred lines in the file and numbers them with the help of cat.
$cat-b mybigfile | head-200 | tail-100101 Invoice # 2020-06-07a sent to vendor.
Browse a screen of text using more or less
The more command is a natural choice for browsing the content one screen at a time, while less increases the ability to move up and down the file by using the up and down keyboard arrows, so you can traverse the content and then roll back in the file.
Two ways to view text using od
The od (octal dump) command can view a file in the form of regular text and a series of ASCII values, that is, how the text is actually encoded in the file. As you can see in the following example, numbered lines show ASCII numeric values, while other lines show text and unprintable characters.
$od-bc msg 0000000 110 1454 154 157 040 055 055 012 111 040 150 157 160 145 H e l l o -\ n\ n I h o p e 0000020 040 171 157 165 040 141 162 145 040 150 141 166 151 156 147 040 y o u a r e h a v i n g 0000040 141 040 167 157 156 145 162 146 165 154 040 144 141 171 041 a w o n d e r f u l d a y! 0000060 012 012 124 150 141 164 047 163 040 151 164 040 146 157 162\ n\ n\ n T h a t's i t f o r 0000100 040 056 056 056 011 156 157 012 142 171 145 041 012 012. . . \ t n o w\ n\ n b y e!\ n\ n 0000120 163,056012s. \ n
Notice that the newline character is displayed as\ n (octal 012) and the tab character is displayed as\ t (octal 011).
One of the particularly useful uses of the od command is to view non-text files for information that identifies the file type. Here, we see the JFIF (JPEG File Interchange format) tag, which allows commands such as file to report file types to mark it as a jpg file. There is a lot of other useful information here, especially if you are curious about the format of these files.
In the next command, we look at the beginning of the jpg file.
$od-bc arrow.jpg | head-12 0000000 377 330 377 340 000020 112 106 111 000 001 000000 001 000000 001 377 377 340\ 0020 J F I F\ 0 001\ 0 001 0000020 000 001 000 000 377 003 000 103 000 002 002 002 003 003 002 002 002 004 002 002 002 003 003 003 004 004 004 004 004 004 010 006 002 002 003 003 003 004 004 004 006 006 006 011 012 012 012 011 010 011 011 014 014 012 006 006\ n\ n\ t\ n\ f\ f 0000100 013 013 013 011 011 011 015 015 016 017 020 020 021 012 014\ v \ t\ r 021\ r 016 017 020 020 021 020\ n\ f 0000120 022 023 022 020 023 023 020 020 020 377 377 000 103 001 003 003 022 022 023 023 017 020 020 377 333\ 0C 001 003 003
If we asked the file command to provide information about this image, we might see information like the following. The file command extracts all of this descriptive information from the data at the beginning of the file:
$file arrow.jpg arrow.png: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 500x375, components 3
Using jp2a to treat a file as a text-based image
If you can only work on the command line and want to know what a particular image contains, you can use a tool such as jp2a (jpeg to ascii) to provide character rendering. The degree to which an image is recognized in this format depends on the file. Don't expect too much, because the image version you will see is tested under "low resolution"! This is an emperor penguin with very low resolution. (please look at it from a distance)
$jp2a Emperor_Penguin.jpg MMMMMMMMWOdkNMMMMMMMMMMMMMMMMMMM MMMXK0kc.... , OKMMMMMMMMMMMMMMMM MMNK0Ol... : Xx'dNMMMMMMMMMMMMM MMMMMMMd;lx00Oo. .. xMMMMMMMMMMMM MMMMMMK.OXMMMMMN,...lMMMMMMMMMMM MMMMMMx'KXNNMMMMK....0MMMMMMMMMM MMMMMMx:kkKNWWMMMl.. 'NMMMMMMMMM MMMMMMddx0NNNWMMMK'...;NMMMMMMMM MMMMMMck0NNWWWWWMMd.. lMMMMMMMM MMMMMM.d0KXNWWWWMMo... WMMMMMMM MMMMMM.xOXNNWNMMMW. .. KMMMMMMM MMMMMM'kKNKWXWMMMK.. 0MMMMMMM MMMMMMxckXNNNNMMMX.:. XMMMMMMM MMMMMMW;xKNWWWMMMM. ;. NMMMMMMM MMMMMMMok0NNWNWMMMx. L... MMMMMM MMMMMMMkxOKXWXNMMMMl.:'dMMMMMMMM MMMMMMM0dKOdKXXNMMMMNx,WMMMMMMMM MMMMMMMWoKxldXKNNMMMMM;MMMMMMMMM MMMMMMMMxxxxdNWNXNMMMM;MMMMMMMMM MMMMMMMMxOcoo0XOOOOWMW,kMMMMMMMM MMMMMMM0xK;.cO0dNX:0XXd;NMMMMMMM MMMNkdd:,'ldXXO0xl;x0kx:;lKMMMMM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM on how to view the contents of files in Linux, I hope the above content can be helpful to you, can learn more knowledge. if you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.