Linux And Unix Command To View File

There are several commands you can use to view a file in Linux and Unix operating systems:

  1. cat: The cat command is used to concatenate and display the contents of a file. It can be used to view the entire contents of a file or to display specific parts of a file. For example:
cat file.txt
  1. less: The less command is a program similar to cat that allows you to view a file one page at a time. You can use the up and down arrows to navigate through the file and type q to quit. For example:
less file.txt
  1. head: The head command is used to display the first few lines of a file. By default, it displays the first 10 lines, but you can specify a different number of lines using the -n option. For example:
head -n 20 file.txt
  1. tail: The tail command is used to display the last few lines of a file. By default, it displays the last 10 lines, but you can specify a different number of lines using the -n option. For example:
tail -n 20 file.txt
  1. more: The more command is similar to the less command, but it does not allow you to scroll backwards through the file. For example:
more file.txt

Leave a Comment