Hot answers tagged

361

Use: git diff --color=always | less -r --color=always is there to tell git to output color codes even if the output is a pipe (not a tty). And -r is there to tell less to interpret those color codes and other escape sequences. Use -R for ANSI color codes only.


141

less +G app.log + will run an initial command when the file is opened G jumps to the end When multiple files are in play, ++ applies commands to every file being viewed. Not just the first one. For example, less ++G app1.log app2.log.


104

From less, type s then type the file name you want to save to, then Enter. From the man page, under COMMANDS: s filename Save the input to a file. This only works if the input is a pipe, not an ordinary file. man page also states that, depending on your particular installation, the s command might not be available. In that case, you could go to line ...


91

Although both commands allow you to view the content of a file, their original purposes are quite different. less extends the capabilities of more. The latter was created to view the content of a file one screenful at a time. less adds features such as backward movements and better memory management (no need to read the entire file before being able to see ...


91

less has very powerful pattern matching.  From the man page: &pattern Display only lines which match the pattern; lines which do not match the pattern are not displayed.  If pattern is empty (if you type & immediately followed by ENTER), any filtering is turned off, and all lines are displayed.  While filtering is in effect, an ...


68

This is actually a function of the terminal emulator you are using (xterm, gnome-terminal, konsole, screen). An alternate screen, or altscreen, gets launched when programs such as less or vim are invoked. This altscreen has no history buffer and exits immediately when you quit the program, switching back to the original screen which restores the previous ...


59

You can use Alt+u to remove the highlight on last search results. You can highlight them again with Alt+u, it's a toggle. Switching off the highlight does not switch off the status column, showing marks on each line containing a match, if the column is enabled using options -J or --status-column or keys -J. To hide the status column, use -+J. To show ...


57

Another option would be to enable colors and use 'less -r' as your pager. git config --global color.ui true git config --global core.pager 'less -r' This results in [color] ui = true [core] pager = less -r in your ~/.gitconfig For more information see the Pro Git book.


53

Just prefix it with ./: less ./- Or use redirection: less < - Note that since - (as opposed to -x or --foo-- for instance) is considered a special filename rather than an option, the following doesn't work: less -- - # THIS DOES NOT WORK


52

As mentioned by William Pursell, less reads the user’s keystrokes from the terminal. It explicitly opens /dev/tty, the controlling terminal; that gives it a file descriptor, separate from standard input, from which it can read the user’s interactive input. It can simultaneously read data to display from its standard input if necessary. (It could also write ...


47

Yes, it is possible with less -x or less --tabs, e.g. less -x4 will set the tabwidth to 4. You can configure defaults with the LESS environment variable, e.g. LESS="-x4".


44

Termcap is a library that Less uses to access the terminal. Termcap is largely obsolete, having been replaced by Terminfo, but Terminfo offers a Termcap compatibility interface to applications. Less is content with the Termcap interface and uses that. The Termcap library is a description of the terminal's facilities. Each facility is identified by a two-...


41

Simply type: less +F filename This emulates pressing "F" within the editor.


41

To quit less, type q. Also, check out man less, or type h from within less for some more, useful bits of information. In general, assuming man has been properly installed, man xyz will tell you how to use the xyz tool. On GNU systems like Cygwin or what you call Linux at least, man will usually display through less as well, so to exit from man, again you ...


40

less doesn't support syntax highlighting. vim, like all vi clones has a read-only mode called view which you can use to just view files. it supports all features of vim including syntax highlighting. e.g. view filename.py the main difference between view and vi is that view doesn't "lock" the file you're viewing by creating a .swp file.


40

Yes, less can follow by file name The feature has a fairly obscure syntax: less --follow-name +F file.log With less, --follow-name is different from the tail option --follow=name. It does not make less follow the file, instead it modifies the behaviour of the command key F inside of less to follow based on the file name, not the file descriptor. Also, ...


39

You can turn off regex mode by hitting Ctrl+R before typing the pattern: ^R Don't interpret regular expression metacharacters; that is, do a simple textual comparison.


37

Short answer: Just use less and forget about more Longer version: more is old utility You can't browse step wise with more, you can use space to browse page wise, or enter line by line, that is about it. less is more + more additional features You can browse page wise, line wise both up and down, search


36

I think you've covered the main point: less +F reads the whole file, whereas on many systems tail -f only reads the end of the file, and even on the systems where it does read the whole file, at least it doesn't keep the whole file in memory. That makes less +F impractical for very large files. You can, however, run less -n +F, which causes less to read only ...


36

less +F filename will go to the end and tail the file. From less man page: F Scroll forward, and keep trying to read when the end of file is reached. Normally this command would be used when already at the end of the file. It is a way to monitor the tail of a file which is growing while it is being viewed. (The behavior is similar to the "tail -...


35

Syntax highlighting of less, works just fine on most *nix systems. apt install source-highlight export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s" export LESS=' -R ' On Fedora/RedHat based distros use /usr/bin/src-hilite-lesspipe.sh instead. Even on Cygwin you can do it with the minor adjustment of the shell script path and ...


35

The most obvious one is cat. But, also have a look at head and tail. There are also other shell utillities to print a file line by line: sed, awk, grep. But those are to alternate the file content or to search inside the file. I made a few tests to estimate which is the most effective one. I run all trough strace to see which made the least system calls. My ...


33

The less-specific answer has already been given, but a generic solution (for any pager) is to expand the tabs (with space characters) with the expand command before feeding to the pager: expand -t4 file | pager


31

Actually it uses whatever is specified in the MANPAGER or the PAGER environment variable. Depending on your man implementation and version there could be also a command line switch to specify the pager. With the man-db implementation I use all the below ways work: MANPAGER=cat man man PAGER=cat man man MANOPT='-P cat' man man man -P cat man To set it ...


31

diff cannot output colors, you need another program, such as colordiff for that. Colors in the terminal are printed via ANSI escape codes which less does not interpret by default. To get less to correctly show colors, you need the -r, or even better, -R switch: colordiff -- "$file1" "$file2" | less -R From man less: -R or --RAW-CONTROL-CHARS ...


30

less prints text to stdout. stdout goes to a terminal (/dev/tty?) and opens the default buffer viewer through a pipe when piping it to another programm using | (less text | cut -d: -f1) to a file when redirecting it with > (less text > tmp) There is a C function called "isatty" which checks if the output is going to a tty (less 4.81, main.c, line 112). ...


29

Use -r (--raw-control-chars) option to less, or also -R (only ANSI escape sequences). I have an alias for this in ~/.bashrc alias rless='less -r'


29

You can use a regular expression: &!cat|dog|fish


29

/70\.5 will do the trick (inside less).


Only top voted, non community-wiki answers of a minimum length are eligible