whats the use of less & more commands in shell programming???
can anyone help......
I hav read on net but i didnt get how to use it.........

Dani AI

Generated

As already pointed out, more and less are pagers: interactive viewers that let a person inspect long text without dumping every line to the terminal. Additional context for shell usage: pagers are designed for manual exploration, not for unattended scripts. For automation, prefer text-processing filters that extract exactly the lines needed; pagers are best when a human needs to search, jump, or page through output.

Practical less tips that were not covered above: use in-view search with /pattern then n/N to repeat; jump to start/end with g/G; show line numbers with -N; avoid line wrapping with -S so very long lines scroll horizontally; preserve ANSI color escapes with -R; enter follow mode with +F to watch new output; press h inside less for built-in help. Compressed logs can be inspected with zless, and the LESS environment variable can hold preferred defaults (for example line numbers and raw control handling).

For : try a combination like less -N -S file.log to see numbered lines and avoid wrapped text while exploring. When building scripts or cron jobs, extract and act on data with grep, awk, or sed rather than relying on an interactive pager. Official references: less manual and more(1) man page.

Recommended Answers

All 2 Replies

Okay, it's good that you're interested!

Let's take an example:
You have a file which is 1Gb in size. You know that opening the file in the shell (e.g using 'cat') is going to be inefficient, as you'll have to scroll through a lot of lines to get to where you want to look. So less and more are basically alternatives to save resources and/or to only select the information that you're interested in.

The default behaviour of more is that the file content scrolls up one screen height at a time, and the space bar is used to advance to the next page. The command less is a more sophisticated version of more. Less can scroll backwards and has many more options over more. (There is plenty of information about this on the web).

If you're viewing a large log file and are only interested in what's happened most recently, then I would usually recommend using 'tail -f file.log' which would display the last 'x' number of lines of that file.

thanx...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.