How do I clear the Gnome terminal history?
Clash Royale CLAN TAG#URR8PPP
up vote
58
down vote
favorite
When we use clear
command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?
terminal command-history gnome-terminal escape-characters
add a comment |Â
up vote
58
down vote
favorite
When we use clear
command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?
terminal command-history gnome-terminal escape-characters
It's terminal dependent, and none of the answers address that.
â Thomas Dickey
Oct 19 '16 at 1:11
add a comment |Â
up vote
58
down vote
favorite
up vote
58
down vote
favorite
When we use clear
command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?
terminal command-history gnome-terminal escape-characters
When we use clear
command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?
terminal command-history gnome-terminal escape-characters
terminal command-history gnome-terminal escape-characters
edited Sep 3 at 13:01
Neil G
1538
1538
asked Dec 16 '11 at 13:18
hpn
66151420
66151420
It's terminal dependent, and none of the answers address that.
â Thomas Dickey
Oct 19 '16 at 1:11
add a comment |Â
It's terminal dependent, and none of the answers address that.
â Thomas Dickey
Oct 19 '16 at 1:11
It's terminal dependent, and none of the answers address that.
â Thomas Dickey
Oct 19 '16 at 1:11
It's terminal dependent, and none of the answers address that.
â Thomas Dickey
Oct 19 '16 at 1:11
add a comment |Â
9 Answers
9
active
oldest
votes
up vote
68
down vote
accepted
You can use tput reset
.
Besides reset
and tput reset
you can use following shell script.
#!/bin/sh
echo -e \033c
This sends control characters Esc-C
to the console which resets the terminal.
Google Keywords: Linux Console Control Sequences
man console_codes
says:
The sequence ESC c causes a terminal reset, which is what you want if
the screen is all garbled. The oft-advised "echo ^V^O" will only make
G0 current, but there is no guarantee that G0 points at table a). In
some distributions there is a program reset(1) that just does "echo
^[c". If your terminfo entry for the console is correct (and has an
entry rs1=Ec), then "tput reset" will also work.
1
What's the difference between reset and tput reset?
â Toothrot
Oct 18 '16 at 12:19
tput reset
is faster thanreset
in Ubuntu 16.04, at least
â Iván RodrÃguez Torres
Feb 13 '17 at 11:22
5
-1, you can still see the buffer if you scroll up
â João Pimentel Ferreira
Jun 18 '17 at 10:31
add a comment |Â
up vote
15
down vote
You can use the reset
command, that will reset the terminal settings.
add a comment |Â
up vote
15
down vote
I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:
If you're using Terminal.app
or iTerm.app
then Control+L
will scroll up so the terminal looks blank, but Cmd+K
will actually reset the terminal / clear scroll-back.
Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K
to input echo -e \033c
as was mentioned above.
2
Cmd+K
is all i wanted. ty
â Gaurav Gandhi
Mar 30 '16 at 11:13
add a comment |Â
up vote
8
down vote
Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:
alias allclear='clear; echo -e "33ce[3J"'
But it doesn't work on OS X.
tput reset
doesn't work in any context AFAICT.
In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:
urxvt*keysym.C-S-K: command:33c
This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear):allclear()
` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"`` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
â KLaw
Feb 7 at 16:26
add a comment |Â
up vote
3
down vote
I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.
echo -e "e[3J"
add a comment |Â
up vote
2
down vote
I mapped F12 to clear screen in each of the following shells: bash, csh and fish shell.
My command is different from all previous ones because it preserves whatever you've already typed in the current line.
(Note: all the configurations below are terminal dependent, but I hope they will work virtually everywhere)
bash
Open the file ~/.inputrc
and insert the following line:
"e[24~": "C-k C-uecho -ne '\ec\e[3J'; history -d $((HISTCMD-1))nC-yC-?"
To have the new key binding available, either open a new terminal or type Ctrl+X then Ctrl+R to reload the .inputrc file in the current terminal.
Explanation
The file ~/.inputrc controls the key bindings of the bash terminal.
About the line:
- The first part of the line,
"e[24~"
, maps the key F12. - The
C-k
(Ctrl+X) clears the kill-ring (bash's copy-and-past memory). - The space avoids a beep in the next command.
- The
C-u
(Ctrl+U) sends the current line to the kill-ring, and erase it. - The
echo -ne '\ec\e[3J'; history -d $((HISTCMD-1))n
sends two grouped commands to the terminal. They are separated by;
and terminated byn
.- The
echo -ne '\ec\e[3J'
clears the screen. - The
history -d $((HISTCMD-1))
avoids these two commands from entering in history.
- The
- The
C-y
(Ctrl+Y) pastes the kill-ring stored by theC-u
command. - The
C-?
(Ctrl+?) is equivalent to Backspace and removes the space inserted in step 3 above.
References:
- How to bind a function key to a command in bash (and how to prevent Ctrl+U from ringing):
https://stackoverflow.com/a/4201274/1669975 - How to reload the .inputrc file: https://superuser.com/a/241190/595358
- How to execute a command without keeping it in history: https://stackoverflow.com/a/33511637/1669975
csh
Type the command bellow.bindkey -c "^[[24~" "echo -ne 'ece[3J'"
It can also be inserted in your .cshrc
file to load the key binding to every new terminal.
(Yes, it is much simpler than in bash)
fish shell
Type the command bellow.bind -k f12 "echo -ne 'ece[3J'; commandline -f repaint"
You can edit and save the function fish_user_key_bindings
to load the key binding to every new terminal.
(Yes, it is much simpler than in bash)
add a comment |Â
up vote
1
down vote
For me, using PuTTY against CentOS 7, clear leaves only the clear command in the scrollback, but running "clear && clear", two instances of the clear command at the same time, completely clears the scrollback and leaves me with no scrollbar. Try that. It's a weird solution but none of these here cleared the scrollback that effectively, and this does.
add a comment |Â
up vote
1
down vote
[Ubuntu 16.04]
The .bash_history file is created in the user's home directory once the terminal is closed
It is useful, but you could delete it if you wish.. Nevertheless it would be created every time you finish using the terminal.
You could delete it manually from:
your files browser.
the terminal: remember that a new .bash_history file will be created when you close the terminal (based in its default configuration).
Or you can call a custom function if you save the functionality you need into a file linked from the bashrc.. you could edit the bashrc itself if you like putting your code there, but the next examples are in a separate file
Honestly this is not useful for me but if you wish is to delete the commands history before exit you could do this:
.bash_custom #this is my custom file
blotout()
HISTSIZE=0
rm $HOME/.bash_history
exit
then at the bottom of add the name and path of my file
.bashrc # this is the configuration file for the bash (I think)
# existent code
#...
#..
# import user customizations
source $HOME/.bash_custom
and thatà  all.
BUT, to do exactly what you want you just need this function in your custom file and link it:
refresh()
tput reset
H=HISTSIZE
HISTSIZE=0
HISTSIZE=H
Or just put the function in the .bashrc if you want but that way you probably need an export statement after the function I'm not sure and if the file is updated probably lost your functions.. I'm not sure about that too :D .
Remember you have to re-start the terminal when edit the .bashrc or your 'custom' file.
add a comment |Â
up vote
0
down vote
Added to ~/.inputrc
to bind the complete clearing to F12:
"e[24~":'!echo -ne 47\0033\014347r'
add a comment |Â
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
68
down vote
accepted
You can use tput reset
.
Besides reset
and tput reset
you can use following shell script.
#!/bin/sh
echo -e \033c
This sends control characters Esc-C
to the console which resets the terminal.
Google Keywords: Linux Console Control Sequences
man console_codes
says:
The sequence ESC c causes a terminal reset, which is what you want if
the screen is all garbled. The oft-advised "echo ^V^O" will only make
G0 current, but there is no guarantee that G0 points at table a). In
some distributions there is a program reset(1) that just does "echo
^[c". If your terminfo entry for the console is correct (and has an
entry rs1=Ec), then "tput reset" will also work.
1
What's the difference between reset and tput reset?
â Toothrot
Oct 18 '16 at 12:19
tput reset
is faster thanreset
in Ubuntu 16.04, at least
â Iván RodrÃguez Torres
Feb 13 '17 at 11:22
5
-1, you can still see the buffer if you scroll up
â João Pimentel Ferreira
Jun 18 '17 at 10:31
add a comment |Â
up vote
68
down vote
accepted
You can use tput reset
.
Besides reset
and tput reset
you can use following shell script.
#!/bin/sh
echo -e \033c
This sends control characters Esc-C
to the console which resets the terminal.
Google Keywords: Linux Console Control Sequences
man console_codes
says:
The sequence ESC c causes a terminal reset, which is what you want if
the screen is all garbled. The oft-advised "echo ^V^O" will only make
G0 current, but there is no guarantee that G0 points at table a). In
some distributions there is a program reset(1) that just does "echo
^[c". If your terminfo entry for the console is correct (and has an
entry rs1=Ec), then "tput reset" will also work.
1
What's the difference between reset and tput reset?
â Toothrot
Oct 18 '16 at 12:19
tput reset
is faster thanreset
in Ubuntu 16.04, at least
â Iván RodrÃguez Torres
Feb 13 '17 at 11:22
5
-1, you can still see the buffer if you scroll up
â João Pimentel Ferreira
Jun 18 '17 at 10:31
add a comment |Â
up vote
68
down vote
accepted
up vote
68
down vote
accepted
You can use tput reset
.
Besides reset
and tput reset
you can use following shell script.
#!/bin/sh
echo -e \033c
This sends control characters Esc-C
to the console which resets the terminal.
Google Keywords: Linux Console Control Sequences
man console_codes
says:
The sequence ESC c causes a terminal reset, which is what you want if
the screen is all garbled. The oft-advised "echo ^V^O" will only make
G0 current, but there is no guarantee that G0 points at table a). In
some distributions there is a program reset(1) that just does "echo
^[c". If your terminfo entry for the console is correct (and has an
entry rs1=Ec), then "tput reset" will also work.
You can use tput reset
.
Besides reset
and tput reset
you can use following shell script.
#!/bin/sh
echo -e \033c
This sends control characters Esc-C
to the console which resets the terminal.
Google Keywords: Linux Console Control Sequences
man console_codes
says:
The sequence ESC c causes a terminal reset, which is what you want if
the screen is all garbled. The oft-advised "echo ^V^O" will only make
G0 current, but there is no guarantee that G0 points at table a). In
some distributions there is a program reset(1) that just does "echo
^[c". If your terminfo entry for the console is correct (and has an
entry rs1=Ec), then "tput reset" will also work.
edited Dec 16 '11 at 14:23
answered Dec 16 '11 at 13:55
Sachin Divekar
3,7381619
3,7381619
1
What's the difference between reset and tput reset?
â Toothrot
Oct 18 '16 at 12:19
tput reset
is faster thanreset
in Ubuntu 16.04, at least
â Iván RodrÃguez Torres
Feb 13 '17 at 11:22
5
-1, you can still see the buffer if you scroll up
â João Pimentel Ferreira
Jun 18 '17 at 10:31
add a comment |Â
1
What's the difference between reset and tput reset?
â Toothrot
Oct 18 '16 at 12:19
tput reset
is faster thanreset
in Ubuntu 16.04, at least
â Iván RodrÃguez Torres
Feb 13 '17 at 11:22
5
-1, you can still see the buffer if you scroll up
â João Pimentel Ferreira
Jun 18 '17 at 10:31
1
1
What's the difference between reset and tput reset?
â Toothrot
Oct 18 '16 at 12:19
What's the difference between reset and tput reset?
â Toothrot
Oct 18 '16 at 12:19
tput reset
is faster than reset
in Ubuntu 16.04, at leastâ Iván RodrÃguez Torres
Feb 13 '17 at 11:22
tput reset
is faster than reset
in Ubuntu 16.04, at leastâ Iván RodrÃguez Torres
Feb 13 '17 at 11:22
5
5
-1, you can still see the buffer if you scroll up
â João Pimentel Ferreira
Jun 18 '17 at 10:31
-1, you can still see the buffer if you scroll up
â João Pimentel Ferreira
Jun 18 '17 at 10:31
add a comment |Â
up vote
15
down vote
You can use the reset
command, that will reset the terminal settings.
add a comment |Â
up vote
15
down vote
You can use the reset
command, that will reset the terminal settings.
add a comment |Â
up vote
15
down vote
up vote
15
down vote
You can use the reset
command, that will reset the terminal settings.
You can use the reset
command, that will reset the terminal settings.
answered Dec 16 '11 at 13:33
enzotib
32.5k710292
32.5k710292
add a comment |Â
add a comment |Â
up vote
15
down vote
I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:
If you're using Terminal.app
or iTerm.app
then Control+L
will scroll up so the terminal looks blank, but Cmd+K
will actually reset the terminal / clear scroll-back.
Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K
to input echo -e \033c
as was mentioned above.
2
Cmd+K
is all i wanted. ty
â Gaurav Gandhi
Mar 30 '16 at 11:13
add a comment |Â
up vote
15
down vote
I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:
If you're using Terminal.app
or iTerm.app
then Control+L
will scroll up so the terminal looks blank, but Cmd+K
will actually reset the terminal / clear scroll-back.
Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K
to input echo -e \033c
as was mentioned above.
2
Cmd+K
is all i wanted. ty
â Gaurav Gandhi
Mar 30 '16 at 11:13
add a comment |Â
up vote
15
down vote
up vote
15
down vote
I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:
If you're using Terminal.app
or iTerm.app
then Control+L
will scroll up so the terminal looks blank, but Cmd+K
will actually reset the terminal / clear scroll-back.
Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K
to input echo -e \033c
as was mentioned above.
I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:
If you're using Terminal.app
or iTerm.app
then Control+L
will scroll up so the terminal looks blank, but Cmd+K
will actually reset the terminal / clear scroll-back.
Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K
to input echo -e \033c
as was mentioned above.
answered Jan 7 '12 at 17:22
cwd
12.8k52114155
12.8k52114155
2
Cmd+K
is all i wanted. ty
â Gaurav Gandhi
Mar 30 '16 at 11:13
add a comment |Â
2
Cmd+K
is all i wanted. ty
â Gaurav Gandhi
Mar 30 '16 at 11:13
2
2
Cmd+K
is all i wanted. tyâ Gaurav Gandhi
Mar 30 '16 at 11:13
Cmd+K
is all i wanted. tyâ Gaurav Gandhi
Mar 30 '16 at 11:13
add a comment |Â
up vote
8
down vote
Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:
alias allclear='clear; echo -e "33ce[3J"'
But it doesn't work on OS X.
tput reset
doesn't work in any context AFAICT.
In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:
urxvt*keysym.C-S-K: command:33c
This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear):allclear()
` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"`` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
â KLaw
Feb 7 at 16:26
add a comment |Â
up vote
8
down vote
Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:
alias allclear='clear; echo -e "33ce[3J"'
But it doesn't work on OS X.
tput reset
doesn't work in any context AFAICT.
In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:
urxvt*keysym.C-S-K: command:33c
This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear):allclear()
` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"`` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
â KLaw
Feb 7 at 16:26
add a comment |Â
up vote
8
down vote
up vote
8
down vote
Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:
alias allclear='clear; echo -e "33ce[3J"'
But it doesn't work on OS X.
tput reset
doesn't work in any context AFAICT.
In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:
urxvt*keysym.C-S-K: command:33c
Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:
alias allclear='clear; echo -e "33ce[3J"'
But it doesn't work on OS X.
tput reset
doesn't work in any context AFAICT.
In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:
urxvt*keysym.C-S-K: command:33c
edited Mar 13 '15 at 12:00
answered Mar 13 '15 at 10:40
ecloud
8112
8112
This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear):allclear()
` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"`` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
â KLaw
Feb 7 at 16:26
add a comment |Â
This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear):allclear()
` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"`` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
â KLaw
Feb 7 at 16:26
This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear):
allclear()
` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"`
` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.â KLaw
Feb 7 at 16:26
This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear):
allclear()
` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"`
` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.â KLaw
Feb 7 at 16:26
add a comment |Â
up vote
3
down vote
I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.
echo -e "e[3J"
add a comment |Â
up vote
3
down vote
I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.
echo -e "e[3J"
add a comment |Â
up vote
3
down vote
up vote
3
down vote
I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.
echo -e "e[3J"
I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.
echo -e "e[3J"
edited Feb 25 '14 at 13:21
Anthon
58.9k1796160
58.9k1796160
answered Feb 25 '14 at 13:03
canon
4913
4913
add a comment |Â
add a comment |Â
up vote
2
down vote
I mapped F12 to clear screen in each of the following shells: bash, csh and fish shell.
My command is different from all previous ones because it preserves whatever you've already typed in the current line.
(Note: all the configurations below are terminal dependent, but I hope they will work virtually everywhere)
bash
Open the file ~/.inputrc
and insert the following line:
"e[24~": "C-k C-uecho -ne '\ec\e[3J'; history -d $((HISTCMD-1))nC-yC-?"
To have the new key binding available, either open a new terminal or type Ctrl+X then Ctrl+R to reload the .inputrc file in the current terminal.
Explanation
The file ~/.inputrc controls the key bindings of the bash terminal.
About the line:
- The first part of the line,
"e[24~"
, maps the key F12. - The
C-k
(Ctrl+X) clears the kill-ring (bash's copy-and-past memory). - The space avoids a beep in the next command.
- The
C-u
(Ctrl+U) sends the current line to the kill-ring, and erase it. - The
echo -ne '\ec\e[3J'; history -d $((HISTCMD-1))n
sends two grouped commands to the terminal. They are separated by;
and terminated byn
.- The
echo -ne '\ec\e[3J'
clears the screen. - The
history -d $((HISTCMD-1))
avoids these two commands from entering in history.
- The
- The
C-y
(Ctrl+Y) pastes the kill-ring stored by theC-u
command. - The
C-?
(Ctrl+?) is equivalent to Backspace and removes the space inserted in step 3 above.
References:
- How to bind a function key to a command in bash (and how to prevent Ctrl+U from ringing):
https://stackoverflow.com/a/4201274/1669975 - How to reload the .inputrc file: https://superuser.com/a/241190/595358
- How to execute a command without keeping it in history: https://stackoverflow.com/a/33511637/1669975
csh
Type the command bellow.bindkey -c "^[[24~" "echo -ne 'ece[3J'"
It can also be inserted in your .cshrc
file to load the key binding to every new terminal.
(Yes, it is much simpler than in bash)
fish shell
Type the command bellow.bind -k f12 "echo -ne 'ece[3J'; commandline -f repaint"
You can edit and save the function fish_user_key_bindings
to load the key binding to every new terminal.
(Yes, it is much simpler than in bash)
add a comment |Â
up vote
2
down vote
I mapped F12 to clear screen in each of the following shells: bash, csh and fish shell.
My command is different from all previous ones because it preserves whatever you've already typed in the current line.
(Note: all the configurations below are terminal dependent, but I hope they will work virtually everywhere)
bash
Open the file ~/.inputrc
and insert the following line:
"e[24~": "C-k C-uecho -ne '\ec\e[3J'; history -d $((HISTCMD-1))nC-yC-?"
To have the new key binding available, either open a new terminal or type Ctrl+X then Ctrl+R to reload the .inputrc file in the current terminal.
Explanation
The file ~/.inputrc controls the key bindings of the bash terminal.
About the line:
- The first part of the line,
"e[24~"
, maps the key F12. - The
C-k
(Ctrl+X) clears the kill-ring (bash's copy-and-past memory). - The space avoids a beep in the next command.
- The
C-u
(Ctrl+U) sends the current line to the kill-ring, and erase it. - The
echo -ne '\ec\e[3J'; history -d $((HISTCMD-1))n
sends two grouped commands to the terminal. They are separated by;
and terminated byn
.- The
echo -ne '\ec\e[3J'
clears the screen. - The
history -d $((HISTCMD-1))
avoids these two commands from entering in history.
- The
- The
C-y
(Ctrl+Y) pastes the kill-ring stored by theC-u
command. - The
C-?
(Ctrl+?) is equivalent to Backspace and removes the space inserted in step 3 above.
References:
- How to bind a function key to a command in bash (and how to prevent Ctrl+U from ringing):
https://stackoverflow.com/a/4201274/1669975 - How to reload the .inputrc file: https://superuser.com/a/241190/595358
- How to execute a command without keeping it in history: https://stackoverflow.com/a/33511637/1669975
csh
Type the command bellow.bindkey -c "^[[24~" "echo -ne 'ece[3J'"
It can also be inserted in your .cshrc
file to load the key binding to every new terminal.
(Yes, it is much simpler than in bash)
fish shell
Type the command bellow.bind -k f12 "echo -ne 'ece[3J'; commandline -f repaint"
You can edit and save the function fish_user_key_bindings
to load the key binding to every new terminal.
(Yes, it is much simpler than in bash)
add a comment |Â
up vote
2
down vote
up vote
2
down vote
I mapped F12 to clear screen in each of the following shells: bash, csh and fish shell.
My command is different from all previous ones because it preserves whatever you've already typed in the current line.
(Note: all the configurations below are terminal dependent, but I hope they will work virtually everywhere)
bash
Open the file ~/.inputrc
and insert the following line:
"e[24~": "C-k C-uecho -ne '\ec\e[3J'; history -d $((HISTCMD-1))nC-yC-?"
To have the new key binding available, either open a new terminal or type Ctrl+X then Ctrl+R to reload the .inputrc file in the current terminal.
Explanation
The file ~/.inputrc controls the key bindings of the bash terminal.
About the line:
- The first part of the line,
"e[24~"
, maps the key F12. - The
C-k
(Ctrl+X) clears the kill-ring (bash's copy-and-past memory). - The space avoids a beep in the next command.
- The
C-u
(Ctrl+U) sends the current line to the kill-ring, and erase it. - The
echo -ne '\ec\e[3J'; history -d $((HISTCMD-1))n
sends two grouped commands to the terminal. They are separated by;
and terminated byn
.- The
echo -ne '\ec\e[3J'
clears the screen. - The
history -d $((HISTCMD-1))
avoids these two commands from entering in history.
- The
- The
C-y
(Ctrl+Y) pastes the kill-ring stored by theC-u
command. - The
C-?
(Ctrl+?) is equivalent to Backspace and removes the space inserted in step 3 above.
References:
- How to bind a function key to a command in bash (and how to prevent Ctrl+U from ringing):
https://stackoverflow.com/a/4201274/1669975 - How to reload the .inputrc file: https://superuser.com/a/241190/595358
- How to execute a command without keeping it in history: https://stackoverflow.com/a/33511637/1669975
csh
Type the command bellow.bindkey -c "^[[24~" "echo -ne 'ece[3J'"
It can also be inserted in your .cshrc
file to load the key binding to every new terminal.
(Yes, it is much simpler than in bash)
fish shell
Type the command bellow.bind -k f12 "echo -ne 'ece[3J'; commandline -f repaint"
You can edit and save the function fish_user_key_bindings
to load the key binding to every new terminal.
(Yes, it is much simpler than in bash)
I mapped F12 to clear screen in each of the following shells: bash, csh and fish shell.
My command is different from all previous ones because it preserves whatever you've already typed in the current line.
(Note: all the configurations below are terminal dependent, but I hope they will work virtually everywhere)
bash
Open the file ~/.inputrc
and insert the following line:
"e[24~": "C-k C-uecho -ne '\ec\e[3J'; history -d $((HISTCMD-1))nC-yC-?"
To have the new key binding available, either open a new terminal or type Ctrl+X then Ctrl+R to reload the .inputrc file in the current terminal.
Explanation
The file ~/.inputrc controls the key bindings of the bash terminal.
About the line:
- The first part of the line,
"e[24~"
, maps the key F12. - The
C-k
(Ctrl+X) clears the kill-ring (bash's copy-and-past memory). - The space avoids a beep in the next command.
- The
C-u
(Ctrl+U) sends the current line to the kill-ring, and erase it. - The
echo -ne '\ec\e[3J'; history -d $((HISTCMD-1))n
sends two grouped commands to the terminal. They are separated by;
and terminated byn
.- The
echo -ne '\ec\e[3J'
clears the screen. - The
history -d $((HISTCMD-1))
avoids these two commands from entering in history.
- The
- The
C-y
(Ctrl+Y) pastes the kill-ring stored by theC-u
command. - The
C-?
(Ctrl+?) is equivalent to Backspace and removes the space inserted in step 3 above.
References:
- How to bind a function key to a command in bash (and how to prevent Ctrl+U from ringing):
https://stackoverflow.com/a/4201274/1669975 - How to reload the .inputrc file: https://superuser.com/a/241190/595358
- How to execute a command without keeping it in history: https://stackoverflow.com/a/33511637/1669975
csh
Type the command bellow.bindkey -c "^[[24~" "echo -ne 'ece[3J'"
It can also be inserted in your .cshrc
file to load the key binding to every new terminal.
(Yes, it is much simpler than in bash)
fish shell
Type the command bellow.bind -k f12 "echo -ne 'ece[3J'; commandline -f repaint"
You can edit and save the function fish_user_key_bindings
to load the key binding to every new terminal.
(Yes, it is much simpler than in bash)
edited Jun 12 '17 at 16:04
answered Jun 12 '17 at 14:23
Akira Cleber Nakandakare
214
214
add a comment |Â
add a comment |Â
up vote
1
down vote
For me, using PuTTY against CentOS 7, clear leaves only the clear command in the scrollback, but running "clear && clear", two instances of the clear command at the same time, completely clears the scrollback and leaves me with no scrollbar. Try that. It's a weird solution but none of these here cleared the scrollback that effectively, and this does.
add a comment |Â
up vote
1
down vote
For me, using PuTTY against CentOS 7, clear leaves only the clear command in the scrollback, but running "clear && clear", two instances of the clear command at the same time, completely clears the scrollback and leaves me with no scrollbar. Try that. It's a weird solution but none of these here cleared the scrollback that effectively, and this does.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
For me, using PuTTY against CentOS 7, clear leaves only the clear command in the scrollback, but running "clear && clear", two instances of the clear command at the same time, completely clears the scrollback and leaves me with no scrollbar. Try that. It's a weird solution but none of these here cleared the scrollback that effectively, and this does.
For me, using PuTTY against CentOS 7, clear leaves only the clear command in the scrollback, but running "clear && clear", two instances of the clear command at the same time, completely clears the scrollback and leaves me with no scrollbar. Try that. It's a weird solution but none of these here cleared the scrollback that effectively, and this does.
answered May 22 '17 at 20:19
Zoltan Shapiro
111
111
add a comment |Â
add a comment |Â
up vote
1
down vote
[Ubuntu 16.04]
The .bash_history file is created in the user's home directory once the terminal is closed
It is useful, but you could delete it if you wish.. Nevertheless it would be created every time you finish using the terminal.
You could delete it manually from:
your files browser.
the terminal: remember that a new .bash_history file will be created when you close the terminal (based in its default configuration).
Or you can call a custom function if you save the functionality you need into a file linked from the bashrc.. you could edit the bashrc itself if you like putting your code there, but the next examples are in a separate file
Honestly this is not useful for me but if you wish is to delete the commands history before exit you could do this:
.bash_custom #this is my custom file
blotout()
HISTSIZE=0
rm $HOME/.bash_history
exit
then at the bottom of add the name and path of my file
.bashrc # this is the configuration file for the bash (I think)
# existent code
#...
#..
# import user customizations
source $HOME/.bash_custom
and thatà  all.
BUT, to do exactly what you want you just need this function in your custom file and link it:
refresh()
tput reset
H=HISTSIZE
HISTSIZE=0
HISTSIZE=H
Or just put the function in the .bashrc if you want but that way you probably need an export statement after the function I'm not sure and if the file is updated probably lost your functions.. I'm not sure about that too :D .
Remember you have to re-start the terminal when edit the .bashrc or your 'custom' file.
add a comment |Â
up vote
1
down vote
[Ubuntu 16.04]
The .bash_history file is created in the user's home directory once the terminal is closed
It is useful, but you could delete it if you wish.. Nevertheless it would be created every time you finish using the terminal.
You could delete it manually from:
your files browser.
the terminal: remember that a new .bash_history file will be created when you close the terminal (based in its default configuration).
Or you can call a custom function if you save the functionality you need into a file linked from the bashrc.. you could edit the bashrc itself if you like putting your code there, but the next examples are in a separate file
Honestly this is not useful for me but if you wish is to delete the commands history before exit you could do this:
.bash_custom #this is my custom file
blotout()
HISTSIZE=0
rm $HOME/.bash_history
exit
then at the bottom of add the name and path of my file
.bashrc # this is the configuration file for the bash (I think)
# existent code
#...
#..
# import user customizations
source $HOME/.bash_custom
and thatà  all.
BUT, to do exactly what you want you just need this function in your custom file and link it:
refresh()
tput reset
H=HISTSIZE
HISTSIZE=0
HISTSIZE=H
Or just put the function in the .bashrc if you want but that way you probably need an export statement after the function I'm not sure and if the file is updated probably lost your functions.. I'm not sure about that too :D .
Remember you have to re-start the terminal when edit the .bashrc or your 'custom' file.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
[Ubuntu 16.04]
The .bash_history file is created in the user's home directory once the terminal is closed
It is useful, but you could delete it if you wish.. Nevertheless it would be created every time you finish using the terminal.
You could delete it manually from:
your files browser.
the terminal: remember that a new .bash_history file will be created when you close the terminal (based in its default configuration).
Or you can call a custom function if you save the functionality you need into a file linked from the bashrc.. you could edit the bashrc itself if you like putting your code there, but the next examples are in a separate file
Honestly this is not useful for me but if you wish is to delete the commands history before exit you could do this:
.bash_custom #this is my custom file
blotout()
HISTSIZE=0
rm $HOME/.bash_history
exit
then at the bottom of add the name and path of my file
.bashrc # this is the configuration file for the bash (I think)
# existent code
#...
#..
# import user customizations
source $HOME/.bash_custom
and thatà  all.
BUT, to do exactly what you want you just need this function in your custom file and link it:
refresh()
tput reset
H=HISTSIZE
HISTSIZE=0
HISTSIZE=H
Or just put the function in the .bashrc if you want but that way you probably need an export statement after the function I'm not sure and if the file is updated probably lost your functions.. I'm not sure about that too :D .
Remember you have to re-start the terminal when edit the .bashrc or your 'custom' file.
[Ubuntu 16.04]
The .bash_history file is created in the user's home directory once the terminal is closed
It is useful, but you could delete it if you wish.. Nevertheless it would be created every time you finish using the terminal.
You could delete it manually from:
your files browser.
the terminal: remember that a new .bash_history file will be created when you close the terminal (based in its default configuration).
Or you can call a custom function if you save the functionality you need into a file linked from the bashrc.. you could edit the bashrc itself if you like putting your code there, but the next examples are in a separate file
Honestly this is not useful for me but if you wish is to delete the commands history before exit you could do this:
.bash_custom #this is my custom file
blotout()
HISTSIZE=0
rm $HOME/.bash_history
exit
then at the bottom of add the name and path of my file
.bashrc # this is the configuration file for the bash (I think)
# existent code
#...
#..
# import user customizations
source $HOME/.bash_custom
and thatà  all.
BUT, to do exactly what you want you just need this function in your custom file and link it:
refresh()
tput reset
H=HISTSIZE
HISTSIZE=0
HISTSIZE=H
Or just put the function in the .bashrc if you want but that way you probably need an export statement after the function I'm not sure and if the file is updated probably lost your functions.. I'm not sure about that too :D .
Remember you have to re-start the terminal when edit the .bashrc or your 'custom' file.
answered Jun 28 '17 at 22:56
Federico Gallo
639
639
add a comment |Â
add a comment |Â
up vote
0
down vote
Added to ~/.inputrc
to bind the complete clearing to F12:
"e[24~":'!echo -ne 47\0033\014347r'
add a comment |Â
up vote
0
down vote
Added to ~/.inputrc
to bind the complete clearing to F12:
"e[24~":'!echo -ne 47\0033\014347r'
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Added to ~/.inputrc
to bind the complete clearing to F12:
"e[24~":'!echo -ne 47\0033\014347r'
Added to ~/.inputrc
to bind the complete clearing to F12:
"e[24~":'!echo -ne 47\0033\014347r'
answered Oct 18 '16 at 12:03
Velkan
231110
231110
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f26975%2fhow-do-i-clear-the-gnome-terminal-history%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
It's terminal dependent, and none of the answers address that.
â Thomas Dickey
Oct 19 '16 at 1:11