Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-06-2007, 12:39 PM   #1
LQ Newbie
Registered: Dec 2007
Posts: 3

Rep: Reputation: 0
Hw to clear the selected lines from History?

From the help of this forem I have got hw to clear the history..using history -c .. But how to clear the particular lines from the history, insted of deleting whole history lines.. I am expecting the positive replies from seniors...
Old 12-06-2007, 12:57 PM   #2
Mega Man X
LQ Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 64
Hi linuxxx123!

I hope you are talking about bash. I really don't know what you mean by "hw". It that is the case, this might help you:

You can also delete lines manually, I suppose, by editing you ~/.bash_history. It is a simple text file that you can edit with any text-editor. I never did it though...
Old 12-06-2007, 01:54 PM   #3
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,459
Blog Entries: 1

Rep: Reputation: 66
There is a small trick I learned just a few weeks ago that can help you: any commands preceded by one or more spaces are not recorded in history as in " ls /etc".

And you set a list of commands in shell variable HISTIGNORE. The commands in this list are not recorded in the history. For example, mine looks like:
Old 12-10-2007, 02:59 PM   #4
LQ Newbie
Registered: Dec 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks a lot

Thank you for all valuable replies... History -d command is exactly fulfill my requirement.. But I canít able to use this command for delete more than one line. Please explain me how to use this command for delete the more number of selected lines. For example delete the line 25 to 56 from bash.

Once again thank you for your valuable replies.
Old 12-11-2007, 01:05 AM   #5
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,802

Rep: Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540
Just add a loop around the cmd, specifying which line nums to delete.
Old 12-11-2007, 02:50 AM   #6
LQ Guru
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
How about just more or less manually altering the history file (like .bash_history), maybe with sed or something?
Old 01-08-2009, 03:56 PM   #7
Registered: Apr 2003
Distribution: ANY
Posts: 339

Rep: Reputation: 32
If you just want the history erased try this.

"rm .bash_history" time you login and issue a command bash will create a new history file with a clean slate.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I clear history in Linux ibrahimt Linux - Security 8 07-14-2009 02:15 AM
How to clear history hi_msh Linux - Newbie 2 01-12-2006 05:40 AM
history clear command suguname Linux - Newbie 5 03-05-2005 09:32 AM
How do I clear all my RedHat 9 History? PionexUser Linux - General 1 11-20-2003 10:42 AM
Clear History Mystified Linux - Newbie 1 03-25-2002 09:27 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:06 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration