Linux Basic – Linux And Unix Command To View File

File view is one of the very basic activity in Linux which helps users to view and manipulate file contents. In Linux several applications are available to display file contents in different ways. You can use any one of the following command to view a text file or any other files.

To play on this, i have created a file called test and added definition and numbers from 1 to 50 to experiment all the file viewing commands.

Command Short Description
cat To display a file contents in screen.
less To display a file contents in screen page wise.
more To display a file contents in screen page wise.
head The head command displays the beginning of a file
tail To view the last “N” lines of a file
nl To print a file contents with line number
od To print a file contents as a octal dump format
xxd To print a file contents as a hex dump format
gv View Postscript/PDF files
xdvi View TeX DVI files

1) What’s Cat Command

The cat stands for (concatenate). It is one of the most frequently used commands on Unix-like operating systems. The most common use of cat is to read the contents of files.

Syntax : cat [options] [filenames]

Example:- Cat Command

See the output on screen.

# cat test
This is TEST file to Experiment the "File Viewing" command examples.
1
2
3
4
5
6
7
.
.
.
45
46
47
48
49
50

2) What’s Less Command

less command allows you to quickly view the file contents on screen from top to bottom using UP & DOWN arrow keys or Page UP & Page Down button.

Alternatively press g to move file top and press G to move file end, If you want to go with corresponding line, press g (When you type “g” it wont appear on screen) and continuously type the concern line number, which you want to jump. To quit the file press (Esc, q, enter).

Syntax : less [options] [filenames]

Example:- Less Command

See the output on screen.

# less test
This is TEST file to Experiment the "File Viewing" command examples.
1
2
3
4
.
.
41
42
:
9
10
11
.
.
46
47
48
49
50

(END)

3) What’s More Command

more command allows you to quickly view the file contents on screen from top to bottom page wise.

Syntax : more [options] [filenames]

Example:- Less Command

See the output on screen.

# more test
This is TEST file to Experiment the "File Viewing" command examples.
1
2
3
4
.
.
41
42
:
9
10
11
.
.
46
47
48
49
50

(END)

4) What’s Head Command

The head command displays the beginning of a file (first part of the file). By default this will print the first 10 lines, If you want to print more lines you can use the (N) option.

Syntax : head [options] [filenames]

Example:- Head Command

See the output on screen.

# head test
This is TEST file to Experiment the "File Viewing" command examples.
1
2
3
4
5
6
7
8
9

5) What’s Tail Command

The tail command displays the last part of a file. By default this will print the last 10 lines, If you want to print more lines you can use the (N) option.

Syntax : tail [options] [filenames]

Example:- Tail Command

See the output on screen.

# tail test
42
43
44
45
46
47
48
49
50

6) What’s nl Command

nl command is used to print a file contents on screen with line numbers, line numbers will start from “1” to “N”, this will print a file on screen one short and it same as cat command.

Syntax : nl [options] [filenames]

Example:- nl Command

See the output on screen.

# nl test
     1  This is TEST file to Experiment the "File Viewing" command examples.
     2  1
     3  2
     4  3
     5  4
     6  5
     .  .
     .  .
     .  .
    46  45
    47  46
    48  47
    49  48
    50  49
    51  50

7) What’s od Command

od stands for Octal Dump, it diplay the contents of a file in different formats with the octal format (binary format) being the default.

Syntax : od [options] [filenames]

Example:- od Command

See the output on screen.

# od test
0000000 064124 071551 064440 020163 042524 052123 063040 066151
0000020 020145 067564 042440 070170 071145 066551 067145 020164
0000040 064164 020145 043042 066151 020145 064526 073545 067151
0000060 021147 061440 066557 060555 062156 062440 060570 070155
0000100 062554 027163 030412 031012 031412 032012 032412 033012
0000120 033412 034012 034412 030412 005060 030461 030412 005062
0000140 031461 030412 005064 032461 030412 005066 033461 030412
0000160 005070 034461 031012 005060 030462 031012 005062 031462
0000200 031012 005064 032462 031012 005066 033462 031012 005070
0000220 034462 031412 005060 030463 031412 005062 031463 031412
0000240 005064 032463 031412 005066 033463 031412 005070 034463
0000260 032012 005060 030464 032012 005062 031464 032012 005064
0000300 032464 032012 005066 033464 032012 005070 034464 032412
0000320 005060 000012
0000323

8) What’s xxd Command

xxd creates a hex dump of a given file. It can also convert a hex dump back to its original binary form.

Syntax : xxd [options] [filenames]

Example:- xxd Command

See the output on screen.

# xxd test
0000000: 5468 6973 2069 7320 5445 5354 2066 696c  This is TEST fil
0000010: 6520 746f 2045 7870 6572 696d 656e 7420  e to Experiment
0000020: 7468 6520 2246 696c 6520 5669 6577 696e  the "File Viewin
0000030: 6722 2063 6f6d 6d61 6e64 2065 7861 6d70  g" command examp
0000040: 6c65 732e 0a31 0a32 0a33 0a34 0a35 0a36  les..1.2.3.4.5.6
0000050: 0a37 0a38 0a39 0a31 300a 3131 0a31 320a  .7.8.9.10.11.12.
0000060: 3133 0a31 340a 3135 0a31 360a 3137 0a31  13.14.15.16.17.1
0000070: 380a 3139 0a32 300a 3231 0a32 320a 3233  8.19.20.21.22.23
0000080: 0a32 340a 3235 0a32 360a 3237 0a32 380a  .24.25.26.27.28.
0000090: 3239 0a33 300a 3331 0a33 320a 3333 0a33  29.30.31.32.33.3
00000a0: 340a 3335 0a33 360a 3337 0a33 380a 3339  4.35.36.37.38.39
00000b0: 0a34 300a 3431 0a34 320a 3433 0a34 340a  .40.41.42.43.44.
00000c0: 3435 0a34 360a 3437 0a34 380a 3439 0a35  45.46.47.48.49.5
00000d0: 300a 0a                                  0..

9) What’s gv Command

gv is used to view the Postscript and PDF files.

Syntax : gv [options] [filenames]

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...