Tweaking history on Linux | Network World

Tweaking history on Linux | Network World

The bash historical past command on Linux techniques helps with remembering instructions you’ve beforehand run and repeating these instructions with out having to retype them.You may resolve, hotheyver, that you simply’d be simply as blissful to neglect that you simply referenced a dozen man pages, listed your recordsdata each 10 minutes or vietheyd beforehand run instructions by typing “history”. In this publish, they’re going to have a look at how one can get the historical past command to recollect simply what you need it to recollect and neglect instructions which can be more likely to be of little “historic value”.

Viewing your command historical past

To view beforehand run instructions, you merely sort “history”. You’ll in all probability see a protracted record of instructions. The variety of instructions remembered is determined by an setting variable known as $HISTSIZE that’s arrange in your ~/.bashrc file, however there’s nothing stopping you from altering this setting if you wish to save extra or fetheyr instructions.To view historical past, use the historical past command:$ historical past 209 uname -v 210 date 211 man chage … To see the utmost variety of instructions that shall be displayed:$ echo $HISTSIZE 500 You can change $HISTSIZE and make the change everlasting by working instructions like these:$ export HISTSIZE=1000 $ echo “HISTSIZE=1000” >> ~/.bashrc There’s additionally a distinction bettheyen how a lot historical past is preserved for you and the way a lot is displayed whenever you sort “history”. The $HISTSIZE variable controls how a lot historical past is displayed whereas the $HISTFILESIZE variable controls what number of instructions are retained in your .bash_history file.$ echo $HISTSIZE 1000 $ echo $HISTFILESIZE 2000 You can confirm the second variable by counting the traces in your historical past file:$ wc -l .bash_history 2000 .bash_history One factor to bear in mind is that instructions that you simply enter throughout a login session aren’t added to your .bash_history file till you log out, despite the fact that they present up within the historical past command output immediately.

Using historical past

There are 3 ways to reissue instructions that you simply discover in your historical past. The easiest method, particularly if the command you need to reuse was run not too long ago, is commonly to sort a ! follotheyd by sufficient of the primary letters within the command’s title to uniquely establish it.$ !u uname -v #37-Ubuntu SMP Thu Mar 26 20:41:27 UTC 2020 Another straightforward technique to repeat a command is to easily press your up-arrow key till the command is displayed after which press enter.Alternately, when you run the historical past command and see the command you need to rerun listed, you’ll be able to sort an ! follotheyd by the sequence quantity proven to the left of the command.$ !209 uname -v #37-Ubuntu SMP Thu Mar 26 20:41:27 UTC 2020

Hiding historical past

If you need to cease recording instructions for some time period, you should use this command:$ set +o historical past Commands is not going to present up whenever you sort “history” nor will they be added to your .bash_history file whenever you exit the session by logging off or exiting the terminal.To reverse this setting, use set -o historical past. To make it everlasting, you’ll be able to add it to your .bashrc file, although failing to utilize command historical past altogether is usually not a good suggestion.$ echo ‘set +o historical past’ >> ~/.bashrc To briefly clear historical past, in order that solely instructions that you simply enter afterwards present up whenever you sort “history”, use the historical past -c (clear) command:$ historical past | tail -3 209 uname -v 210 date 211 man chage $ historical past -c $ historical past 1 historical past NOTE: The instructions entered after typing “history -c” is not going to be added to your .bash_history file.

Controlling historical past

The command historical past settings on many techniques will default to together with one known as $HISTCONTROL that ensures that, even when you run the identical command seven occasions in a row, it would solely be remembered as soon as. It additionally ensures that instructions that you simply sort after first getting into a number of blanks shall be omitted out of your command historical past.$ grep HISTCONTROL .bashrc HISTCONTROL=ignoreboth The “ignoreboth” means “ignore both duplicate commands and command starting with blanks”. For instance, when you sort these instructions:$ echo do this $ date $ date $ date $   pwd $ historical past your historical past command ought to report one thing like this:$ historical past $ echo do this $ date $ historical past Notice that the sequential date instructions theyre decreased to 1 and the indented command was omitted.

Overlooking historical past

To ignore sure instructions in order that they by no means present up whenever you sort “history” and are by no means added to your .bash_history file, use the $HISTIGNORE setting. For instance:$ export HISTIGNORE=”historical past:cd:exit:ls:pwd:man” This setting will trigger all historical past, cd, exit, ls, pwd and man instructions to be omitted out of your historical past output and your .bash_history file.If you need to make this setting everlasting, you need to add it to your .bashrc file.$ echo ‘HISTIGNORE=”history:cd:exit:ls:pwd:man”‘ >> .bashrc This setting simply implies that whenever you look again by beforehand run instructions, the record gained’t be cluttered by instructions that you simply’re unlikely to be on the lookout for when you’re wanting by your command historical past.

Remembering, ignoring and forgetting the previous

Command historical past is beneficial as a result of it helps you bear in mind what instructions you’ve not too long ago used and reminds you about modifications you’ve not too long ago made. It additionally makes it simpler to rerun instructions, particularly these with a string of arguments that you do not essentially need to recreate. Tailoring your historical past settings could make your use of command historical past somewhat simpler and extra environment friendly. Join the Network World communities on Facebook and LinkedIn to touch upon subjects which can be high of thoughts. Copyright © 2020 IDG Communications, Inc.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *