How to display the contents of a file in unix

there are many ways to view the contents of a file

=commands=
 * cat command: print all the contents of the file in terminal. If the contents of your file is larger than a page, cat will not stop paging through the program until it hits the end
 * Hint: shift-page up and shift-page down allow you to page up and down in you terminal, so you can view previous output


 * more: prints the contents of a file. If the file is more than a page, it waits and allows you to scroll down the page with the down arrow key.  It does not let you go up in the file


 * less: is like more but allows you to go up and down in the file. It also uses page up and page down, and many other functions like searching.

See: Howto use the less command

=Commands for displaying parts of files=
 * head: displays the first 10(default) lines of a file


 * -c, --bytes=[-]N
 * print the first N bytes of each file;  with  the  leading  `-',print all but the last N bytes of each file


 * -n, --lines=[-]N
 * print the first N lines instead of the first 10; with the leading `-', print all but the last N lines of each file


 * -q, --quiet, --silent
 * never print headers giving file names


 * -v, --verbose
 * always print headers giving file names


 * tail: similar to head except prints the last 10(default) lines of a file.


 * --retry
 * keep trying to open a file even if it is inaccessible when tail starts or if it becomes inaccessible later -- useful only with -f


 * -c, --bytes=N
 * output the last N bytes


 * -f, --follow[={name|descriptor}] output appended data  as the file grows;
 * -f, --follow, and --follow=descriptor are  equivalent


 * -n, --lines=N
 * output the last N lines, instead of the last 10


 * --max-unchanged-stats=N
 * with --follow=name, reopen a FILE which has not changed size after N (default 5) iterations to see if it has been unlinked or  renamed  (this  is  the usual case of rotated log files)


 * --pid=PID
 * with -f, terminate after process ID, PID dies


 * -q, --quiet, --silent
 * never output headers giving file names


 * -s, --sleep-interval=S
 * with -f,  each  iteration  lasts  approximately  S (default 1) seconds


 * -v, --verbose
 * always output headers giving file names


 * --help display this help and exit


 * --version
 * output version information and exit


 * grep: displays all lines that match a specified phrase
 * Usage: grep phrase filename
 * See: Howto use the grep command


 * sed : sed is very complex.
 * See: Howto use the sed command


 * gawk : gawk is very complex.
 * See: Howto use the gawk command

=pipes=
 * cat filename|head
 * same as head filename


 * cat filename|tail
 * same as head filename


 * cat filename|more
 * same as more filename


 * cat filename|grep phrase
 * same as head phrase filename


 * cat filename|head|grep phrase
 * prints the first 10 line that have if they have phrase in them
 * same as head filename|grep phrase


 * cat filename|grep phrase|head
 * prints the first 10 line that have phrase in them
 * same as grep phrase filename|head

=See Also=
 * Guide to unix text editors

From HowTo Wiki, a Wikia wiki.