I have a question regarding the terminal konsole, I have searched for how to clear the history and it appears that I must delete the contents of the bash_history file and then use the command
history -c
and
history -w
, however I have already deleted the contents of the bash_history, I have entered history -c and history -w, but they only print the history, I hope for your help, thank you.
HI @SCK, welcome to the community. Please post the output of garuda-inxi for all Issues & Assistance topics.
history is managed differently in Fish than it is in Bash. If you are interested in learning more about it, run man history in the terminal.
man history
HISTORY(1) fish-shell HISTORY(1)
NAME
history - show and manipulate command history
SYNOPSIS
history [search] [--show-time] [--case-sensitive]
[--exact | --prefix | --contains] [--max N] [--null] [--reverse]
[SEARCH_STRING ...]
history delete [--case-sensitive]
[--exact | --prefix | --contains] SEARCH_STRING ...
history merge
history save
history clear
history clear-session
DESCRIPTION
history is used to search, delete, and otherwise manipulate the history of interactive commands.
The following operations (sub-commands) are available:
search Returns history items matching the search string. If no search string is provided it returns all history items. This is the
default operation if no other operation is specified. You only have to explicitly say history search if you wish to search
for one of the subcommands. The --contains search option will be used if you don't specify a different search option. Enâ
tries are ordered newest to oldest unless you use the --reverse flag. If stdout is attached to a tty the output will be
piped through your pager by the history function. The history builtin simply writes the results to stdout.
delete Deletes history items. The --contains search option will be used if you don't specify a different search option. If you
don't specify --exact a prompt will be displayed before any items are deleted asking you which entries are to be deleted.
You can enter the word "all" to delete all matching entries. You can enter a single ID (the number in square brackets) to
delete just that single entry. You can enter more than one ID separated by a space to delete multiple entries. Just press
[enter] to not delete anything. Note that the interactive delete behavior is a feature of the history function. The history
builtin only supports --exact --case-sensitive deletion.
merge Immediately incorporates history changes from other sessions. Ordinarily fish ignores history changes from sessions started
after the current one. This command applies those changes immediately.
save Immediately writes all changes to the history file. The shell automatically saves the history file; this option is provided
for internal use and should not normally need to be used by the user.
clear Clears the history file. A prompt is displayed before the history is erased asking you to confirm you really want to clear
all history unless builtin history is used.
clear-session
Clears the history file from all activity of the current session. Note: If history merge or builtin history merge is run in
a session, only the history after this will be erased.
The following options are available:
These flags can appear before or immediately after one of the sub-commands listed above.
-C or --case-sensitive
Does a case-sensitive search. The default is case-insensitive. Note that prior to fish 2.4.0 the default was case-sensiâ
tive.
-c or --contains
Searches items in the history that contain the specified text string. This is the default for the --search flag. This is
not currently supported by the delete subcommand.
-e or --exact
Searches or deletes items in the history that exactly match the specified text string. This is the default for the delete
subcommand. Note that the match is case-insensitive by default. If you really want an exact match, including letter case,
you must use the -C or --case-sensitive flag.
-p or --prefix
Searches items in the history that begin with the specified text string. This is not currently supported by the delete subâ
command.
-t or --show-time
Prepends each history entry with the date and time the entry was recorded. By default it uses the strftime format # %c%n.
You can specify another format; e.g., --show-time="%Y-%m-%d %H:%M:%S " or --show-time="%a%I%p". The short option, -t,
doesn't accept a strftime format string; it only uses the default format. Any strftime format is allowed, including %s to
get the raw UNIX seconds since the epoch.
-z or --null
Causes history entries written by the search operations to be terminated by a NUL character rather than a newline. This alâ
lows the output to be processed by read -z to correctly handle multiline history entries.
-*NUMBER* -n NUMBER or --max NUMBER
Limits the matched history items to the first NUMBER matching entries. This is only valid for history search.
-R or --reverse
Causes the history search results to be ordered oldest to newest. Which is the order used by most shells. The default is
newest to oldest.
-h or --help
Displays help for this command.
EXAMPLE
history clear
# Deletes all history items
history search --contains "foo"
# Outputs a list of all previous commands containing the string "foo".
history delete --prefix "foo"
# Interactively deletes commands which start with "foo" from the history.
# You can select more than one entry by entering their IDs separated by a space.
CUSTOMIZING THE NAME OF THE HISTORY FILE
By default interactive commands are logged to $XDG_DATA_HOME/fish/fish_history (typically Ë/.local/share/fish/fish_history).
You can set the fish_history variable to another name for the current shell session. The default value (when the variable is unâ
set) is fish which corresponds to $XDG_DATA_HOME/fish/fish_history. If you set it to e.g. fun, the history would be written to
$XDG_DATA_HOME/fish/fun_history. An empty string means history will not be stored at all. This is similar to the private session
features in web browsers.
You can change fish_history at any time (by using set -x fish_history "session_name") and it will take effect right away. If you
set it to "default", it will use the default session name (which is "fish").
Other shells such as bash and zsh use a variable named HISTFILE for a similar purpose. Fish uses a different name to avoid conâ
flicts and signal that the behavior is different (session name instead of a file path). Also, if you set the var to anything other
than fish or default it will inhibit importing the bash history. That's because the most common use case for this feature is to
avoid leaking private or sensitive history when giving a presentation.
NOTES
If you specify both --prefix and --contains the last flag seen is used.
Note that for backwards compatibility each subcommand can also be specified as a long option. For example, rather than history
search you can type history --search. Those long options are deprecated and will be removed in a future release.
COPYRIGHT
2023, fish-shell developers
3.6 Mar 25, 2023 HISTORY(1)
I just tried the command and it continues printing the history without deleting it, do I need to use sudo or something like that?
ââsck@SCKlaptop in ~ took 1s
â°âλ history clear
2023-09-19 23:10:12 reset
2023-09-19 23:09:39 clear
2023-09-19 23:02:10 history clear | history clear
2023-09-19 23:01:31 history clear
2023-09-19 23:00:06 history 1mclear
2023-09-19 22:57:57 sudo history clear
Just as you say @BluishHumility, it is history clear, but I canât understand why the history is kept intact, am I doing something wrong?
1m-e 22mor 1m--exact0m
Searches or deletes items in the history that exactly match the specified text string. This is the default for the 1mdelete 22msubcommand. Note that the match is case-insensitive by default. If you really
want an exact match, including letter case, you must use the 1m-C 22mor 1m--case-sensitive 22mflag.
1m-p 22mor 1m--prefix0m
Searches items in the history that begin with the specified text string. This is not currently supported by the 1mdelete 22msubcommand.
1m-t 22mor 1m--show-time0m
Prepends each history entry with the date and time the entry was recorded. By default it uses the strftime format 1m# %c%n22m. You can specify another format; e.g., 1m--show-time="%Y-%m-%d %H:%M:%S " 22mor
1m--show-time="%a%I%p"22m. The short option, 1m-t22m, doesn't accept a strftime format string; it only uses the default format. Any strftime format is allowed, including 1m%s 22mto get the raw UNIX seconds since the
epoch.
1m-z 22mor 1m--null0m
Causes history entries written by the search operations to be terminated by a NUL character rather than a newline. This allows the output to be processed by 1mread -z 22mto correctly handle multiline hisâ
tory entries.
1m-22m*NUMBER* 1m-n 4m22mNUMBER24m or 1m--max 4m22mNUMBER0m
Limits the matched history items to the first 4mNUMBER24m matching entries. This is only valid for 1mhistory search22m.
1m-R 22mor 1m--reverse0m
Causes the history search results to be ordered oldest to newest. Which is the order used by most shells. The default is newest to oldest.
1m-h 22mor 1m--help0m
Displays help for this command.
1mEXAMPLE0m
history clear
# Deletes all history items
history search --contains "foo"
# Outputs a list of all previous commands containing the string "foo".
history delete --prefix "foo"
# Interactively deletes commands which start with "foo" from the history.
# You can select more than one entry by entering their IDs separated by a space.
1mCUSTOMIZING THE NAME OF THE HISTORY FILE0m
By default interactive commands are logged to 1m$XDG_DATA_HOME/fish/fish_history 22m(typically 1m~/.local/share/fish/fish_history22m).
You can set the 1mfish_history 22mvariable to another name for the current shell session. The default value (when the variable is unset) is 1mfish 22mwhich corresponds to 1m$XDG_DATA_HOME/fish/fish_history22m. If you set
it to e.g. 1mfun22m, the history would be written to 1m$XDG_DATA_HOME/fish/fun_history22m. An empty string means history will not be stored at all. This is similar to the private session features in web browsers.
You can change 1mfish_history 22mat any time (by using 1mset -x fish_history "session_name"22m) and it will take effect right away. If you set it to 1m"default"22m, it will use the default session name (which is 1m"fish"22m).
1m-e 22mor 1m--exact0m
Searches or deletes items in the history that exactly match the specified text string. This is the default for the 1mdelete 22msubcommand. Note that the match is case-insensitive by default. If you really
want an exact match, including letter case, you must use the 1m-C 22mor 1m--case-sensitive 22mflag.
1m-p 22mor 1m--prefix0m
Searches items in the history that begin with the specified text string. This is not currently supported by the 1mdelete 22msubcommand.
1m-t 22mor 1m--show-time0m
Prepends each history entry with the date and time the entry was recorded. By default it uses the strftime format 1m# %c%n22m. You can specify another format; e.g., 1m--show-time="%Y-%m-%d %H:%M:%S " 22mor
1m--show-time="%a%I%p"22m. The short option, 1m-t22m, doesn't accept a strftime format string; it only uses the default format. Any strftime format is allowed, including 1m%s 22mto get the raw UNIX seconds since the
epoch.
1m-z 22mor 1m--null0m
Causes history entries written by the search operations to be terminated by a NUL character rather than a newline. This allows the output to be processed by 1mread -z 22mto correctly handle multiline hisâ
tory entries.
1m-22m*NUMBER* 1m-n 4m22mNUMBER24m or 1m--max 4m22mNUMBER0m
Limits the matched history items to the first 4mNUMBER24m matching entries. This is only valid for 1mhistory search22m.
1m-R 22mor 1m--reverse0m
Causes the history search results to be ordered oldest to newest. Which is the order used by most shells. The default is newest to oldest.
1m-h 22mor 1m--help0m
Displays help for this command.
1mEXAMPLE0m
history clear
# Deletes all history items
history search --contains "foo"
# Outputs a list of all previous commands containing the string "foo".
history delete --prefix "foo"
# Interactively deletes commands which start with "foo" from the history.
# You can select more than one entry by entering their IDs separated by a space.
1mCUSTOMIZING THE NAME OF THE HISTORY FILE0m
By default interactive commands are logged to 1m$XDG_DATA_HOME/fish/fish_history 22m(typically 1m~/.local/share/fish/fish_history22m).
You can set the 1mfish_history 22mvariable to another name for the current shell session. The default value (when the variable is unset) is 1mfish 22mwhich corresponds to 1m$XDG_DATA_HOME/fish/fish_history22m. If you set
it to e.g. 1mfun22m, the history would be written to 1m$XDG_DATA_HOME/fish/fun_history22m. An empty string means history will not be stored at all. This is similar to the private session features in web browsers.
You can change 1mfish_history 22mat any time (by using 1mset -x fish_history "session_name"22m) and it will take effect right away. If you set it to 1m"default"22m, it will use the default session name (which is 1m"fish"22m).
Other shells such as bash and zsh use a variable named 1mHISTFILE 22mfor a similar purpose. Fish uses a different name to avoid conflicts and signal that the behavior is different (session name instead of a file path). Also, if you set the var to anything other than 1mfish 22mor 1mdefault 22mit will inhibit importing the bash history. That's because the most common use case for this feature is to avoid leaking private or senâ
sitive history when giving a presentation.
1mNOTES0m
If you specify both 1m--prefix 22mand 1m--contains 22mthe last flag seen is used.
Note that for backwards compatibility each subcommand can also be specified as a long option. For example, rather than 1mhistory search 22myou can type 1mhistory --search22m. Those long options are deprecated and will
be removed in a future release.
as mentioned in man page of this command. And yes please follow the template, garuda-inxi please. We canât have exceptions for anyone opening a help request.
I can actually replicate the issue SCK is facing. I too canât clear my fish shellâs history with
history clear
In fact none of the options or flags I give history seem to be registered by it for some reason, e.g.,
history --help
according to man should output help but it returns the history of my shell instead.
Yep, just confirmed with bash. There is something wrong with fishâs history itâs not parsing any flags or verbs passed to it.
eg,
In bash
history --help
history --help
history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
Display or manipulate the history list.
Display the history list with line numbers, prefixing each modified
entry with a `*'. An argument of N lists only the last N entries.
Options:
-c clear the history list by deleting all of the entries
-d offset delete the history entry at position OFFSET. Negative
offsets count back from the end of the history list
-a append history lines from this session to the history file
-n read all history lines not already read from the history file
and append them to the history list
-r read the history file and append the contents to the history
list
-w write the current history to the history file
-p perform history expansion on each ARG and display the result
without storing it in the history list
-s append the ARGs to the history list as a single entry
If FILENAME is given, it is used as the history file. Otherwise,
if HISTFILE has a value, that is used, else ~/.bash_history.
If the HISTTIMEFORMAT variable is set and not null, its value is used
as a format string for strftime(3) to print the time stamp associated
with each displayed history entry. No time stamps are printed otherwise.
Exit Status:
Returns success unless an invalid option is given or an error occurs.
but the same in fish
2023-09-20 19:44:58 bash
2023-09-20 19:44:44 ls /usr/lib/virtualbox/
2023-09-20 19:44:28 ls /sbin/vboxconfig
2023-09-20 19:43:52 history | less
2023-09-20 19:43:46 history --clear
2023-09-20 19:42:08 history clear-session
2023-09-20 19:41:00 history search rm
2023-09-20 19:40:39 man history
2023-09-20 19:40:34 history -C rm
2023-09-20 19:36:05 history clear
2023-09-20 19:34:51 history --help | less
2023-09-20 19:34:26 history --help
2023-09-20 19:32:33 ls ~/.local/share/fish/fish_history
2023-09-20 19:32:20 ls .local/share/fish/fish_history
2023-09-20 19:30:47 ls
2023-09-20 19:30:46 rm \n
2023-09-20 19:30:00 rm '\n'
2023-09-20 19:29:28 ls $XDG_DATA_HOME/fish/fish_history
2023-09-20 19:29:12 echo $XDG_DATA_HOME
2023-09-20 19:27:03 cat .local/share/fish/fish_history
2023-09-20 19:26:58 ls .local/share/fish/
2023-09-20 10:59:56 history -- --help
Itâs the same for any flag or verb, fishâs history is simply not reading it.
⯠history clear
If you enter 'yes' your entire interactive command history will be erased
Are you sure you want to clear history? (yes/no) yes
Command history cleared!
~ took 4s
⯠history
~
âŻ
I didnât particularly want my history cleared, but here we are.
I guess I should look for a better username to use online. btw, I got this one with a âcool discord user namesâ on google. I saw this at the top of the list and decided to use it everywhere. So I am quite open to suggestions.
Itâs kind of a neat function because it provides the timestamps, and the formatting is a bit less clunky than just using the --show-time flag on its own.
⯠history --show-time
# Wed 20 Sep 2023 01:01:30 PM EDT
history -h
# Wed 20 Sep 2023 01:00:23 PM EDT
bash
# Wed 20 Sep 2023 01:00:09 PM EDT
history
# Wed 20 Sep 2023 12:48:21 PM EDT
micro /etc/pacman.conf
~
⯠history --show-time='%F %T '
2023-09-20 13:02:16 history --show-time
2023-09-20 13:01:30 history -h
2023-09-20 13:00:23 bash
2023-09-20 13:00:09 history
2023-09-20 12:48:21 micro /etc/pacman.conf
But it seems like the search options might not be compatible with the other options.
history - show and manipulate command history
history [search] [--show-time] [--case-sensitive]
[--exact | --prefix | --contains] [--max N] [--null] [--reverse]
[SEARCH_STRING ...]
history delete [--case-sensitive]
[--exact | --prefix | --contains] SEARCH_STRING ...
history merge
history save
history clear
history clear-session
So we would have to write in some logic to allow the function to honor the other possible options.
Perhaps we could just alias history --show-time='%F %T ' to history -t so folks who use that flag get the cleaner formatting, and if anyone wants to take it further than that they can tweak it on their own.
-t or --show-time
Prepends each history entry with the date and time the entry was recorded. By default it
uses the strftime format # %c%n. You can specify another format; e.g.,
--show-time="%Y-%m-%d %H:%M:%S " or --show-time="%a%I%p". The short option, -t, doesn't
accept a strftime format string; it only uses the default format. Any strftime format is
allowed, including %s to get the raw UNIX seconds since the epoch.