Functionality of the file reading commands

While learning the how to navigate through directories and systems through terminals and command lines,one thing is certain, your ability to located  exactly your looking for is essential. As we all know, files can come in smaller sizes or enormous sizes, and familiarity with your tools for reading files is essential in expediting your workflow. In this article, we will take a look at some of the most command commands used to read a file, and flags and arguments that can used to help you pinpoint the information your looking for.


‘cat’ command

The concatenate command, or ‘cat’ for short, is something you can use to view the contents of a given file. Here are some helpful commands:

cat example.txt 

simple viewing a file’s contents

cat -b example.conf 

cat -n example.conf

Using ‘-b’, or ‘-n’ you will be able to have the lines of your file numbered. This can be very useful if you viewing a file in order to identify an error. Often when updating or creating configurations for certain applications, like Apache for example, running a config test makes you aware of errors, usually indicating line where the error is occurring.

Note: Although these examples are for viewing file content using ‘cat’, ‘cat’ has many other uses for combining files.


‘more’ command

more example.conf

The ‘more’ command is used to view large text files in full page increments. After running the command you can press the ‘space bar’ to scroll through the file, once you identify what your looking for, type ‘q’ to return to the command line.


‘less’ command

less example.conf

The ‘less’ command is similar to the ‘more’ command in respects to the ability to view scroll through a file full pages at a time(with the space bar). ‘less’ however adds some flexibility for navigation unlike ‘more’ such as being able to scroll backwards by using the letter ‘b’. You also have the ability to scroll from line to line instead of page to page by using the arrow buttons, however, if you know exactly what you are looking for in the file you can have it highlighted for you to identify it more clearly. This can be done by using the ‘/’ followed by string you are looking for, very useful tool!!


‘head’ command

head example.conf

head -20 example.conf

The ‘head’ command is designed to output the first ten lines of the file you are attempting to view. The second example of the ‘head’ command above shows how you can increase the amount of lines that are outputted from the beginning of the file.


tail’ command

tail example.log 

tail -f example.log

The ‘tail’ command works like the ‘head’ command, just at the opposite end, or tail of the file. ‘tail’ comes most useful when viewing logs, so one may view the latest entries to the log files from the moment you ran the command. The second example above includes a flag ‘-f’, which allows you to see the latest entries to the log files as they come in, so one may identify if an occurrence if repetitive.


These commands are just starting points to help you pinpoint the information you are looking for when navigating through your systems. All of these commands have additional flags and arguments that cant be used to enhance your experience. For more information on these commands, type ‘man’ before your choice of command to view additional usages.

Related Articles