Commands tagged history (56)

  • Command 'favorite' to store your favorite commands from history. Show Sample Output


    -3
    favorite --add myhost 'ssh me@myhost'
    djangofan · 2017-01-23 18:15:03 1
  • This is the way to get access to your Firefox history...


    8
    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;"
    return13 · 2015-02-24 21:51:14 1
  • 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.


    0
    nohist(){ export HISTFILE=/dev/null; }
    ivanalejandro0 · 2014-12-31 22:30:08 2
  • Replaces current history with what's in the history file (~/.bash_history) thereby deleting the current session history.


    0
    history -r
    wanker · 2014-11-08 10:58:40 0
  • Top 30 History Command line with histogram display Show Sample Output


    1
    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";}'
    injez · 2014-09-29 12:40:43 0
  • 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...


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

  • 0
    function hgr() { grep --color -i "${1}" ~/.bash_history | sed -e 's/^ *//g' -e 's/ *$//g' | sort | uniq; }
    doge · 2013-11-27 16:54:02 0
  • 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. Show Sample Output


    0
    echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
    99RedBalloons · 2013-09-19 03:25:14 0
  • 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. Show Sample Output


    10
    !:n
    hackerb9 · 2013-09-15 03:41:13 1
  • [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' >> ~/.inputrcecho '"\ep": history-search-backward' >> ~/.inputrcbind -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. ☺) Show Sample Output


    9
    <Meta-p> (aka <ALT+P>)
    hackerb9 · 2013-09-10 17:13:02 3
  • 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. Show Sample Output


    0
    function garg () { tail -n 1 ${HISTFILE} | awk "{ print \$$1 }" }
    plasticphyte · 2013-09-10 04:07:46 0
  • <space>secret_command;export HISTCONTROL= This will make "secret_command" not appear in "history" list.


    3
    export HISTCONTROL=ignorespace
    gorynka · 2013-07-25 08:31:10 0
  • 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)}'"


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

  • -1
    cat $HISTFILE | grep command
    Stolas · 2013-05-01 13:11:05 0
  • this also can find the old command you used before


    0
    history | tail -100 | grep cmd
    datamining · 2013-04-22 03:49:43 0
  • 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.


    -9
    cat .bash_history | tail -100 | grep {command}
    techie · 2013-04-10 10:40:52 3
  • 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.. Show Sample Output


    0
    export HISTFILE=/dev/null
    sonic · 2013-02-18 16:37:01 0
  • just use a space to prevent commands from being recorded in bash's history on most systems


    4
    _ls
    marcusEting · 2013-02-02 00:44:01 0

  • 2
    history -d $((HISTCMD-1)) && command_to_run
    bleiva · 2013-02-01 15:06:08 6
  • this one works on user crontab


    0
    gzip -c ~/.bash_history > ~/.backup/history-save-$(date +\%d-\%m-\%y-\%T).gz
    tictacbum · 2013-01-11 17:31:07 0
  • set how many commands to keep in history Default is 500 Saved in /home/$USER/.bash_history Add this to /home/$USER/.bashrc HISTFILESIZE=1000000000 HISTSIZE=1000000


    1
    export HISTFILESIZE=99999
    totti · 2013-01-02 09:25:06 1
  • hide your ass, buddy.


    0
    export HISTSIZE=0
    kiiwii · 2012-11-17 14:12:34 1
  • simple and easy backup your history with timestamp Show Sample Output


    2
    history > ~/history-save-$(date +%d-%m-%y-%T)
    unixmonkey14859 · 2012-08-18 07:40:33 0
  • This makes your commandlinefu.com's favorites appear as most recent commands in your history.


    5
    (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
    xenomuta · 2012-08-17 12:31:51 0
  • 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 user@localhost will be registered in the history as well, and it's not usable.


    1
    ssh user@hostname.domain "> ~/.bash_history"
    maxadamo · 2012-07-09 14:29:22 0
  •  1 2 3 > 

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands



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: