cat, more, less, head, tail in Linux Operating System

cat, more, less, head, tail in Linux Operating System

In a terminal of the Linux Operating System, we often see people using these words like cat or less. Today we will find out where and when we are going to use these words.

Cat

  • Cat is used to draw text files on the terminal.
  • cat FileName => It will print the text file on the terminal.
  • cat FileName_1 FileName_2 FileName_3 => it will print all the three files respectively upon the terminal.
  • cat -n FileName_1 FileName_2 FileName_3 => It prints the line Numbers before each line.
  • cat is best when we have one page of text.

More

  • more => is used when we have more than one page of text.
  • more => is also used just like cat command and to see the remaining text just press spaceBar
  • more works pretty well for multiple pages of text but more command was improved upon and they call the improvement less.

Less

  • less is also just like more.
  • The advantage of using less over more is the improvement, they made to it.
  • less FileName => Now we can use PgUp and PgDn key to move from one page to another. Also, we can use arrow keys to go down or up just one line at a time.
  • And to quit out of less, we type q key.
  • less -M FileName => At the bottom of the page, we see the name of the file along with lines in the file and also at which line, we are looking at, and also it gives us percentage.
  • less is good for looking at the whole file but sometimes we just want to look first few lines on the file or the heading of the file, for that we use head.

Head

  • head is used when we want to see just a few beginning lines of the page.
  • head FileName => This shows first 10 lines of the text file.
  • head -n 25 FileName or head -n25 FileName => it will show the first 25 lines of the file. So basically you can write any number at the place of 25.
  • The default number is 10 but we can change it using -n.

Tail

  • tail FileName => command shows us last 10 lines of the text file.
  • tail -f FileName => What this does is that if new lines are being added to this file. You will see new line at once without closing and opening the file again.
  • tail -n5 FileName => you know what it does now.
  • you can use Ctrl+C to return to the main terminal.