How to view contents of a file in Linux

view file in linux

You can use any of the method given below to view contents of a file in Linux. Let us say the file name is “filename”. Then you can view its content…

1. using cat command

cat filename

or

cat < filename

2. using head command

head filename

3. using tail command

tail filename

4. using pg command

pg filename

5. using more command

more filename

6. using paste command

paste filename

7. using grep command

grep '.*' filename

8. using cut command

cut -c 1- filename

9. using while loop

while read line
>do
>echo $line
>done < filename

10. using xargs command

xargs -L1 < filename

11. using sed

sed '' filename

or

sed -n 'p' filename

or

sed -n '1, $p' filename

12. using awk

awk '1' filename

or

awk '{print;}' filename

or

awk '{print $0;}' filename

13. using perl

perl -pne '' filename

or

perl -ne 'print;' filename

or

perl -ne 'print $_;' filename

If you know some more ways then share them in comments.