Linux provides many commands for examining the contents of files including cat, more,\u00a0head and tail, but that's just a start.\nFor one thing, even the most obvious commands have a lot more options than many Linux users ever get around to using. And there are some less obvious commands that offer some unique features. In this post, we\u2019ll both at commands for viewing the contents of files and options for tailoring those views to better cater to your needs.\ncat\nThe cat command sends the entire contents of text files to your terminal window for viewing. In fact, if you type \u201ccat\u201d followed by the name of a file with thousands of lines, those lines will whiz by your window so fast, you won\u2019t be able to make out much more of it than the last screenful of text. Yet, as familiar as the cat command is to Linux users, even this basic command provides a lot of useful options such as numbering the lines in the output that many of us likely haven\u2019t ever used. To expand on that, not only can you number lines; you have some choices in how you do the numbering.\nNumbering every line looks like this:\n$ cat -n msg\n 1 Hello --\n 2\n 3 I hope you are having a wonderful day!\n 4\n 5\n 6 That's it for ... now\n 7\n 8 bye!\n 9\n 10 s.\n\nYou can also number only lines with content. Note that a line containing only blanks is not considered \u201cempty\u201d for this command and would be numbered.\n$ cat -b msg\n 1 Hello --\n\n 2 I hope you are having a wonderful day!\n\n\n 3 That's it for ... now\n\n 4 bye!\n\n 5 s.\n\nThe cat command allows you to ignore repeated blank lines with the -s option, but you have to add another command to suppress blanks lines altogether.\n$ cat -s msg\nHello --\n\nI hope you are having a wonderful day!\n\nThat's it for ... now\n\nbye!\n\ns.\n\nTo ignore all of the blank lines, just pipe the output from cat to a grep command as follows. The dot (.) matches text including blank characters, so it will display lines that contain only blanks and only look empty.\n$ cat msg | grep .\nHello --\nI hope you are having a wonderful day!\nThat's it for ... now\nbye!\ns.\n\nThe -E optoin provides a visual cue to show whether there are extra blanks at the ends of lines by sticking a $ at the end of every line.\n$ cat -E msg\nHello --$\n$\nI hope you are having a wonderful day! $\n$\n$\nThat's it for ... now$\n$\nbye!$\n$\ns.$\n\nWith -A, you get both the $ characters at the end of each line and tabs showing up as ^I rather than empty space.\n$ cat -A msg\nHello --$\n$\nI hope you are having a wonderful day!$\n$\n$\nThat\u2019s it for \u2026^Inow$\n$\nbye!$\n$\ns.$\n\nDisplaying portions of files with head and tail\nThe head and tail commands show the tops or bottoms of files and default to ten lines. You can specify a different number of lines to view by using strings like -3 (show 3 lines) or -11 (show 11 lines). The tail command works the same way as head but displays the bottoms of files rather than the tops.\n$ head -3 msg\nHello --\nI hope you are having a wonderful day!\n$ tail -3 msg\nbye!\n\ns.\n\nYou can also combine head and tail commands to view text between the tops of bottoms of files. You just have to pick your starting point and how many lines you want to see. In this example, the command would display the second hundred lines in a file and, with cat's help, numbering those lines.\n$ cat -b mybigfile | head -200 | tail -100 101 Invoice #2020-06-07a sent to vendor ...\nBrowsing text a screenful at a time with more or less\nThe more command is an obvious choice for browsing through a file\u2019s content a screenful at a time while less adds the ability to move up and down in a file by using the up and down keyboard arrows so that you can start scanning and then back up in the file.\nLooking at text files two ways at once with od\nThe od (octal dump) command allows you to view a file both as normal text and as a series of ASCII values (i.e., how that text is actually encoded in the files). As you can see in the example below, the numbered lines show the numeric ASCII values and the alternate lines show the text and non-printable characters.\n$ od -bc msg\n0000000 110 145 154 154 157 040 055 055 012 012 111 040 150 157 160 145\n H e l l o - - n n I h o p e\n0000020 040 171 157 165 040 141 162 145 040 150 141 166 151 156 147 040\n y o u a r e h a v i n g\n0000040 141 040 167 157 156 144 145 162 146 165 154 040 144 141 171 041\n a w o n d e r f u l d a y !\n0000060 012 012 012 124 150 141 164 047 163 040 151 164 040 146 157 162\n n n n T h a t ' s i t f o r\n0000100 040 056 056 056 011 156 157 167 012 012 142 171 145 041 012 012\n . . . t n o w n n b y e ! n n\n0000120 163 056 012\n s . n\n\nNotice how newline characters are shown as n (octal 012) and tabs are shown as t (octal 011).\nOne of the especially helpful uses of the od command is for looking at non-text files for information that identifies the file types. In this case, we see the JFIF (JPEG File Interchange Format) label that identifies it as a jpg file to commands like file that report on file types. There's a lot of other useful information in there as well, especially if you're curious about how these files are formatted.\nIn this next command, we are looking at the beginning portion of a jpg file.\n$ od -bc arrow.jpg | head -12\n0000000 377 330 377 340 000 020 112 106 111 106 000 001 001 000 000 001\n 377 330 377 340 020 J F I F 001 001 001\n0000020 000 001 000 000 377 333 000 103 000 003 002 002 002 002 002 003\n 001 377 333 C 003 002 002 002 002 002 003\n0000040 002 002 002 003 003 003 003 004 006 004 004 004 004 004 010 006\n 002 002 002 003 003 003 003 004 006 004 004 004 004 004 b 006\n0000060 006 005 006 011 010 012 012 011 010 011 011 012 014 017 014 012\n 006 005 006 t b n n t b t t n f 017 f n\n0000100 013 016 013 011 011 015 021 015 016 017 020 020 021 020 012 014\n v 016 v t t r 021 r 016 017 020 020 021 020 n f\n0000120 022 023 022 020 023 017 020 020 020 377 333 000 103 001 003 003\n 022 023 022 020 023 017 020 020 020 377 333 C 001 003 003\n\nIf we were to ask the file command for information on this image file, we might see something like this. The file command is pulling all this descriptive information from data at the beginning of the file.\n$ file arrow.jpg\narrow.png: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 500x375, components 3\n\nLooking at files as text-based images with jp2a\nIf you are limited to the command line and want to get an idea what a particular image file contains, you can use a tool like jp2a (jpeg to ascii) to give you a character rendition. How recognizable the image will be in this format depends on the file. Don\u2019t expect much as the version of the image you will see is going to put \u201clow res\u201d to the test! This one\u2019s a very low resolution emperor penguin.\n$ jp2a Emperor_Penguin.jpg\nMMMMMMMMWOdkNMMMMMMMMMMMMMMMMMMM\nMMMXK0kc.... ,OKMMMMMMMMMMMMMMMM\nMMNK0Ol... :Xx'dNMMMMMMMMMMMMM\nMMMMMMMd;lx00Oo. ..xMMMMMMMMMMMM\nMMMMMMK.OXMMMMMN,...lMMMMMMMMMMM\nMMMMMMx'KXNNMMMMK....0MMMMMMMMMM\nMMMMMMx:kkKNWWMMMl.. 'NMMMMMMMMM\nMMMMMMddx0NNNWMMMK'...;NMMMMMMMM\nMMMMMMck0NNWWWWWMMd ..lMMMMMMMM\nMMMMMM.d0KXNWWWWMMo ...WMMMMMMM\nMMMMMM.xOXNNWNMMMW. ....KMMMMMMM\nMMMMMM'kKNKWXWMMMK ..'.0MMMMMMM\nMMMMMMxckXNNNNMMMX .:..XMMMMMMM\nMMMMMMW;xKNWWWMMMM. .;. NMMMMMMM\nMMMMMMMok0NNWNWMMMx .l..MMMMMMMM\nMMMMMMMkxOKXWXNMMMMl.:'dMMMMMMMM\nMMMMMMM0dKOdKXXNMMMMNx,WMMMMMMMM\nMMMMMMMWoKxldXKNNMMMMM;MMMMMMMMM\nMMMMMMMMxxxxdNWNXNMMMM;MMMMMMMMM\nMMMMMMMMxOcoo0XOOOOWMW,kMMMMMMMM\nMMMMMMM0xK;.cO0dNX:0XXd;NMMMMMMM\nMMMNkdd:,'ldXXO0xl;x0kx:;lKMMMMM\nMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n\nWrap-Up\nThere are quite a few commands on Linux for examining the content of files in various ways. Some have options which can prove very helpful when you need to manipulate file contents. Others are just \u2026 interesting.