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



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
favorite --add myhost 'ssh [email protected]'
2017-01-23 18:15:03
User: djangofan
Tags: history

Command 'favorite' to store your favorite commands from history.

sqlite3 ~/.mozilla/firefox/*.[dD]efault/places.sqlite "SELECT strftime('%d.%m.%Y %H:%M:%S', visit_date/1000000, 'unixepoch', 'localtime'),url FROM moz_places, moz_historyvisits WHERE moz_places.id = moz_historyvisits.place_id ORDER BY visit_date;"
2015-02-24 21:51:14
User: return13

This is the way to get access to your Firefox history...

nohist(){ export HISTFILE=/dev/null; }
2014-12-31 22:30:08
Functions: export

Yo run the `nohist` command and after that the commands won't get stored in the history file for the current session.

This makes no permanent changes.

history|awk '{print $2}'|sort|uniq -c|sort -rn|head -30|awk '!max{max=$1;}{r="";i=s=100*$1/max;while(i-->0)r=r"#";printf "%50s %5d %s %s",$2,$1,r,"\n";}'
2014-09-29 12:40:43
User: injez
Functions: awk head printf sort uniq

Top 30 History Command line with histogram display

quickscript () { filename="$1"; history | cut -c 8- | sed -e '/^###/{h;d};H;$!d;x' | sed '$d' > ${filename:?No filename given} }
2014-02-09 12:19:29
User: joedhon
Functions: cut sed

In order to write bash-scripts, I often do the task manually to see how it works. I type ### at the start of my session.

The function fetches the commands from the last occurrence of '###', excluding the function call. You could prefix this with a here-document to have a proper script-header.

Delete some lines, add a few variables and a loop, and you're ready to go.

This function could probably be much shorter...

function hgr() { grep --color -i "${1}" ~/.bash_history | sed -e 's/^ *//g' -e 's/ *$//g' | sort | uniq; }
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
2013-09-19 03:25:14
Functions: echo

If the HISTTIMEFORMAT is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment character.

2013-09-15 03:41:13
User: hackerb9

Bash's history expansion character, "!", has many features, including "!:" for choosing a specific argument (or range of arguments) from the history. The gist is any number after !: is the number of the argument you want, with !:1 being the first argument and !:0 being the command. See the sample output for a few examples. For full details search for "^HISTORY EXPANSION" in the bash(1) man page.

 Note that this version improves on the previous function in that it handles arguments that include whitespace correctly.

<Meta-p> (aka <ALT+P>)
2013-09-10 17:13:02
User: hackerb9
Tags: history bash tcsh

[Click the "show sample output" link to see how to use this keystroke.]

Meta-p is one of my all time most used and most loved features of working at the command line. It's also one that surprisingly few people know about. To use it with bash (actually in any readline application), you'll need to add a couple lines to your .inputrc then have bash reread the .inputrc using the bind command:

echo '"\en": history-search-forward' >> ~/.inputrc

echo '"\ep": history-search-backward' >> ~/.inputrc

bind -f ~/.inputrc

  I first learned about this feature in tcsh. When I switched over to bash about fifteen years ago, I had assumed I'd prefer ^R to search in reverse. Intuitively ^R seemed better since you could search for an argument instead of a command. I think that, like using a microkernel for the Hurd, it sounded so obviously right fifteen years ago, but that was only because the older way had benefits we hadn't known about.

  I think many of you who use the command line as much as I do know that we can just be thinking about what results we want and our fingers will start typing the commands needed. I assume it's some sort of parallel processing going on with the linguistic part of the brain. Unfortunately, that parallelism doesn't seem to work (at least for me) with searching the history. I realize I can save myself typing using the history shortly after my fingers have already started "speaking". But, when I hit ^R in Bash, everything I've already typed gets ignored and I have to stop and think again about what I was doing. It's a small bump in the road but it can be annoying, especially for long-time command line users. Usually M-p is exactly what I need to save myself time and trouble.

  If you use the command line a lot, please give Meta-p a try. You may be surprised how it frees your brain to process more smoothly in parallel. (Or maybe it won't. Post here and let me know either way. ☺)

function garg () { tail -n 1 ${HISTFILE} | awk "{ print \$$1 }" }
2013-09-10 04:07:46
User: plasticphyte
Functions: awk tail

This gets the Nth argument in the last line of your history file. This is useful where history is being written after each command, and you want to use arguments from the previous command in the current command, such as when doing copies/moving directories etc.

I wrote this after getting irritated with having to continually type in long paths/arguments.

You could also use $_ if all you want is the last argument.

export HISTCONTROL=ignorespace
2013-07-25 08:31:10
User: gorynka
Functions: export
<space>secret_command;export HISTCONTROL=

This will make "secret_command" not appear in "history" list.

history | awk '{$1="";print substr($0,2)}'
2013-07-07 08:00:26
User: Fagood
Functions: awk
Tags: history awk

alias h="history | awk '{\$1=\"\";print substr(\$0,2)}'"

# h

[ 07/07/2013 10:04:53 ] alias h="history | awk '{\$1=\"\";print substr(\$0,2)}'"

cat $HISTFILE | grep command
history | tail -100 | grep cmd
2013-04-22 03:49:43
User: datamining
Functions: grep tail

this also can find the old command you used before

cat .bash_history | tail -100 | grep {command}
2013-04-10 10:40:52
User: techie
Functions: cat grep tail

I know how hard it is to find an old command running through all the files because you couldn't remember for your life what it was. Heres the solution!! Grep the history for it. depending on how old the command you can head or tail or if you wanted to search all because you cannot think how long ago it was then miss out the middle part of the command. This is a very easy and effective way to find that command you are looking for.

export HISTFILE=/dev/null
2013-02-18 16:37:01
User: sonic
Functions: export
Tags: history bash

just an alternative to setting the size, this allows you to scroll up and see your previous commands in a given session but when you logout the history is not saved. That's the only advantage to doing it this way..

2013-02-02 00:44:01
User: marcusEting
Tags: history

just use a space to prevent commands from being recorded in bash's history on most systems

history -d $((HISTCMD-1)) && command_to_run
gzip -c ~/.bash_history > ~/.backup/history-save-$(date +\%d-\%m-\%y-\%T).gz
2013-01-11 17:31:07
User: tictacbum
Functions: date gzip
Tags: history backup

this one works on user crontab

export HISTFILESIZE=99999
2013-01-02 09:25:06
User: totti
Functions: export

set how many commands to keep in history

Default is 500

Saved in /home/$USER/.bash_history

Add this to /home/$USER/.bashrc



export HISTSIZE=0
history > ~/history-save-$(date +%d-%m-%y-%T)
2012-08-18 07:40:33
Functions: date
Tags: history

simple and easy backup your history with timestamp

(cat ~/.bash_history;U='curl -s www.commandlinefu.com';$U/users/signin -c/tmp/.c -d'username=<USER>&password=<PASS>&submit=1'|$U/commands/favourites/json -b/tmp/.c|grep -Po 'nd":.*?[^\\]",'|sed -re 's/.*":"(.*)",/\1/g')>~/.h;HISTFILE=~/.h bash --login
2012-08-17 12:31:51
User: xenomuta
Functions: bash cat grep sed

This makes your commandlinefu.com's favorites appear as most recent commands in your history.

ssh [email protected] "> ~/.bash_history"
2012-07-09 14:29:22
User: maxadamo
Functions: ssh

Only from a remote machine:

Only access to the server will be logged, but not the command.

The same way, you can run any command without loggin it to history.

ssh [email protected] will be registered in the history as well, and it's not usable.

<ctrl+p> for previous command; <ctrl+n> for next command
2012-06-01 11:25:09
Tags: history

Sometimes easier to just hit these keys to access previous / next commands in history instead of moving your hands all the way to the cursor keys