20.3 C
New York
Thursday, October 24, 2024

Methods to look at recordsdata 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 material

The cat, head, tail, extra and much less instructions mean you can view the content material of textual content recordsdata. The cat command shows the complete file whereas head and tail show the primary and final traces (defaulting to 10). The instructions beneath show solely three traces.

$ head -3 TZs
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
$ tail -3 TZs
W-SU
WET
Zulu

The extra command will present you a screenful of traces at a time or fewer if you happen to add an choice (e.g., extra -10). Each the extra and much less instructions mean you can again up whereas viewing file content material, however much less backs up a line at a time whereas extra backs up a display screen at a time.

Utilizing the nl command

If you wish to view the traces in a textual content file in a numbered format, you should utilize the nl command. Right here’s an instance of utilizing nl together with head to see solely the primary three traces of the output.

$ nl TZs | head -3
1 Africa/Abidjan
2 Africa/Accra
3 Africa/Addis_Ababa

Viewing different forms of recordsdata

To view the content material of recordsdata aside from textual content recordsdata whereas engaged on the command line, you should utilize the od -bc command, but it surely’s going to point out you the content material within the octal and character (the place obtainable) codecs proven beneath. The “E L F” within the output beneath is brief for “executable and linkable format”. This format is used for storing binaries, libraries, core dumps and such.

$ od -bc /usr/bin/extra | 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 within the instance beneath 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
H 377 341 032 X E x i f I I
0000040 052 000 010 000 000 000 005 000 032 001 005 000 001 000 000 000
* b 005 032 001 005 001

Within the command beneath, output from the echo command is piped to the od -bc command to supply a straightforward instance of how this command works. It exhibits the letters in “hi there” adopted by a newline character.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles