Do not clear the screen after viewing a file with less

less -X /var/log/insecure
From the manpage: man less -X or --no-init Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen. Bonus: If you want to clear the screen after viewing a file this way that had sensitive information, hit or just type clear. Since is readily available, I don't know why less bothers to automatically clear. If you're viewing the file at all, chances are you want to see the output from it after you quit.
Sample Output
# less -X /var/log/acpid
....
[Thu Nov  1 13:09:15 2007] starting up
[Thu Nov  1 13:09:15 2007] 1 rule loaded
[Thu Nov  1 13:09:15 2007] client connected from 3180[82:82]
[Thu Nov  1 13:09:15 2007] 1 client rule loaded
[Thu Jan 17 15:15:08 2008] starting up
/var/log/acpid lines 1-43/69 61%
(q typed)
#

2
By: sonic
2016-06-24 13:53:49

What Others Think

Oh yeah, I can learn parameters. Look at me! I should get a freaking medal. Seriously though, this is one annoying feature has caused me to to hate less command, except for on terminals like PuTTY where I could scroll up and still see the file, but it still made it a pain because once I typed anything those characters were lost.. It ALMOST caused me to go back to using more, but after years of dealing with using less because it was better in every other way, I finally decided to spend the 48 seconds to figure out that you can indeed disable the feature, and probably disable more stuff that I don't want to disable.. but I'll deal with that when I come across it. Until then: cat >> ~/.bashrc alias less='less -FX' ^D . ~/.bashrc Then.. Oh no, I viewed /etc/shadow in front of that guy who has super powers and can memorize 150 characters in 3 seconds. He's going to plug those encrypted passwords into crack5 (which seems to still be the tool of choice after decades) and once it takes a few days for that super computer to brute force some important passwords, I will immediately be shot by firing squad because I'm a sys admin for.. North Korea? But wait, I was smart and when I saw him look I hit frantically! Maybe I'll get to live after all. Why did I ever mess with the default security of this program to save myself a few seconds of trouble every once in a while!?? Umm anyway, since I'm supposed to be posting this from North Korea and I'm not using a VPN + TOR, I might as well say that Kim Jong Un is great. Our fearless leader can climb mountains that make him more powerful than nuclear bombs. Now back to work for me, or maybe I should take a break and play homefront revolution. Happy Friday!
sonic · 120 weeks and 4 days ago
I hit ctrl+l frantically, but I screwed up in the text so I screwed up in my story too. Consider me dead.
sonic · 120 weeks and 4 days ago
head soccer 2
headsoccer · 118 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: