



(13 ratings)
< Viewing text files with cat >
Many
files on a Linux system are files that are human readable and can be
viewed as text. For example, shell scripts are just simple text files,
as well as many of the important configuration files that can be edited
by hand. This is why Linux provides many ways of editing and viewing
text files, but here I'll concentrate on cat and less.
cat is a simple little program that displays the contents of a text file when you give the file name as an argument to it:$ cat view_this
This
is a nice way of viewing short files that fit on your screen, but if
the file is so long that its contents cannot be displayed on your
screen all at once, you'll end up only staring at the end of the file.
Maybe not exactly what you want. In most cases, you'll want to use less instead.
< Using the less command >
less is a program that lets you view text files, like cat does, but if the files are so long that they don't fit on your screen, less automatically paginates the file. You use less by giving the file name as an argument to it:$ less view_this
When viewing the file, you can use Page Up and Page Down keys to move through the file, and typing q will exit.
You
can also open several files at the same time so you can navigate from
one file to next without closing it first. If you want to open several
files, just give all the file names at once:$ less file1 file2 file3
When viewing several files at the same time, you can use :n for examining the next file and :p for the previous file.
Here are some, but absolutely not all, of the commands you can use in less:
| Command / key | Action |
| e, j, Down, or Enter | move forward one line |
| y, k, or Up | move backward one line |
| f, Space, or Page Down | move forward one page |
| b, or Page Up | move backward one page |
| /characters | search forward in the file for lines containing the specified characters |
| n | repeat the previous search |
| :e file_name | examine a new file |
| :n | examine the next file |
| :p | examine the previous file |
| h, or ? | display help |
| q | quit |
20 Random Tutorials from the same category :
The humble Linux cheat sheet
Moving around in the Linux file system
Pipes - Get the most out of your shell
Getting LILO to boot Windows (by default)
Wildcards, Quotes, Back Quotes and Apostrophes in shell commands ( * ? [] " ` ')
Linux command line terminology
Unix Multi-Process Programming and Inter-Process Communications (IPC)
Redirecting standard input and output
How and when to use the dd command?
Installing software from source in Linux
Change from text login to graphical login
Automating Program Compilation - Writing Makefiles
How to find - Size of a directory & Free disk space
How to set Shell Environment Variables (bash shell)
Understanding software Installation (configure, make, make install)
Linux file permissions
Running multiple X sessions
Execute a task 'at' the time you want..
Asking questions in a discussion forum
Understanding file permissions and modifying them using chmod













