Preventing bash commands to be displayed in the history or deleting a specific command from history

It's sometimes useful when using the linux command line to prevent things to go into the bash history; for example if you're using curl to download a file while providing your username password.

This can be easily done in linux by configuring the HISTCONTROL variable in either your ~/.bashrc (which I recommend in order to have it permanently in your bash sessions) or by just changing the value for your current session.

Either way either set the variable as follows on your ~/.bashrc or on your current session

HISTCONTROL=ignorespace

If you took the ~/.bashrc approach don't forget to source it to have i

Once this is done commands that you start with a white space will be ignored :

[root@myserver] curl -o strx25.tar.bz2 --user user:password http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2

note the whitespace before the curl command

Removing a specific line from history

Now if you have to remove a specific line from history this is done in 2 steps

Display commands in history :

[root@myserver]history
  832  docker images
  833  docker rmi 0d22948b5794
  834  docker images
  835  docker rmi 1a31905bb4e4
  836  docker build -t dse/docker .
  837  docker images
  838  docker rmi 47a8395f9714
  839  docker build -t dse/docker .
  840  docker images
  841  docker rmi fe7a4702bf61
  842  docker ps
  843  docker ps -a
  844  docker rm e3f7c83390ee
  845  docker rmi fe7a4702bf61
  846  docker build -t dse/docker .
  847  docker images
  848  docker  rmi a386794cb70c

Once you identified the culprit; delete it with the following command (for example here the line 845):

history -d 845

OSX show used ports or listening applications with their PID

On OSX you can display applications listening on a given port using the lsof the commands described below will show listening application...