- The Model Context Protocol: Simplifying Building AI apps with Anthropic Claude Desktop and Docker | Docker
- This robot vacuum and mop performs as well as some flagship models - but at half the price
- Finally, a ThinkPad model that checks all the boxes for me as a working professional
- Why I recommend this Android phone for kids over a cheap Samsung or Motorola model
- My favorite USB-C accessory of all time scores a magnetic upgrade
How to examine files on Linux
$ ls -ld TOPs
-rw-r--r--. 1 jdoe jdoe 9571 Oct 18 12:58 TOPs
$ ls -ldh TOPs
-rw-r--r--. 1 jdoe jdoe 9.4K Oct 18 12:58 TOPs
Viewing file content
The cat, head, tail, more and less commands allow you to view the content of text files. The cat command displays the entire file while head and tail display the first and last lines (defaulting to 10). The commands below display only three lines.
$ head -3 TZs
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
$ tail -3 TZs
W-SU
WET
Zulu
The more command will show you a screenful of lines at a time or fewer if you add an option (e.g., more -10). Both the more and less commands allow you to back up while viewing file content, but less backs up a line at a time while more backs up a screen at a time.
Using the nl command
If you want to view the lines in a text file in a numbered format, you can use the nl command. Here’s an example of using nl along with head to see only the first three lines of the output.
$ nl TZs | head -3
1 Africa/Abidjan
2 Africa/Accra
3 Africa/Addis_Ababa
Viewing other types of files
To view the content of files other than text files while working on the command line, you can use the od -bc command, but it’s going to show you the content in the octal and character (where available) formats shown below. The “E L F” in the output below is short for “executable and linkable format”. This format is used for storing binaries, libraries, core dumps and such.
$ od -bc /usr/bin/more | head -4
0000000 177 105 114 106 002 001 001 000 000 000 000 000 000 000 000 000
177 E L F 002 001 001
0000020 003 000 076 000 001 000 000 000 040 070 000 000 000 000 000 000
003 > 001 8
The JFIF sequence in the example below identifies the file as being in jpeg format.
$ od -bc hummingbird.jpg | head -6
0000000 377 330 377 340 000 020 112 106 111 106 000 001 001 001 000 110
377 330 377 340 020 J F I F 001 001 001 H
0000020 000 110 000 000 377 341 032 130 105 170 151 146 000 000 111 111