26

Rather than scroll past hundreds of lines of output to see the previous command history, can the output of the last command be cleared? E.g. after executing ls, clear its output because you don't need it any more.

EDIT:

This is not your usual clear or ctrl+L operation. The idea is to scroll back though the history looking for the output of a previous command, but without having to have to scroll past a load of ls, or cat, or sudo apt-get install output unless I really want to. It might look something like this:

cat fileIWantToRemember
ls directoryIWantToForget
# some command that wipes the output of ls
# scroll back to see the output of cat immediately
6
  • Do you mean to clear the output, or to remove the command from your command history? If you want to modify your command history, maybe this thread addresses what you're looking for?
    – ernie
    Sep 24, 2013 at 23:40
  • The terminal just displays a stream of text, and stores some in its own internal buffer. It has no way of knowing, or discriminating between command output. The rxvt-unicode terminal does have a perl interpreter that might be able to implement something like this. But as far as I know it's not done.
    – Keith
    Sep 25, 2013 at 4:06
  • A long time ago, I used a terminal emulator on Mac OS X which had this feature, but I can't remember what it was called any more. It wasn't free, though. However, while doing a quick google search for it, I ran into finalterm.org, which looks like it is trying to implement that feature. However, "Final Term is in heavy development and neither stable nor feature complete!", so I didn't try it. Looks interesting, though. The google search, for what it's worth, was terminal emulator output folding
    – rici
    Sep 25, 2013 at 4:38
  • Final Term is heavily-enough developed to fold commands (and lots of other amazing stuff), and once there's a keyboard shortcut to do that then problem solved. I was beginning to think I was crazy...
    – nacnudus
    Sep 25, 2013 at 10:50
  • 2
    it is not your exact answer but in such cases to view content of big files I use 'less' command instead of 'cat'. Another thing is if any command give huge number of lines as output to console you can avoid it by writing "$ the-command | less".
    – Devasish
    Jan 29, 2020 at 11:40

3 Answers 3

5

With thanks to @rici, this behaviour can be called "folding". The output of commands isn't forgotten, but you can hide it until you need it again. Folding is common in text editors but seems to be rare in terminal emulators.

Final Term is a new terminal emulator that includes folding among many other fancy tricks. Beware: "Final Term is in heavy development and neither stable nor feature complete!" It was heavily-enough developed to fold my commands when I tested it, but too unstable not to crash. One to watch.

1
  • Do you have more info on Final Term, it's site is a single static page which doesn't provides any download link, no source code link and the only timestamp is from 2020, it it still active ?
    – adamency
    Oct 17, 2023 at 13:01
0

In bash, you can press the shortcut Ctrl + L to clear the screen, similar to the clear command. (http://ss64.com/bash/syntax-keyboard.html)

Or, you can use history | tail -3 to see the last three commands. (http://www.howtogeek.com/howto/44997/how-to-use-bash-history-to-improve-your-command-line-productivity/)

4
  • See my comment to @Justin below, the point is not to have to scroll past it when looking through the history for something else. Something like HISTCONTROL=ignorespace in your second link that you can use after the fact would be good.
    – nacnudus
    Sep 24, 2013 at 23:42
  • I'm a bit lost on what you want to achieve. Another thought, in many consoles I used, you can usually use arrow keys to browse command history in bash, does this apply to your situation?
    – phe0113
    Sep 24, 2013 at 23:47
  • Does my edit clarify the question?
    – nacnudus
    Sep 24, 2013 at 23:56
  • @nacnudus, yes, I get your point now :)
    – phe0113
    Sep 25, 2013 at 0:22
0

It sounds as if you want to remove items from your history. To do this, you'll first need to enable the writing of history on the fly, rather than on logout by editing your ~/.bashrc and adding:

shopt -s histappend; export PROMPT_COMMAND='history -a';'

Then, to delete items you can do:

history -d offset, where offset is the history entry you want to delete

Based on this forum thread.

1
  • 4
    This seems to delete it from the history file, which is almost the right idea, but can it wipe it from the current terminal?
    – nacnudus
    Sep 24, 2013 at 23:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .