Tag Info

Hot answers tagged

50

Typing "history -d xxx" will delete a specified line. You then have to type "history -w" to make them permanent. It also removes them from the .bash_history file. The surest fire way is cYrus's answer.


37

Just edit the file ~/.bash_history.


28

I have found the solution to my problem in the ZSH documentation. Oh-my-zsh seems to map the ↑ and ↓ Keys to something like bindkey '\e[A' history-search-backward bindkey '\e[B' history-search-forward Which yields the exact behavior I described above. The ZSH Documentation describes the behavior of history-search-backward as Search backward in the ...


17

To prevent a command from being added to the history in the first place, make sure that the environment variable HISTCONTROL contains among its colon-separated values the value ignorespace, for example (add e.g. to .bashrc): $ export HISTCONTROL=ignorespace This will prevent any command with a leading space from being added to the history. You can then ...


17

You've probably got INC_APPEND_HISTORY set. The INC_APPEND_HISTORY option, from man zshoptions: This options works like APPEND_HISTORY except that new history lines are added to the $HISTFILE incrementally (as soon as they are entered), rather than waiting until the shell exits. The option that you want is APPEND_HISTORY: APPEND_HISTORY If ...


13

history -s command


10

Hit F7 to bring up a list of the last few commands, then you can hit the first letter to jump to the first matching entry. Hit the same letter repeatedly to move up commands with the same first letter (working from newest from oldest).


10

You can search the history using Ctrl+R and then type the search string (e.g. iw to find iwconfig). Then you can then still navigate through the history at that point with the up and down arrow keys, or press Ctrl+R again to find the previous occurence.


8

First of all, if the command you're about to issue is sensitive, unsafe, or you just don't need it cluttering up your history, it is best/quickest to just prevent it from entering the history in the first place. Make sure that $HISTCONTROL contains ignorespace: (bash)$ echo $HISTCONTROL ignoredups:ignorespace Then proceed any command you don't want in ...


7

You need to mark the nonprinting sections of the prompt with \[ ... \] so bash can tell they won't take up space on screen. Try: export PS1="\w \[\e[0;32m\]\$(vcprompt -f '[%n:%b]')\[\e[m\]\$ "


7

Bash History Any new commands that have been issued in the active terminal can be appended to the .bash_history file with the following command: history -a The only tricky concept to understand is that each terminal has its own bash history list (loaded from the .bash_history file when you open the terminal) If you want to pull any new history that's ...


6

If you supply a negative argument to Alt-., it reverses direction. The easiest way to do that (with standard keybindings) is Alt-- (equivalent to an argument of -1). So, after one or more Alt-. keypresses, pressing Alt-- will cause the next Alt-. to go in the reverse direction. (Just ignore the argument dialog which appears when you press Alt--.)


6

Prevent sensible information from being stored in history file If you've hitted some password on command line, than realize that all commands are logged, you could either: Force exit current session without saving history: kill -9 $$ This will drop all current history. Hit on oppened bash session Up until sensible informations are shown, than Ctrl+w ...


6

Your history is logged by your shell. Bash, for example, uses the file ~/.bash_history by default. It is also not limited by your current session, but the history is usually persisted beyond that, up to what the environment variables HISTSIZE and HISTFILESIZE allow. More information on how the history works in bash is available in it's man page, in the ...


6

Assuming your shell is bash, this question has been asked and answered on SO. Press Ctrl-U to delete the command line from the location of the cursor up to the beginning. Precede this by Ctrl-E if the cursor isn't at the end of the line. Or press Ctrl-C to cancel the current prompt and obtain a new one, which has the benefit that you still see the command ...


5

There are two reasons why your script will not work as intended: The bash environment for a running script is "non-interactive" and does not have the history features enabled. The bash environment for a running script is independent from the environment you are interactively working in. Depending on your use case the easiest solution might be to source ...


4

After a bit of practice, I found how to use the workaround solution. I matched the correct syntax to print a filtered list, I did it with history | grep iwconfig (it wasn't so difficult after all); with the output I can use !n with the now easy-to-read filtered list.


4

You can setup a special zle widget to show only local history items: function only-local-history () { zle set-local-history 1 zle up-history zle set-local-history 0 } zle -N only-local-history Assuming, that ↑ is bound to up-line-or-history (I think that is default), you can bind this widget to another key stroke, like ...


4

Copy & Paste this to your .zshrc: Cursors are using local history: bindkey "${key[Up]}" up-line-or-local-history bindkey "${key[Down]}" down-line-or-local-history up-line-or-local-history() { zle set-local-history 1 zle up-line-or-history zle set-local-history 0 } zle -N up-line-or-local-history down-line-or-local-history() { zle ...


4

If you need to remove several lines at the same time I normally use this: history | grep <string> | cut -d ' ' -f 3 | awk '{print "history -d " $1}' If you need to remove the last command you can use: history -d $((HISTCMD-2))


4

history -s command You can even bind a keystroke to do this for you. You can enter this at a Bash prompt: bind '"\C-q": "\C-a history -s \C-j"' or add this to your ~/.inputrc: "\C-q": "\C-a history -s \C-j" then you can type something and press Ctrl-q and it will be added to the history without being executed. The space before "history" causes the ...


3

Use the script command DESCRIPTION Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1).


3

history | sed -i 59d 59 is the line number. Cannot be anything sweeter than this :)


3

Here's one way to set up history-search-backward and history-search-forward: Step1: Put the following in your /etc/inputrc file: $if mode=emacs "\ep": history-search-backward "\en": history-search-forward $endif (Or simply put the following between in the existing if statement) "\ep": history-search-backward "\en": history-search-forward Step2: ...


3

Cleaner version of the Scott's answer: Put this to .bash_profile: if [ ! -z "$EXECUTE_COMMAND" ]; then history -s "$EXECUTE_COMMAND" $EXECUTE_COMMAND fi Start bash this way: $ EXECUTE_COMMAND='ping 127.0.0.1' bash -l PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. 64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.177 ms ... ^C 5 packets ...


3

I can't comment on Stefan's answer, but you normally have to keep pressing Ctrl+R. See this page for more information.


3

tl;dr; for a in /home/* ; do cp $a/.bash_history /tmp/$a.bash_history ; done Longer version: for a in pattern loops over all items in a pattern. The pattern itself is stores in the variable called a. Examples: for a in * ; do echo $a ; done echo's all filenames. for a in /home/* ; do echo $a ; done echo's the names of all homedirs in /home. ...


3

You might be looking for ttyrec which records the input and output of the entire console session, and allows you to play it back.


3

Look into sudosh. A link to the SourceForge page is: HERE (There may even be a package, depending on your repos/disto) You can "sudosh" into a shell and everything is recorded for that session. All sudosh sessions are recorded and saved with a date and time stamp appended to it automatically. (You can even grep/search the contents of the sudosh ...


3

When you log in to the remote machine, the sshd there allocates a pseudo-terminal and starts your login shell. Any processes you start, background or foreground, are child processes of that shell. (Read up on "fork", "parent process", and "child process"; use the "pstree" command to look at the state of the system.) If you disconnect, for example by closing ...



Only top voted, non community-wiki answers of a minimum length are eligible