Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Using bash, I save my history with the timestamp.

How do print the history omitting the timestamp?

alias h=history
alias g=grep -i

To find lines that I used for heroku, I type:

> h | g heroku

I'd like to unique the results without the time-stamp, naturally.

This question is somewhat related: How to avoid duplicate entries in .bash_history

However, sometimes I want to see the duplicate in the history to see the context under which a command was run.

share|improve this question
2  
history | cut -d " " -f7-1000 | sort | uniq | grep heroku try this out. –  devav2 Oct 24 '12 at 1:58
    
Awesome -- I was hoping that history had an option to do what the cut command does. Only issue with the above is that all entries get sorted alphabetically. I'd rather the results get sorted such that the most recently used commands are last, as I'm more likely to use more recently used commands. –  justingordon Oct 24 '12 at 9:31
add comment

2 Answers 2

Addition to answer by @devav2

Clear/nullify the history timestamp environment variable

HISTTIMEFORMAT ="";

Export the following command,

export HISTCONTROL=ignoredups --> This will ignore the duplicates that are executed in sequence

share|improve this answer
    
ignoredups makes up error work poorly, because if the recent command is further up in the list, it doesn't get added again. –  justingordon Feb 28 at 17:27
    
@justingordon, Yes, using above comment by devav2, I have just added few information useful towards it. –  Raj S Mar 2 at 6:37
    
I'd still like to see the most recent time used, as well as remove any of the older duplicates, not just ones used twice. –  justingordon Mar 2 at 18:09
    
@justingordon for your 1st commment, ignoredups will remove duplicates that are in sequence so if you want your history in timeline order, use following command export HISTCONTROL=ignoredups history | cut -d " " -f7-1000 | grep heroku further, if you want to see timestamp of a particular command, export HISTTIMEFORMAT=" %F %T " Hope this seems to be helpful –  Raj S Mar 3 at 12:36
    
Raj, this does what I need: "history | cut -d " " -f7-1000 | sort | uniq | grep heroku", but the uniq command only removes duplicate lines adjacent. A simple program could substitute for sort | uniq and do the trick. Just wondering if there was a clever built-in way to do this. –  justingordon Mar 3 at 18:05
show 1 more comment

Simply, history | sed 's/.[ ]*.[0-9]*.[ ]*//' | uniq | grep -i "heroku"

the sed will remove the any [spaces][numbers][spaces] at the start of each line

for optimization make it

history | grep -i "heroku" | sed 's/.[ ]*.[0-9]*.[ ]*//' | uniq

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.