Reading with Less
Less is a viewer that shows a file one screen at a time. It opens the file for reading, and it leaves the file unchanged.
Read a short file
Less with -FX prints the file and exits at once.
$ cd ~/practice
$ less -FX projects/report.txtRead the log file
The same form works on any file in the folder.
$ cd ~/practice
$ less -FX data/logs.txtExample
$ cd ~/practice
$ less -FX projects/report.txt
$ less -FX data/logs.txtKey points
- Use less to read a file that is longer than one screen.
- Less shows the first screen of the file.
- Press the down arrow to move down through the file, and the up arrow to move back up.
- Press q to quit Less and return to the prompt.
- The -FX options print the file and exit at once.
- A long file opens inside Less, one screen at a time.
In this example, Less opens the report file first. It prints four lines, then exits. Then it opens the log file. It prints five lines, then exits. Both files are short, so Less prints each one and exits at once.
Note
Less reads a file, and it never changes the file.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does less do?