Skip to content
Related Articles

Related Articles

Whitespaces Before Any Command in Linux

View Discussion
Improve Article
Save Article
  • Last Updated : 19 Feb, 2020
View Discussion
Improve Article
Save Article

By default, the history command does not show the commands in which you have inserted a space at the start. So, to overcome this, you need to make changes to .bashrc file.

For Example, Suppose you run rm -rf /test* command and you have inserted a blank space at the start of the command. If you then run history command, you will end up with the list of commands except for the last ran command(which you run with a blank space in the beginning).

  • Run “history 5” and see the 5 latest commands that you ran.
  • Run ” ls” Add a white space at the beginning of the command
  • Run “history 5″ again and you will see that ” ls” is missing.

See the screenshot below:

history command

You can use HISTCONTROL (defined in the .bashrc) to control what needs to be stored in the history file. The possible options are:

  • HISTCONTROL=ignorespace (Commands starting with white spaces will not be stored).
  • HISTCONTROL=ignoredups (Duplicate Commands will not be stored).
  • HISTCONTROL=ignoreboth (It will ignore both of the above cases).

Interesting Fact: If you run a command like "sudo !!" , it will add sudo to the previous command you ran. For Example, Try to run the following commands in your terminal and see.

  • Run “mkdir ~/Desktop/Test”
  • Run “sudo !!”

The second command executed will be “sudo mkdir ~/Desktop/Test“. It is useful when you try to install some dependencies in your project/system. It is very useful in case you need Super User Permission.

sudo !! command

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!