What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Maintained by Jon H.

Site originally by David Winterbottom (user root).

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands tagged history from sorted by
Terminal - Commands tagged history - 55 results
stty -ixon
2012-05-28 19:04:19
User: ricardofunke
Functions: stty

This command disable sending of start/stop characters.

It's useful when you want to use incremental reverse history search forward shortcut (Ctrl+s).

To enable again, type:

stty -ixoff
2012-04-15 16:42:32
User: moollaza

"What it actually shows is going to be dependent on the commands you've previously entered.

When you do this, bash looks for the last command that you entered that contains the substring "ls", in my case that was "lsof ...". If the command that bash finds is what you're looking for, just hit Enter to execute it. You can also edit the command to suit your current needs before executing it (use the left and right arrow keys to move through it).

If you're looking for a different command, hit Ctrl+R again to find a matching command further back in the command history. You can also continue to type a longer substring to refine the search, since searching is incremental.

Note that the substring you enter is searched for throughout the command, not just at the beginning of the command." - http://www.linuxjournal.com/content/using-bash-history-more-efficiently

history | awk '{$1=""; print $0}' > install_pkg.sh
2012-01-23 06:46:25
User: cfunz
Functions: awk
Tags: history

If you are installing some new package. You can first go through the step by step install and then take the commands that you ran from history to create shell script which can used to install the package on other machines say test or production.

2011-12-06 18:21:09
User: anarcat
Tags: history

!$ will be expanded to the last argument on the previous command. There are also positionnal parameters like !:1, !:2...

$ history -a #in one shell , and $ history -r #in another running shell
2011-11-05 01:19:30
User: b_t
Tags: history bash

By default bash history of a shell is appended (appended on Ubuntu by default: Look for 'shopt -s histappend' in ~/.bashrc) to history file only after that shell exits.

Although after having written to the history file, other running shells do *not* inherit

that history - only newly launched shells do.

This pair of commands alleviate that.

echo "shopt -s histappend" >> ~/.bashrc ; . ~/.bashrc
shopt -s histverify
2011-10-27 00:33:34
User: b_t
Tags: history bash

Bash history commands are those that begin with the character !

(eg. the most popular 'sudo !!' Explained here => http://www.commandlinefu.com/commands/view/13).

By default bash immediately executes the history command.

Setting this shell option will make bash first allow you to verify/edit an

history command before executing it.

To set this option permanently, put this command in ~/.profile or ~/.bashrc file.

To unset this option issue following command.

shopt -u histverify
<space> secret -p password
2011-09-16 12:41:16
User: pcholt

Put a space in front of your command on the command line and it will not be logged as part of your command line history.

2011-08-18 01:08:57
User: dbbolton
Tags: history bash zsh

You can find a command's history event number via the `history` command.

You can also put the history event number in your prompt: \! for bash, or %h for zsh.

Finally, I would like to point out that by "number", I mean POSITIVE INTEGER. Not, say, a letter, such as 'm'. Examples:



history -c
alias cdd="history -a && grep '^ *[0-9]* *cd ' ~/.bash_history| tail -10 >>~/.bash_history && history -r ~/.bash_history"
2011-07-13 09:44:16
User: knoppix5
Functions: alias

This alias is meant to append n (here is n=10) most recently used cd commands to the bottom of history file. This way you can easily change to one of previous visited directories simply by hitting 1-10 times arrow up key.

Hint: You can make more aliases implying the same rule for any set of frequently used long and complex commands like: mkisof, rdesktop, gpg...

history | tail -(n+1) | head -(n) | sed 's/^[0-9 ]\{7\}//' >> ~/script.sh
2011-06-08 13:40:58
Functions: head sed tail

Uses history to get the last n+1 commands (since this command will appear as the most recent), then strips out the line number and this command using sed, and appends the commands to a file.

2010-11-15 09:16:11
User: Delian
Functions: unset

Unsetting HISTFILE avoid getting current session history list saved.

export HISTSIZE=0
bind '"\C-h": "\`fc\ \-s\`"'
2010-08-16 17:58:16
User: rthemocap

This is similar to using `!!` or

In bash 4.1 it seems you can bind directly to a shell command, but I'm not running that version.

svn up -r PREV # revert
2010-07-07 23:09:00

* Add comment with # in your command

* Later you can search that command on that comment with CTRL+R

In the title command, you could search it later by invoking the command search tool by first typing CTRL+R and then typing "revert"

alias histdel='history -d $((HISTCMD-2)) && history -d $((HISTCMD-1))'
2010-07-02 00:20:44
Functions: alias

I rarely need this, but I have a hard time remembering the command when I need it.

Admit it. This has happened to you. Yes this is bad, and you better clean up now.

Borrowed from http://thoughtsbyclayg.blogspot.com/2008/02/how-to-delete-last-command-from-bash.html

proceed_sudo () { sudor_command="`HISTTIMEFORMAT=\"\" history 1 | sed -r -e 's/^.*?sudor//' -e 's/\"/\\\"/g'`" ; sudo sh -c "$sudor_command"; }; alias sudor="proceed_sudo # "
2010-06-29 14:56:29
User: mechmind
Functions: alias sh sudo
Tags: history sudo

USAGE: $ sudor your command

This command uses a dirty hack with history, so be sure you not turned it off.


This command behavior differ from other commands. It more like text macro, so you shouldn't use it in subshells, non-interactive sessions, other functions/aliases and so on. You shouldn't pipe into sudor (any string that prefixes sudor will be removed), but if you really want, use this commands:

proceed_sudo () { sudor_command="`HISTTIMEFORMAT=\"\" history 1 | sed -r -e 's/^.*?sudor//' -e 's/\"/\\\"/g'`" ; pre_sudor_command="`history 1 | cut -d ' ' -f 5- | sed -r -e 's/sudor.*$//' -e 's/\"/\\\"/g'`"; if [ -n "${pre_sudor_command/ */}" ] ; then eval "${pre_sudor_command%| *}" | sudo sh -c "$sudor_command"; else sudo sh -c "$sudor_command" ;fi ;}; alias sudor="proceed_sudo # "
2010-06-12 02:48:27
User: dbbolton
Tags: history bash zsh

'n' is a non-negative integer. Using 0 will expand to the name of the previous command.

history | awk '{a[$'$(echo "1 2 $HISTTIMEFORMAT" | wc -w)']++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
git log --all --pretty=format:" " --name-only | sort -u
2010-05-11 16:06:42
Functions: sort
Tags: history git

What was the name of that module we wrote and deleted about 3 months ago? windowing-something?

git log --all --pretty=format:" " --name-only | sort -u | grep -i window
history | awk '{a[$'$(echo "1 2 $HISTTIMEFORMAT" | wc -w)']++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
2010-05-02 21:48:53
User: bandie91
Functions: awk echo sort wc
Tags: history awk wc

If you use HISTTIMEFORMAT environment e.g. timestamping typed commands, $(echo "1 2 $HISTTIMEFORMAT" | wc -w)

gives the number of columns that containing non-command parts per lines.

It should universify this command.

history | perl -F"\||<\(|;|\`|\\$\(" -alne 'foreach (@F) { print $1 if /\b((?!do)[a-z]+)\b/i }' | sort | uniq -c | sort -nr | head
2010-04-08 13:46:09
User: alperyilmaz
Functions: perl sort uniq

Most of the "most used commands" approaches does not consider pipes and other complexities.

This approach considers pipes, process substitution by backticks or $() and multiple commands separated by ;

Perl regular expression breaks up each line using | or < ( or ; or ` or $( and picks the first word (excluding "do" in case of for loops)

note: if you are using lots of perl one-liners, the perl commands will be counted as well in this approach, since semicolon is used as a separator

2010-02-06 18:35:10
User: drewk

Bash has a great history system of its commands accessed by the ! built-in history expansion operator (documented elsewhere on this site or on the web). You can combine the ! operator inside the process redirection

Very handy.