I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.
Let me teach you how to work efficiently with command line history in bash.
This tutorial comes with a downloadable cheat sheet that summarizes (and expands on) topics covered here (scroll to the end for a download link).
In case you are a first time reader, this is the 3rd part of the article series on working efficiently in bourne again shell. Previously I have written on how to work efficiently in vi and emacs command editing modes by using predefined keyboard shortcuts (both articles come with cheat sheets of predefined shortcuts).
First, lets review some basic keyboard shortcuts for navigating around previously typed commands.
As you remember, bash offers two modes for command editing - emacs mode and vi mode. In each of these editing modes the shortcuts for retrieving history are different.
Suppose you had executed the following commands:
$ echo foo bar baz
$ iptables -L -n -v -t nat
$ ... lots and lots more commands
$ echo foo foo foo
$ perl -wle 'print q/hello world/'
$ awk -F: '{print$1}' /etc/passwd
$
and you wanted to execute the last command (awk -F …).
You could certainly hit the up arrow and live happily along, but do you really want to move your hand that far away?
If you are in emacs mode just try CTRL-p which fetches the previous command from history list (CTRL-n for the next command).
In vi mode try CTRL-[ (or ESC) (to switch to command mode) and ‘h‘ (’j‘ for the next command).
There is another, equally quick, way to do that by using bash’s history expansion mechanism - event designators. Typing ‘!!‘ will execute the previous command (more about event designators later).
Now, suppose that you wanted to execute ‘iptables -L -n -v -t nat‘ command again without retyping it.
A naive user would, again, just keep hitting up-arrow key until he/she finds the command. But that’s not the way hackers work. Hackers love to work quickly and efficiently. Forget about arrow keys and page-up, page-down, home and end keys. They are completely useless and, as I said, they are too far off from the main part of the keyboard anyway.
In emacs mode try CTRL-r and type a few first letters of ‘iptables‘, like ‘ipt‘. That will display the last iptables command you executed. In case you had more than one iptables commands executed in between, hitting CTRL-r again will display older entries. In case you miss the right command and move too deep into history list, you can reverse the search direction by hitting CTRL-s (don’t forget that by default CTRL-s stops the output to the terminal and you’ll get an effect of “frozen” terminal (hit CTRL-q to “unfreeze”), see stty command to change this behavior).
In vi mode the same CTRL-r and CTRL-s still work but there is another way more specific to vi mode.
Switch to command mode by hitting CTRL-[ or ESC and hit ‘/‘, then type a first few characters of ‘iptables’ command, like ‘ipt’ and hit return. Bash will display the most recent match found in history. To navigate around use ‘n‘ or just plain ‘/‘ to repeat the search in the same direction, and ‘N‘ or ‘?‘ to repeat the search in opposite direction!
With event designators you may execute only the most recently executed command matching (or starting with) ’string’.
Try ‘!iptables‘ history expansion command which refers to the most recent command starting with ‘iptables’.
Another way is to use bash’s built in ‘history‘ command then grep for a string of interest and finally use an event designator in form ‘!N‘, where N is an integer which refers to N-th command in command history list.
For example,
$ history | grep 'ipt' 2 iptables -L -n -v -t nat $ !2 # will execute the iptables command
I remembered another way to execute N-th command in history list in vi editing mode. Type ‘N‘ (command number) and then ‘G‘, in this example ‘2G‘
Listing and Erasing Command History
Bash provides a built-in command ‘history‘ for viewing and erasing command history.
Suppose that we are still working with the same example:
$ echo foo bar baz
$ iptables -L -n -v -t nat
$ ... lots and lots more commands
$ echo foo foo foo
$ perl -wle 'print q/hello world/'
$ awk -F: '{print$1}' /etc/passwd
$
Typing ‘history‘ will display all the commands in bash history alongside with line numbers:
1 echo foo bar baz
2 iptables -L -n -v -t nat
... lots and lots more commands
568 echo foo foo foo
569 perl -wle 'print q/hello world/'
570 awk -F: '{print$1}' /etc/passwd
Typing ‘history N‘, where N is an integer, will display the last N commands in the history.
For example, ‘history 3‘ will display:
568 echo foo foo foo
569 perl -wle 'print q/hello world/'
570 awk -F: '{print$1}' /etc/passwd
history -c will clear the history list and history -d N will delete a history entry N.
By default, the history list is kept in user’s home directory in a file ‘.bash_history‘.
History Expansion
History expansion is done via so-called event designators and word designators. Event designators can be used to recall previously executed commands (events) and word designators can be used to extract command line arguments from the events. Optionally, various modifiers can be applied to the extracted arguments.
Event designators are special commands that begin with a ‘!‘ (there is also one that begins with a ‘^‘), they may follow a word designator and one or more modifiers. Event designators, word designators and modifiers are separated by a colon ‘:‘.
Event Designators
Lets look at a couple of examples to see how the event designators work.
Event designator ‘!!‘ can be used to refer to the previous command, for example,
$ echo foo bar baz foo bar baz $ !! foo bar baz
Here the ‘!!‘ executed the previous ‘echo foo bar baz‘ command.
Event designator ‘!N‘ can be used to refer to the N-th command.
Suppose you listed the history and got the following output:
1 echo foo foo foo
2 iptables -L -n -v -t nat
... lots and lots more commands
568 echo bar bar bar
569 perl -wle 'print q/hello world/'
570 awk -F: '{print$1}' /etc/passwd
Then the event designator ‘!569‘ will execute ‘perl …‘ command, and ‘!1‘ will execute ‘echo foo foo foo‘ command!
Event designator ‘!-N‘ refers to current command line minus N. For example,
$ echo foo bar baz foo bar baz $ echo a b c d e a b c d e $ !-2 foo bar baz
Here the event designator ‘!-2‘ executed a one before the previous command, or current command line minus 2.
Event designator ‘!string‘ refers to the most recent command starting with ‘string‘. For example,
$ awk --help $ perl --help
Then the event designator ‘!p‘ or ‘!perl‘ or ‘!per‘ will execute the ‘perl –help‘ command. Similarly, ‘!a‘ will execute the awk command.
An event designator ‘!?string?‘ refers to a command line containing (not necessarily starting with) ‘string‘.
Perhaps the most interesting event designator is the one in form ‘^string1^string2^‘ which takes the last command, replaces string1 with string2 and executes it. For example,
$ ehco foo bar baz bash: ehco: command not found $ ^ehco^echo^ foo bar baz
Here the ‘^ehco^echo^‘ designator replaced the incorrectly typed ‘ehco‘ command with the correct ‘echo‘ command and executed it.
Word Designators and Modifiers
Word designators follow event designators separated by a colon. They are used to refer to some or all of the parameters on the command referenced by event designator.
For example,
$ echo a b c d e a b c d e $ echo !!:2 b
This is the simplest form of a word designator. ‘:2‘ refers to the 2nd argument of the command (3rd word). In general ‘:N‘ refers to Nth argument of the command ((N+1)-th word).
Word designators also accept ranges, for example,
$ echo a b c d e a b c d e $ echo !!:3-4 c d
There are various shortcuts, such as, ‘:$‘ to refer to the last argument, ‘:^‘ to refer to the first argument, ‘:*‘ to refer to all the arguments (synonym to ‘:1-$‘), and others. See the cheat sheet for a complete list.
Modifiers can be used to modify the behavior of a word designators. For example:
$ tar -xvzf software-1.0.tgz software-1.0/file ... $ cd !!:$:r software-1.0$
Here the ‘r‘ modifier was applied to a word designator which picked the last argument from the previous command line. The ‘r‘ modifier removed the trailing suffix ‘.tgz’.
The ‘h‘ modifier removes the trailing pathname component, leaving the head:
$ echo /usr/local/apache /usr/local/apache $ echo !!:$:h /usr/local
The ‘e‘ modifier removes all but the trailing suffix:
$ ls -la /usr/src/software-4.2.messy-Extension ... $ echo /usr/src/*!!:$:e /usr/src/*.messy-Extension # ls could have been used instead of echo
Another interesting modifier is the substitute ‘:s/old/new/‘ modifier which substitutes new for old. It can be used in conjunction with ‘g‘ modifier to do global substitution. For example,
$ ls /urs/local/software-4.2 /urs/local/software-4.3 /usr/bin/ls: /urs/local/software-4.2: No such file or directory /usr/bin/ls: /urs/local/software-4.3: No such file or directory $ !!:gs/urs/usr/ ...
This example replaces all occurances of ‘urs’ to ‘usr’ and makes the command correct.
There are a few other modifiers, such as ‘p‘ modifier which prints the resulting command after history expansion but does not execute it. See the cheat sheet for all of the modifiers.
Modifying History Behavior
Bash allows you to modify which commands get stored in the history list, the file where they get stored, the number of commands that get stored, and a few other options.
These options are controlled by setting HISTFILE, HISTFILESIZE, HISTIGNORE and HISTSIZE environment variables.
HISTFILE, as the name suggests, controls where the history file gets saved.
For example,
$ export HISTFILE=/home/pkrumins/todays_history
will save the commands to a file /home/pkrumins/todays_history
Set it to /dev/null or unset it to avoid getting your history list saved.
HISTFILESIZE controls how many history commands to keep in HISTFILE.
For example,
$ export HISTFILESIZE=1000
will keep the last 1000 history commands.
HISTSIZE controls how many history commands to keep in the history list of current session.
For example,
$ export HISTSIZE=42
will keep 42 last commands in the history of current session.
If this number is less than HISTFILESIZE, only that many commands will get written to HISTFILE.
HISTIGNORE controls the items which get ignored and do not get saved. This variable takes a list of colon separated patterns. Pattern ‘&’ (ampersand) is special in a sense that it matches the previous history command.
There is a trick to make history ignore the commands which begin with a space. The pattern for that is “[ ]*”
For example,
$ export HISTIGNORE="&:[ ]*:exit"
will make bash ignore duplicate commands, commands that begin with a space, and the ‘exit’ command.
There are several other options of interest controlled by the built-in ‘shopt‘ command.
The options may be set by specifying ‘-s‘ parameter to the ‘shopt‘ command, and may be unset by specifying ‘-u‘ parameter.
Option ‘histappend‘ controls how the history list gets written to HISTFILE, setting the option will append history list of current session to HISTFILE, unsetting it (default) will make HISTFILE get overwritten each time.
For example, to set this option, type:
$ shopt -s histappend
And to unset it, type:
$ shopt -u histappend
Option ‘histreedit‘ allows users to re-edit a failed history substitution.
For example, suppose you had typed:
$ echo foo bar baz
and wanted to substitute ‘baz’ for ‘test’ with the ^baz^test^ event designator , but you made a mistake and typed ^boo^test^. This would lead to a substitution failure because the previous command does not contain string ‘boo’.
If you had this option turned on, bash would put the erroneous ^baz^test^ event designator back on the command line as if you had typed it again.
Finally, option ‘histverify‘ allows users to verify a substituted history expansion.
Based on the previous example, suppose you wanted to execute that ‘echo’ command again by using the ‘!!’ event designator. If you had this option on, bash would not execute the ‘echo’ command immediately but would first put it on command line so that you could see if it had made the correct substitution.
Tuning the Command Prompt
Here is how my command prompt looks:
Wed Jan 30@07:07:03 pkrumins@catonmat:1002:2:~$
The first line displays the date and time the command prompt was displayed so I could keep track of commands back in time.
The second line displays username, hostname, global history number and current command number.
The global history number allows me to quickly use event designators.
My PS1, primary prompt display variable looks like this:
PS1='\d@\t\n\u@\h:\!:\#:\w$ '
Bash History Cheat Sheet
Here is a summary cheat sheet for working effectively with bash history.
This cheat sheet includes:
- History editing keyboard shortcuts (emacs and vi mode),
- History expansion summary - event designators, word designators and modifiers,
- Shell variables and `shopt’ options to modify history behavior,
- Examples
PDF format (.pdf):
Download link: bash history cheat sheet (.pdf)
Downloaded: 21640 times
ASCII .txt format:
Download link: bash history cheat sheet (.txt)
Downloaded: 5717 times
LaTeX format (.tex):
Download link: bash history cheat sheet (.tex)
Downloaded: 2950 times
This cheat sheet is released under GNU Free Document License.
Discuss it on catonmat forums!
Are there any tips you want to add?
Did you like this post? Subscribe here:
If you really enjoyed the post, I'd appreciate a gift from my geeky Amazon book wishlist. Books would make me more educated and I could write even better posts. Thanks! :)

(21 votes, average: 4.62 out of 5)
|
|
|


February 19th, 2008 at 4:09 am
Hi there, kak dela..
One more great article here, took me some time to implement but working just awesome as always.
Man, maybe it’s time for you to submit some PR or something to get some attention from the Google team or uncle Gates, the door maker? They’ll pay you a load of Frnaklin’s to manage their backend servers :D
Good luck..
February 19th, 2008 at 9:56 am
Very nice article — one question I was hoping to see answered, though: when I have multiple shells open, how can I have all of their histories end up in .bash_history? It seems that many times logging out in one terminal clobbers history entries previously written when logging out from other terminals.
February 19th, 2008 at 10:32 am
Josh, it’s pretty easy. I have it done. I’ll update the article later today, but here is how to do it:
February 19th, 2008 at 3:30 pm
Nice article, the ^R way is quite handy. Do you know a way to make history contain only unique entries? (like ipython)
February 19th, 2008 at 3:39 pm
MarkS, yes I know a way to make history contain only uniques.
Do the following:
That will make history not to save duplicate consecutive entries!
February 19th, 2008 at 5:51 pm
[…] The Definitive Guide to Bash Command Line History - good coders code, great reuse (tags: shell bash tutorial) […]
February 19th, 2008 at 6:18 pm
[…] Line History Hi all! I just wrote a another article with a cheat sheet. It’s called "The Definitive Guide to Bash Command Line History". This tutorial teaches you how to quickly retrieve and modify commands you executed […]
February 19th, 2008 at 8:56 pm
From the title I was hoping you would answer a question that has bothered me for a long time: how do multiple xterm/rxvt/aterm/whatever histories interact? No one works in a single xterm, so clearly it is relevant. And if you do different things in different xterms, the histories look different. Yet there is only one .bash_history file in a default setup. Can you explain how this works?
February 19th, 2008 at 9:27 pm
Cunningham, all the terminals interact with your shell program. The shell program manages the history. The terminals are just computer interfaces for text entry and display, they do not know about your shell history.
I think if you closed all your terminals and run them all, then pressing key-up would display the same command from history.
When you have executed a bunch of commands on each of the terminals and you close them, bash overwrites .bash_history again and again with history in each session.
You should see my previous comment I answered Josh on how to have a unified .bash_history accross all bash sessions (no matter what terminal).
February 20th, 2008 at 10:06 am
I have fixed your usage of quotes in the LaTeX file. The modified file is available here: http://people.lispr.in/~ghoseb/bash-history-cheat-sheet.tex
I also modified the file to generate A4 PDF instead of US Letter.
February 20th, 2008 at 10:08 am
Forgot to add: Superb Tips :)
February 26th, 2008 at 7:57 pm
Great Tips!
Is it somehow possible to replace more than one occurrence with the “^”-designator?
February 27th, 2008 at 7:06 pm
[…] Bash history […]
February 29th, 2008 at 1:18 am
[…] Change history (in bash) Filed under: Linux — 0ddn1x @ 2008-02-28 22:50:19 +0000 http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/ […]
February 29th, 2008 at 6:37 am
[…] Today I found a very good guide to increasing bash productivity using vi editing commands, and leveraging the command line history to save time and effort. Both of these articles have very good downloadable […]
February 29th, 2008 at 6:42 am
[…] Today I found a very good guide to increasing bash productivity using vi editing commands, and leveraging the command line history to save time and effort. Both of these articles have very good downloadable […]
February 29th, 2008 at 6:42 am
[…] Today I found a very good guide to increasing bash productivity using vi editing commands, and leveraging the command line history to save time and effort. Both of these articles have very good downloadable […]
March 19th, 2008 at 9:19 am
Great write-up, You uncovered quite a few tricks I never knew, but you missed a very useful one: “!$” will match the last argument of the previous command. This can be very useful for things like this:
April 13th, 2008 at 3:54 pm
[…] a tool for this in bash namely the history command with all its nice options. See for instance this tutorial . Posted by codeflicker Filed in […]
April 13th, 2008 at 11:30 pm
# "-l" says use stdout, not a special file alias h='fc -l; echo r NNN to repeat one, or ; echo r CMD to repeat the last command beginning with CMD' alias r='fc -s' # From "man history": # In the second form ("fc -s"), command is # re-executed [..] # A useful alias to use with this is `r=fc -s', # so that typing `r cc'' runs the last command # beginning with `cc' and typing `r'' re-executes # the last command.April 14th, 2008 at 10:04 am
Good infos! Maybe you could also inform about the possibility using HISTORYCONTROL. Regards.
May 1st, 2008 at 11:28 pm
[…] The Definitive Guide to Bash Command Line History - This is THE BEST post I’ve seen on command-line history. If anyone uses a shell for anything then read this! […]
May 7th, 2008 at 2:00 pm
unless ive miss read I cant see on this page where on previous linux flavours you could search for previous commands with slash(/) then use the arrow keys to scroll through these commands but with the newer flavours eg fedora this does not work. Im sure ive seen in the past a solution for this but ive forgotten it :-( anyone know how to get / search and arrow key scroll working in fedora?
May 9th, 2008 at 3:56 am
[…] If you’re interested in learning more about terminal history commands, I highly recommend The Definitive Guide to Bash Command Line History. […]
May 9th, 2008 at 7:37 pm
Ted - your post does not answer the question I was asking :-(. I know about ctrl+r but thats not the search facility I was looking for.
June 5th, 2008 at 4:59 pm
@Mike, I’m not positive, but that could be a feature of being in vi mode on the command line rather than the default readline/emacs style key bindings.
There’s actually a good post on this blog about vi mode.
http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-sheet/
In vi, I know you can do a search with “/” and I wouldn’t be surprised if you could then up arrow through commands.
Alternatively, most shells that I’ve used support using the arrow keys to maneuver through history (without using a slash).
June 5th, 2008 at 5:51 pm
Hi Ted,
Ive found that if you ’set -o vi’ in your profile you can then do ‘esc k’ to put you into search mode then do ‘/cp’ for example and then press enter and this will find your last cp command. You can then press ‘n’ to scroll to the next cp command and so on :-)
June 14th, 2008 at 3:52 am
Excellent article, a great amount of new things.
Hm, if you don’t mind the question, maybe you know… I often have multiple shells open via GNU Screen, and when I type “halt” to put my system down, the history of the open sessions won’t update with the data used in them. Is there any way to force a constant update of the history file (without needing to log out to update)?
June 14th, 2008 at 1:33 pm
I actually come from the “bang-something” side where it used to be the only way to refer to history back in the tcsh days, and keep surprising my colleagues with my “!:”-fu magic sequences :)
One correction I have is that most (all?) the mentions you made to “!!:x” (e.g. “!!:2″) can be actually typed as “!:x” (i.e. one “!” is enough). Only “!!” by itself to repeat the last line and execute it immediately requires two “!”.
June 14th, 2008 at 1:38 pm
Answer to Gabriel about replacing more than one occurrence: you can use the !:s (the “^” is actually mentioned in the manual as a simplified version of “!:s”):
$ echo a b b b c
a b b b c
$ !:gs/b/d/
echo a d d d c
a d d d c
It’s all in “man bash”, BTW.
June 14th, 2008 at 1:42 pm
Ah, and also all the mentions of “!:x” not using numbers (”$”, “^”, “*”) do not require the “:”, e.g.:
$ echo a b c d
a b c d
$ echo !$
echo d
d
But “echo !2″ will print the 2nd command in the history list, not the 2nd argument in the previous command.
All this squeezing out of unnecessary typing adds up when you type in a hurry and many times.
June 14th, 2008 at 4:50 pm
[…] Una de las opciones de bash es la de permitir el acceso a los últimos comandos ejecutados, en este post comentan el uso de esos comandos para manejar bash como un pro. El autor también tiene una entrada […]
June 14th, 2008 at 11:47 pm
First of all, C-p and C-n are much easier… the Up and Down cursor keys.
Once you know of Ctrl-R, your use of ! automatically declines drastically, and ^ehco^echo becomes non-existent. With the ! prefix, you have to be absolutely sure that the command is what you want to run, there is no chance to see its expanded form before it is executed—this may be a risk (like when you do !rm). Ctrl-R is much safer as it allows you to see/change the command while entering it. The same aplies to ^ehco^echo — just ^R e h c, then use the arrow keys to change to e c h.
Also, ! is hardly used. Except you count how many commands you are away from your designated command — ^R to the resuce (again, surprisingly?)
June 15th, 2008 at 12:35 pm
Response to cjk:
1. Usually a command you want to fix in this way (or just generally want to build up on top of a previous command) is pretty recent in the history so you’ll see what your “!” notation is going to catch.
2. If you are not sure what’s going to happen after your fix then you can always add “:p” to the end of the command to cause the changed command to be printed and added to the history without actually executing it, then if you are happy with it then do “!!” (or ^R Enter if you insist).
For example:
$ echo a b c d
a b c d
$ ^d^replaced^:p
echo a b c replaced
$
Notice that the second echo was printed by the shell but wasn’t actually executed. Then you can do:
$ !!
echo a b c replaced
a b c replaced
$
And now it was executed.
I’m not discarding the use of interactive editing altogether - I use it a lot. But there are instances when the “!” notation is more useful. e.g. when you want to use the same argument(s) from a previous command but with a completely different command - interactive editing will require you to erase the old command before you edit the new one, skipping backwards and forwards around the parts you want to keep. With “!” and the various ways to refer to previous command’s arguments it’s easier and saves lots of repetitive typing (I’m saying this from personal experience, not as a theoretical claim).
June 16th, 2008 at 6:05 am
There is a feature in Suse Linux that I have always found useful, you can type the first chars of a command and the the PGUP key, it will take you to the last ocurrence of the command that starts with those chars. If you keep pressing the PGUP key it will jump back in history through the ocurrences of the commands starting with the chars.
Currently Im using Ubuntu, and I really miss that feature.
Do you know how to recreate it?
June 16th, 2008 at 1:09 pm
Ix:
Does the string you type have to match the BEGINNING of the command line?
^R/^S will do incremental search but they will match any part of the line, not just the beginning. I couldn’t find an interactive way to match the beginning in a search.
Just go through “man bash” (look for a section named “Searching” under “READLINE”) to find all the details.
BTW - while looking for an answer for you I found that it’s possible to interactively yank arguments from previous line to the current one. It’s not the full power of “!” notation but for people who prefer a more visual feedback and are not already accustomed to the old way it might be a good compromise.
June 17th, 2008 at 4:12 am
I’m surprised no one mentioned this before. This also answers Ix’s question (or comes close to it). Put the following in your ~/.inputrc file and save it (not including the dashes):
———
“\eOA”: history-search-backward
“\eOB”: history-search-forward
“\eOC”: forward-char
“\eOD”: backward-char
“\e[A”: history-search-backward
“\e[B”: history-search-forward
“\e[C”: forward-char
“\e[D”: backward-char
———
Now, on the shell, start typing the beginning of a command, and press the Up key. You’ll see the history is navigated only within the commands that start with the string you type (I call this the matlab type of history navigation). Very useful if you’re used to the Up and Down keys.
July 5th, 2008 at 10:11 pm
[…] The Definite Guide to Bash Command Line HistoryTags: Linux, Mac OS X, merken […]
July 10th, 2008 at 11:14 am
Thank all who’ve posted here! Very useful information!
July 22nd, 2008 at 6:28 pm
[…] The Definitive Guide to Bash Command Line History (31,568 views) […]
August 7th, 2008 at 2:05 pm
This is cool. I wish I had time to read that and memory to retain that.
August 9th, 2008 at 9:23 am
[…] Display commands typed previously history For more info: http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/ […]
September 3rd, 2008 at 5:30 pm
Very good guide - I learnt lots here.
I have a question, which has bugged a few of us for a while and I’ve not seen an answer to this anywhere yet.
In ksh if you set -o vi and then recall a command and hit v to edit the command with vi, how do you exit without having to a)# out the lines and then quit or b)delete the line/s and then exit.
December 7th, 2008 at 12:10 am
[…] history. If you commonly find yourself scrolling through your bash history with your arrow keys, this guide is for you. In case you were wondering, Ubuntu uses emacs mode for command editing by default. The […]
January 12th, 2009 at 2:10 am
[…] The Definitive Guide to Bash Command Line History - good coders code, great reuse (tags: bash shell unix) […]
January 26th, 2009 at 4:47 pm
[…] Bash history<br/> […]
February 11th, 2009 at 10:25 am
[…] The Definitive Guide to Bash Command Line History - good coders code, great reuse - In case you are a first time reader, this is the 3rd part of the article series on working efficiently in bourne again shell. Previously I have written on how to work efficiently in vi and emacs command editing modes by using predefined keyboard shortcuts (both articles come with cheat sheets of predefined shortcuts). […]
February 26th, 2009 at 5:14 am
Some people may find this useful
February 26th, 2009 at 5:25 am
wow, just learnt something by reading the comments above, you can make this one even shorter by omitting the ‘:’ like this:
I find it much better than the ^^^ and s/// forms as you don’t have to retype the argument you wish to replace
March 10th, 2009 at 9:46 pm
[…] reading this: The Definitive Guide to Bash Command Line History - good coders code, great reuse might help […]
April 1st, 2009 at 4:54 pm
[…] http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/ […]
May 31st, 2009 at 12:41 pm
[…] Krumins has an excellent write-up called The Definitive Guide to Bash Command Line History which goes in-depth on many of the above topics, should you crave more bash history […]
August 2nd, 2009 at 6:06 pm
[…] The Definitive Guide to Bash Command Line History: http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/ […]
August 14th, 2009 at 7:41 pm
[…] Guide to Bash Command Line History: http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/ […]
October 15th, 2009 at 2:22 pm
[…] information as Goggle is your best freind. I am providing you with one link which you can refer: History Command Thanks, […]
November 29th, 2009 at 10:11 am
When we open several Linux pseudo-Terminals (tty1 to tty6 normally), their combined history is stored in the .bash_history file. I want to have a separate history maintained for each of the terminals. How do we achieve that?
December 5th, 2009 at 7:53 am
Parag Dave, try this:
Put the following in .bash_profile (or system wide file /etc/profile)
TTY=$(tty | sed ’s|/|_|g’)
HISTFILE=”~/.bash_history$TTY”
This should make HISTFILE to be ~/.bash_history_dev_tty1 for 1st, etc.
February 6th, 2010 at 1:45 pm
how to remove the error of readline in closed file handle while using perl scripting in centos 5.3
February 9th, 2010 at 5:45 pm
hello…
i have recently started learning perl…..and having issues when i try to read input from another file. the details of a script that i tried to run are as follows:
i made a text file by the name “text.txt” and the contents were
Sidra|38|BE
Hira|48|BE
Shagufta|50|BE
Then i wrote the following script
open(DAT, “text.txt”);
$data_file=” text.txt “;
open(DAT, $data_file);
@raw_data=;
hello…
i have recently started learning perl…..and having issues when i try to read input from another file. the details of a script that i tried to run are as follows:
i made a text file by the name “text.txt” and the contents were
Sidra|38|BE
Hira|48|BE
Shagufta|50|BE
Then i wrote the following script
open(DAT, “text.txt”);
$data_file=” text.txt “;
open(DAT, $data_file);
@raw_data=;
close(DAT);
foreach $student (@raw_data)
{
chomp($student);
($name,$roll_no,$class)=split(/\|/,$student);
print “The student $name bearing roll number $roll_no is in class $class”;
print “\n”;
}
the script produces no output and displays a message saying
“readline () closed filehandle at line ”
I tried the same with another file by the name “text.dat” holding the same data but it did not work either. Please help me out resolving this issue.
Thankyou…
March 1st, 2010 at 9:06 pm
I’m using this settings,
export HISTSIZE=100000
export HISTTIMEFORMAT=’%Y-%m-%d %H:%M ‘
export ignoredups
history then shows when the command has been issued to the terminal, which could be very usefull information from time to time.