I use Sailfish 4.6 Sauna on my Sony XA2 dual sim. In terminal i used command ‘history’, i need clear history. ‘history -c’ ‘history -clear’ dont work.
Help me please clear my history in terminal with command.
Thank! Sorry my bad English
Hey, try:
history -c && history -w
or
cat /dev/null > ~/.bash_history
By default, SailfishOS uses busybox shell which is ‘ash’ not bash.
To remove history:
rm ~/.ash_history
The easiest solution might be to use another shell, where you have more control over its behavior. The BusyBox shall have CONFIG_FEATURE_EDITING_HISTORY but this is a compile time setting. So you would need to modify and recompile the package.
I believe bash is available through default repos.
Its worked,but this remove ash_history and creat new clear file. In my linux mint i clear history with command ‘history -c’ and terminal on linux mint save 5command in session, and save 3command with reboot terminal. In my sailfish terminal save all history,this clear only remove ash_history,but i need clear history with command, i want to configurr the history to store only 5 commands and clear it with the command
Busybox does not support all of the commands that bash does, only some of them. You could remove the busybox symlink for bash with pkcon remove busybox-symlinks-bash
, and the full bash will be installed instead.
You shouldn’t have to change anything else as the default shell is already set to /bin/bash
.
Thank you! If I run pkcon remove busybox-symlinks-bash what will it do to the sailfish system and how it works?
It will replace the default shell with the standard bash shell. Normally, everything should work.
Thank you, after running this command I was able to clear my history with the command 'history -c"
Do you know how I can now set up history so that when I exit the terminal, the last five commands remain (let’s say I used 20 commands, exited the terminal, came back, and there were 5 left in the history)?
See the bash manual:
HISTORY
When the -o history option to the set builtin is enabled, the shell provides access to the command history , the list of commands previously typed. The value of the HISTSIZE variable is used as the number of commands to save in a history list. The text of the last HISTSIZE commands (default 500) is saved. The shell stores each command in the history list prior to parameter and variable expansion (see EXPANSION above) but after history expansion is performed, subject to the values of the shell variables HISTIGNORE and HISTCONTROL .
On startup, the history is initialized from the file named by the variable HISTFILE (default ~/.bash_history ). The file named by the value of HISTFILE is truncated, if necessary, to contain no more than the number of lines specified by the value of HISTFILESIZE . If HISTFILESIZE is unset, or set to null, a non-numeric value, or a numeric value less than zero, the history file is not truncated. When the history file is read, lines beginning with the history comment character followed immediately by a digit are interpreted as timestamps for the preceding history line. These timestamps are optionally displayed depending on the value of the HISTTIMEFORMAT variable. When a shell with history enabled exits, the last $HISTSIZE lines are copied from the history list to $HISTFILE . If the histappend shell option is enabled (see the description of shopt under SHELL BUILTIN COMMANDS below), the lines are appended to the history file, otherwise the history file is overwritten. If HISTFILE is unset, or if the history file is unwritable, the history is not saved. If the HISTTIMEFORMAT variable is set, time stamps are written to the history file, marked with the history comment character, so they may be preserved across shell sessions. This uses the history comment character to distinguish timestamps from other history lines. After saving the history, the history file is truncated to contain no more than HISTFILESIZE lines. If HISTFILESIZE is unset, or set to null, a non-numeric value, or a numeric value less than zero, the history file is not truncated.
The builtin command fc (see SHELL BUILTIN COMMANDS below) may be used to list or edit and re-execute a portion of the history list. The history builtin may be used to display or modify the history list and manipulate the history file. When using command-line editing, search commands are available in each editing mode that provide access to the history list.
The shell allows control over which commands are saved on the history list. The HISTCONTROL and HISTIGNORE variables may be set to cause the shell to save only a subset of the commands entered. The cmdhist shell option, if enabled, causes the shell to attempt to save each line of a multi-line command in the same history entry, adding semicolons where necessary to preserve syntactic correctness. The lithist shell option causes the shell to save the command with embedded newlines instead of semicolons. See the description of the shopt builtin below under SHELL BUILTIN COMMANDS for information on setting and unsetting shell options.
Figured it out. Set it up. The history is cleared and stores as many values as needed. But after rebooting the device (not the terminal, but the phone itself), it displays the entire history again (including the one I deleted before and it didn’t display), I wrote the history -c command and it cleared the history in the session. Now I rebooted the terminal - the entire history is present again, it only clears the session (before that I didn’t clear it with the command at all). I think either busybox-symlinks-bash appeared again after rebooting, or it takes the history from the cache file.
Make sure you have only one terminal window open (fingerterm or ssh), then delete all history files in your home:
history -c; history -w; rm ~/.*sh_history
And just to be sure immediately close that last terminal, too.
Thats worked! Thanks!
An other simple line is ‘history | tail -5’ . It shows the latest five commands …