Clearing Your Bash History

AID: 1093
  • Status: Published

1390 points

  • Byastrochimp
  • TypeGeneral
  • Posted on2009-07-01 at 06:51:04
Most computer savvy people have heard of GNU Linux and why it's either good or bad for them. A point that often comes up when GNU Linux is discussed is the fact that command line interface (CLI) knowledge is part of the skills required to operate a GNU Linux computer. This is a valid argument as graphical user interface (GUI) based applications on most GNU Linux distributions (i.e. Ubuntu, Fedora) are still not truly at the point where they can be considered replacements for direct CLI intervention. GUI applications are often simply front ends for CLI utilities and as such often do not truly capture all the power and extensibility of the latter.

The Bash Shell is often referred to as CLI. It is in fact only a single type of CLI, with its own command syntax rules. There are many other types of CLI implementations, but in GNU Linux the Bash Shell is usually the go-to CLI interface.

The Bash Shell is used to directly interface with all CLI based applications in GNU Linux. It also has its own commands which determine the way Bash Shell itself operates. These commands determine things like: how long of a history Bash Shell keeps, whether a user may use piped commands, keeping track of user assigned aliases for often used commands, etc. The Bash Shell can be the only place a user ever operates in as it provides all the necessary tools for day to day tasks like e-mail, internet access, word processing applications, and pretty much anything else you would normally see on a Windows and/or GNU Linux user's screen.

To open the Bash Shell and start playing with it, you will need to know where it is. It is usually located in a system tools or accessories menu branch and is referred to as the Terminal. This nomenclature is a call back to the olden days when an operator would sit at a CLI terminal and enter commands.

Sometimes during your day to day CLI activities you're forced to write passwords directly into your CLI of choice due to poor programming practices, poor user practices (if you're me), or simply because you don't have time to be the James Bond of the CLI. In such cases you need to make sure that the password doesn't stay logged on your system.

Everything you type (that's not intentionally obfuscated by the application or OS) into your CLI is usually logged. I use bash for my CLI needs. In bash all commands written in the CLI are stored in a file located in

~/.bash_history
                                    
1:

Select allOpen in new window



or

/home/(username)`_history
                                    
1:

Select allOpen in new window



If you do a

tail ~/.bash_history
                                    
1:

Select allOpen in new window



you will see all the commands (up to around 200 by default) that you've written into your terminal. This is usually very helpful because it lets you retrace your steps if something breaks, and allows you an easy way to recall long commands to the screen (by pressing the up arrow several times).

Sometimes you need to erase your bash history because it may contain important information. This is very easy to do. The first option is to run

history -c
                                    
1:

Select allOpen in new window



This will clear your whole history file. What if you want to remove a specific entry in your history file? You're in luck! the history command gives you a chance to do that

history | tail
                                    
1:

Select allOpen in new window



This pipes the output of your perhaps long history into a readable format with the latest commands first. Now you have to find the number of the command you want to remove. Get it and remember it.

history -d (number)
                                    
1:

Select allOpen in new window



That's all! This should give you a reasonable assurance that your commands will not be visible to would be root pirates (a.k.a.: hackers arrrrrrrg!), smart dogs, and curious siblings.
Asked On
2009-07-01 at 06:51:04ID1093
Tags

Linux

,

Bash Shell

,

CLI

Topic

Linux

Views
870

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Linux Experts

  1. arnold

    331,375

    Wizard

    750 points yesterday

    Profile
    Rank: Genius
  2. woolmilkporc

    279,119

    Guru

    2,668 points yesterday

    Profile
    Rank: Genius
  3. farzanj

    132,548

    Master

    0 points yesterday

    Profile
    Rank: Genius
  4. KeremE

    109,627

    Master

    0 points yesterday

    Profile
    Rank: Genius
  5. duncan_roe

    105,116

    Master

    0 points yesterday

    Profile
    Rank: Genius
  6. hanccocka

    99,734

    Master

    1,500 points yesterday

    Profile
    Rank: Genius
  7. legolasthehansy

    74,904

    Master

    0 points yesterday

    Profile
    Rank: Guru
  8. xterm

    65,407

    Master

    0 points yesterday

    Profile
    Rank: Sage
  9. Papertrip

    59,708

    Master

    0 points yesterday

    Profile
    Rank: Sage
  10. DaveBaldwin

    55,260

    Master

    0 points yesterday

    Profile
    Rank: Genius
  11. TobiasHolm

    46,700

    0 points yesterday

    Profile
    Rank: Sage
  12. rindi

    43,404

    0 points yesterday

    Profile
    Rank: Savant
  13. ahoffmann

    41,621

    0 points yesterday

    Profile
    Rank: Genius
  14. noci

    40,754

    0 points yesterday

    Profile
    Rank: Genius
  15. gerwinjansen

    38,789

    0 points yesterday

    Profile
    Rank: Sage
  16. Darr247

    38,657

    0 points yesterday

    Profile
    Rank: Genius
  17. chandranjoy

    36,828

    0 points yesterday

    Profile
    Rank: Master
  18. torakeshb

    33,696

    0 points yesterday

    Profile
    Rank: Master
  19. pfrancois

    33,520

    0 points yesterday

    Profile
    Rank: Guru
  20. un1x86

    30,652

    0 points yesterday

    Profile
    Rank: Master
  21. maeltar

    30,550

    0 points yesterday

    Profile
    Rank: Guru
  22. ozo

    24,100

    0 points yesterday

    Profile
    Rank: Savant
  23. jgiordano

    23,700

    0 points yesterday

    Profile
    Rank: Guru
  24. for_yan

    23,600

    1,000 points yesterday

    Profile
    Rank: Genius
  25. bummerlord

    23,300

    0 points yesterday

    Profile
    Rank: Master

Hall Of Fame