Linux Basic Command Line to Read a File – Part 1

Command Line to Read File

0 48 If you wondering how to read a file in linux system, here some basic command line to read a file. Some of them default on linux or already installed, and some of the you should install first.  You can use those command lines to view or read a file text or any other file such as doc, pdf and more.

Here the folowing command line to read or view a file:

1. cat

cat is concatenate files and print on the standard output. cat command can read a text file with printing full content of the file to terminal screen.

The syntax :

cat [OPTION]… [FILE]…


ReadHow to Configure DenyHosts on CentOS 6


example :

example of cat command
example of cat command

2. head

head make output the first part of files.

The format of head :

head [OPTION]… [FILE]…

example :

example of head command
example of head command

By default, you can only read the first ten lines of a file. You can change the number of lines displayed by specifying a number option

head -20 <filename>

3. tail

tail make output the last part of files and tail is the reverse of head. Using tail, you can view the last ten lines of a file. This can be useful for viewing the last ten lines of a log file for important system messages.

tail syntax :

tail [OPTION]… [FILE]…

You can also use tail to watch log files as they are updated. Using the -f option, tail automatically prints new messages from an open file to the screen in real-time. For example, to actively watch /var/log/messages, enter the folowing at a shell prompt (as the root user):

example of tail with option -f
example of tail with option -f

Press [Ctrl]-[C] when you are finished.

4. more

more – file perusal filter for crt viewing and more is a filter for paging through text one screenful at a time.

syntax :

more [options] file […]


ReadSetup Timezone and NTP on CentOS 6


example :

the command is more /var/log/message

more /var/log/message
more /var/log/message

The [Space] bar moves forward one page and [Q] quits.

For the rest of command line to read to read file will be in Linux Command Line to Read a File – Part 2.

You might also like More from author