banner



Bash basics: How to use (and scrub) your shell’s command history - wolffchout1949

For many users who develop started with the command personal credit line in Linux, there's a peachy chance they're exploitation Bourn Again Shell, or Bash. Bash is the default trounce along Mac OS X, and Windows users can use Bash finished the Windows Subsystem for Linux.

While Bash generally works just tight with little to no configuration, there are some features that give the axe really make the crush Thomas More efficacious. One of those commands ishistory.

Looking back out sooner or later

If you've ever looked at your web browser's history, you already have a thoroughly idea of how history works. Belt's history stores the history of commands that have been entered on the command line. This pot be useful if you've ever wondered how you did something earlier.

bash history Alex Campbell

The history command showing recently eneterd commands. Note the misspelledpacman command (14) and the subsequent incoming of a word on the command line (15).

To see a inclination of past commands, simply casehistory connected the command line. You'll go steady a listing of commands (includinghistory) that birth been entered during the current shell academic session.

Bash's history also provides pointer-key navigation. If you open a Do shell and press the up pointer, you'll see the antecedently entered instruction appear on the program line line.

Bash keeps its history in memory until the shell session is union, when IT will write information technology to disk (the file is generally placed at /home/(user)/.bash_history). You nates manually tack on the current history to the history file using the-a change like indeed:

          $ history -a        

You can too supplement the history from file to the current session with the -n switch. If you prefer that the history file overwrite the history in memory, use the -r switch. Finally, you can overwrite the history single file with the -w switch.

Sending history to the memory board hole

While keeping a story of all overlook you've entered can represent convenient, just like keeping every message in your Gmail story or leaving your web browser history untouched. Only like leaving those troves of data alone, they can grow to become security measures risks. I for one keister recall entering passwords along the command contrast without thought process about it because a old command failed. For advanced users who make use of SSH OR database connections, those commands allow passing passwords as command demarcation arguments.

clear history Alex Cmapbell

Clearing Bash's history in memory only takes one program line.

For those users who are a trifle more paranoid about privacy, a Bash history file represents a trove of metadata roughly how a person uses his or her computer.

As luck would have it, you can delete your history from memory with the-c switch. Only be cautious: Clearing the account from memory does notclear the history file. If you remember the-w switch I mentioned earlier, you have the tool for the job. To clear the history file, only clear the memory with the -c switch then write the (mostly) blank file to disk with the -w change:

          $ history -c          $ history -w        

Information technology give the sack get a little tedious having to remember to clear your history file each time you're done working, merely you stool also set the uncertain HISTFILESIZE to zero to prevent extra lines from organism written. To keep the changes, you can echo the setting dead to ~/.bash_profile:

          $ echo "HISTFILESIZE=0" >> ~/.bash_profile        

You can delete a single-entry bookkeeping in your Bash history with the -d switch followed past the command's reference rail line (which is displayed to the left of the list of commands):

          $ history -d 42        

This is great for when you make you accidentally typed a password and just need to clear that one goof.

Optional history

Sometimes keeping a history isn't such a bad thing, but several people mightiness prefer having a choice or so what gets recorded and when. Smash has those people covered excessively, with a extra setting that tells the history recorder to ignore every command that begins with a space character.

In Bash, commands run equitable the same if they are typed with 10 spaces in front of the command, Beaver State none. The setting HISTCONTROL is a list of control settings that Bash uses to control its behavior. If HISTCONTROL is set with "ignorespace", Whap wish omit any overtop with a preceding quad theatrical role from its history.

To set HISTCONTROL temporarily, type:

          $ HISTCONTROL="ignorespace"        

To set IT for good, add it to your .bash_profile lodge:

          $ echo "HISTCONTROL="ignorespace"" >> ~/.bash_profile        
ignorespace Alex Campbell

With "ignorespace" enabled, you can keep commands out of the history by preceeding them with a space character.

While keeping your Bonk history aweigh and clear of information may seem frivolous, it can be important to the budding developer Beaver State anyone using a shared computer. Call up: While other regular users of a Linux or Macintosh machine can't read the history file, anyone who can obtain root privileges can. If you'Re sending in your laptop for repair or having another untrusted person access to your computer, equal sure to wipe off your Do (non scarce World Wide Web) history.

Source: https://www.pcworld.com/article/411725/bash-basics-how-to-use-and-scrub-your-shells-command-history.html

Posted by: wolffchout1949.blogspot.com

0 Response to "Bash basics: How to use (and scrub) your shell’s command history - wolffchout1949"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel