November 21, 2024

Real Tech Reviews

-Real reviews, real people-

Terminal Trick To Avoid Writing A Command To .bash_history

Why would you want to avoid writing a command to your Bash history file?

Maybe you are performing a penetration test and you want to demonstrate to your client that your exploitation methods don’t leave a trace. Maybe you don’t want to save a command on a work computer or shared shell.

*Enter any other reason here*

Most terminals offer an easy solution to prevent your command from being written to the Bash history folder so that you don’t have to use any clever solutions to delete the line from .bach_history.

Enter the “space”

If you precede your command with a space, most terminals won’t even attempt to write it to your .bash_history, saving you the step of deleting it and running the chance that the command may get picked up by some .bash_history profiling software or the like.

Simply add a space to the beginning of any command you do not want recorded. Take the following command for example:

If you enter this in the terminal, it will execute as expected giving you a list of all the files in your current directory, however when you hit up or run a history command it’s not saved.

” ls -a”

For example, running la -a without using a space:

Running history following an ls -a, I get the list of previous commands, including the ls -a as expected:

Now I run an echo command with a space before echo:

Finally, I run history again. Note the echo command is not listed:

I thought that is a cool little trick and deserves a write-up!

Do you know any similar tips or tricks?