How To Read Text Files In Linux?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
1. Use the “cat” command:
The “cat” command is one of the most frequently used commands on Linux and Unix-like operating systems. It reads the given file(s) and prints their contents to the standard output (usually, the shell). To read a text file called “filename.txt”, type the following command at the prompt, and press ‘Enter’:
$ cat filename.txt
2. Use the “less” command:
The “less” command allows you to view the contents of a file page-by-page. To view the contents of a file called “filename.txt”, type the following command at the prompt, and press ‘Enter’:
$ less filename.txt
3. Use the “more” command:
The “more” command is similar to the “less” command. It displays the contents of the file page-by-page. To view the contents of a file called “filename.txt”, type the following command at the prompt, and press ‘Enter’:
$ more filename.txt
4. Use the “head” command:
The “head” command is used to display the first few lines of a file. To view the first 10 lines of a file called “filename.txt”, type the following command at the prompt, and press ‘Enter’:
$ head -n 10 filename.txt
5. Use the “tail” command:
The “tail” command is used to display the last few lines of a file. To view the last 10 lines of a file called “filename.txt”, type the following command at the prompt, and press ‘Enter’:
$ tail -n 10 filename.txt