Linux Basics

24 / 87
   

Seeing Inside File - cat, tail, head

To see what is inside a text file, you can use either cat, tail, head.

Using cat you can see the whole content of the file:

cat myfirstfile_copy.txt

Do not use this command to look inside a huge file. For the huge file, you can use the more command which would display the content of a file in a paginated way:

more myfirstfile_copy.txt

tail shows you the last few lines of a file

tail myfirstfile_copy.txt

By default tail shows you only last 10 lines, you can change it using command line option. For example, to see last 20 lines, you can use

tail -20 myfirstfile_copy.txt

If you want to chase a file - continuously print newlines appended to the file - use the command:

tail -f myfirstfile_copy.txt

If you are interested in first few lines, you can use head. By default By default head shows you only first 10 lines, you can change it using command line option. For example, to see first 20 lines, you can use

head -20 myfirstfile_copy.txt