Linux File Viewing Commands: cat, less, more

There are various ways to view the contents of a file in Linux.

  1. By using the ‘cat’ command with the file name, you can display the entire content of the file.
  2. To view the contents of a file in a paginated way, you can use the command “less file name”. Use the up and down arrow keys to scroll through the file, and press the “q” key to exit.
  3. To utilize the ‘more’ command, enter ‘more’ followed by the file name, which is similar to ‘less’ and allows for viewing the file content page by page. Scroll through the file using the space key and exit by pressing the q key.
  4. By using the “head” command with the file name, you can display the first few lines of a file, with the default being the first 10 lines.
  5. The tail command can display the last few lines of a file by default, showing up to the last 10 lines. You can specify the number of lines to display by using the -n parameter, for example, tail -n 20 filename will display the last 20 lines.
  6. With the grep command, you can search for lines containing a specific keyword in a file by using the command “grep” followed by the keyword and file name.

These are just a few common ways to view the content of files, and different commands can be selected based on specific needs.

bannerAds