Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Sat Aug 19, 2017 2:43 am


Tips & Tricks, Questions regarding shell scripts, awk, perl, sed and much more.

Author Message
mandrei99
Post  Post subject: Linux / FreeBSD: Avoid bash history duplicate lines with HISTCONTROL  |  Posted: Mon Jan 12, 2015 12:01 pm

Joined: Tue Aug 04, 2009 9:16 am
Posts: 245

Offline
 

Linux / FreeBSD: Avoid bash history duplicate lines with HISTCONTROL

Linux / FreeBSD: Avoid bash history duplicate lines with HISTCONTROL

Please see previous article "How to increase bash history size in Linux" [url]/how-to-increase-bash-history-size-in-linux-t19491.html[/url] first.

Bash history, by default, is 500 lines long. Running the same command multiple times, consume multiple bash history entries. Example:
Code:
[user@linux ~]# one-command
-bash: one-command: command not found
[user@linux ~]# one-command
-bash: one-command: command not found
[user@linux ~]# one-command
-bash: one-command: command not found
[user@linux ~]# one-command
-bash: one-command: command not found
[user@linux ~]# one-command
-bash: one-command: command not found
[user@linux ~]# history | tail
  504  one-command
  505  one-command
  506  one-command
  507  one-command
  508  one-command
  509  history | tail


This is also inconvenient when searching through history (using CTRL+R) or shifting with up/down keys and the same command pops up every time.
To avoid duplicate lines in bash history use the following bash variable in /etc/profile.d/bash_hist.sh file:
Code:
export HISTCONTROL=ignoreboth:erasedups


And the result:
Code:
[user@linux ~]# two-command
-bash: two-command: command not found
[user@linux ~]# two-command
-bash: two-command: command not found
[user@linux ~]# two-command
-bash: two-command: command not found
[user@linux ~]# two-command
-bash: two-command: command not found
[user@linux ~]# history | tail
  503  one-command
  504  one-command
  505  one-command
  506  one-command
  507  one-command
  508  export HISTCONTROL=ignoreboth:erasedups
  509  two-command
  510  history | tail





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "Linux / FreeBSD: Avoid bash history duplicate lines with HISTCONTROL"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. How to increase bash history size in Linux

mandrei99

0

8379

Mon Jan 12, 2015 11:45 am

mandrei99 View the latest post

There are no new unread posts for this topic. Echo new line in linux - supress new line or echo multiple new lines

mandrei99

0

2788

Wed Jan 14, 2015 5:26 pm

mandrei99 View the latest post

There are no new unread posts for this topic. Remove empty lines in vi/vim

debuser

0

522

Mon Apr 26, 2010 11:06 am

debuser View the latest post

There are no new unread posts for this topic. Using sed to comment/uncomment lines in files

debuser

0

5046

Fri Apr 02, 2010 6:07 am

debuser View the latest post

There are no new unread posts for this topic. Unix shell - using TR to replace new lines with spaces

debuser

0

4855

Thu Feb 25, 2010 8:08 am

debuser View the latest post

There are no new unread posts for this topic. Password generator with user inputs bash script

Kvr123

0

319

Thu Dec 01, 2016 5:06 am

Kvr123 View the latest post

There are no new unread posts for this topic. SED uncomment line - How to uncomment a line or all lines with SED

mandrei99

0

3305

Wed Jan 14, 2015 5:08 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to echo newline in Linux/Unix shell

mandrei99

0

16707

Tue Jun 25, 2013 5:58 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to convert pdf to text in FreeBSD

mandrei99

1

1085

Thu Jan 08, 2015 10:08 am

mandrei99 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO