USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

Remove bash_history duplicates & increase history size.
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming
View previous topic :: View next topic  
Author Message
monsterb
Jr. Member


Joined: 16 Oct 2024
Posts: 85
Location: Indiana

PostPosted: Sun Dec 31, 2024 6:18 am    Post subject: Remove bash_history duplicates & increase history size. Reply with quote

To remove duplicates in your .bash_history file, export this variable in the .bashrc file:

HISTCONTROL=erasedups

To increase the .bash_history size from 500 to 1000 commands, export this variable in the .bashrc file:

HISTSIZE=1000

Restart your shell to see changes. (eraseups only works with Bash 3 and up)


Back to top
View user's profile Send private message Send e-mail Visit poster's website
JP
Linux Guru


Joined: 07 Jul 2024
Posts: 6670
Location: Central Montana

PostPosted: Mon Jan 01, 2024 4:12 am    Post subject: Reply with quote

Thanks, I'm trying that now .... <(:^D



_________________
Dell Box - Arch Linux
Dell Lappy - DreamLinux 3.5 - Default OS
Mepis 8.0 - Backup
Back to top
View user's profile Send private message Visit poster's website
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Mon Jan 01, 2024 4:31 am    Post subject: Reply with quote

an easy way to search your history files.......

add the following alias to your .bashrc file

i used "hs" for history search .....
Code:

alias hs='history | grep $1'


the quotes are not needed unless your searching for more than one word.... examples

Code:


[crouse@localhost ~]$ hs alias
   34  alias
   40  alias
   86  alias
  102  alias
  113  alias
  502  hs alias
[crouse@localhost ~]$


[crouse@localhost ~]$ hs "grep ve"
  230  history | grep vec*
  231  history | grep vec
  232  history | grep ve*
  503  hs "grep ve"
[crouse@localhost ~]$





_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
Deuce868
Member


Joined: 04 May 2024
Posts: 140

PostPosted: Sun Jan 14, 2024 1:56 am    Post subject: Reply with quote

going back through history is what control-r is for. You don't need a custom command for it.


Back to top
View user's profile Send private message
jada
Linux Guru


Joined: 13 May 2024
Posts: 3064
Location: Sun City, CA 92585

PostPosted: Sun Jan 14, 2024 4:35 am    Post subject: Reply with quote

I posted not a long time ago at http://www.bashscripts.org/ and if you get this error "argument list to long"

run
Code:

$ find /tmp -maxdepth 1 -name "*" -print0 |xargs -0 rm -f



_________________
openSUSE 11.1 Desktop KDE 4.3.1 buildservice Factory
Linux Mint 7 Desktop Gnome
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Sun Jan 14, 2024 7:42 am    Post subject: Reply with quote

Deuce868 wrote:
going back through history is what control-r is for. You don't need a custom command for it.


oh...... I don't know, I like the way mine looks, when i'm searching through my history (very large) , I get all the instances of it quickly.

Code:

[crouse@localhost ~]$ hs pacman
   61  pacman -Ss libdvdcss
  121  pacman -Si vobcopy
  220  pacman -Si gobby
  241  cd pacman.d
  254  less pacman.log
  276  pacman -Si vctl
  277  pacman -Si thunderbird
  301  pacman -Si pacman
  302  pacman -Ss pacman
  354  less /var/log/pacman.UPDATELOG
  428  cd pacman.d
  436  less pacmanauto.sh
  447  pacman -Si pygtk
  481  less /etc/pacman.conf
  484  less /etc/pacman.conf
  504  hs pacman
[crouse@localhost ~]$



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
Deuce868
Member


Joined: 04 May 2024
Posts: 140

PostPosted: Sun Jan 14, 2024 7:37 pm    Post subject: Reply with quote

Right, but control-r will put the command at your prompt. So let's say you wanted to go back and repeat your rsync command you ran yesterday you can do

ctrl-r rsync <enter> and the whole command plops down there for you.

What do you do with your script? Copy/paste for just retype it?


Back to top
View user's profile Send private message
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Sun Jan 14, 2024 9:52 pm    Post subject: Reply with quote

I'm usually in KDE .... using Konsole, so I can cut-n-paste from one terminal to another. So my way comes in pretty handy for what I'm doing. Many times, I need to run said command on another machine i'm logged into, and it's just a matter of quickly finding that command. This way I don't have to cycle through a bunch of commands to find the one i want quickly. It's just more convenient for what I happen to be doing most of the time. Wink Your way works too, just takes me longer if i have a history list that's really long.



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
monsterb
Jr. Member


Joined: 16 Oct 2024
Posts: 85
Location: Indiana

PostPosted: Sun Jan 14, 2024 11:40 pm    Post subject: Re: Remove bash_history duplicates & increase history si Reply with quote

monsterb wrote:
To remove duplicates in your .bash_history file, export this variable in the .bashrc file:

HISTCONTROL=erasedups

To increase the .bash_history size from 500 to 1000 commands, export this variable in the .bashrc file:

HISTSIZE=1000

Restart your shell to see changes. (eraseups only works with Bash 3 and up)


Alot of great ideas for bash_history here -- keep them coming 'Wink'

I like scrolling through bash_history with the up and down arrow keys. The variable "HISTCONTROL=erasedups" removes all the duplicates like "ls" and so on.


Back to top
View user's profile Send private message Send e-mail Visit poster's website
orphius
New Member


Joined: 25 Sep 2024
Posts: 9

PostPosted: Thu Sep 25, 2024 9:49 pm    Post subject: histcontrol not working Reply with quote

I have tried the "HISTCONTROL=erasedups" and it never works. I have tried putting in my "/etc/bashrc and /et/profile and ~/.bashrc"
None of these options work. I could really use some help on this.
By the way I am using Pclinuxos Minime 2024. If that helps?


Back to top
View user's profile Send private message
rumbarg
Jr. Member


Joined: 06 Jun 2024
Posts: 69
Location: Houston, TX

PostPosted: Thu Sep 25, 2024 11:02 pm    Post subject: Reply with quote

I just tried this myself - didn't have a .bashrc - the file I had to edit was /etc/bash.bashrc

Seems to have worked, but the filename is different here in sidux.

regards,

rumbarg



_________________
sidux sidux 2024-01 - Χάος
Back to top
View user's profile Send private message
orphius
New Member


Joined: 25 Sep 2024
Posts: 9

PostPosted: Fri Sep 26, 2024 12:15 am    Post subject: Reply with quote

Yes sidux is drastically different. However, do you know which version of bash you are using. This may be a problem with the specific version of bash and not the distro. If you want to know the version of your bash, use the following at the command prompt "bash --version" without the quotes. This info would be helpful.



_________________
ArchLinux x86_64
Back to top
View user's profile Send private message
rumbarg
Jr. Member


Joined: 06 Jun 2024
Posts: 69
Location: Houston, TX

PostPosted: Fri Sep 26, 2024 3:21 pm    Post subject: Reply with quote

Didn't see this until just now - here's that informaion:

GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)

regards,
rumarg



_________________
sidux sidux 2024-01 - Χάος
Back to top
View user's profile Send private message
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Fri Sep 26, 2024 5:05 pm    Post subject: Reply with quote

hmmmm it works for me using Arch Linux...

Code:

export HISTCONTROL=erasedups
export HISTSIZE=10000
shopt -s histappend


Code:

[crouse@VistaCrusher ~]$ bash --version
GNU bash, version 3.2.39(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2024 Free Software Foundation, Inc.
[crouse@VistaCrusher ~]$


NOTE: this will not affect your PREVIOUS history.....only from that point forward..... edit your bashrc file and type "history" and you should get a long list..... try typing "history 3" "history" "history 2" etc etc adding in duplicates then type just history and you shouldn't have any of the duplicates you typed in...... from the point you added in the line to your bashrc file...... anything BEFORE that edit seems to stay. You "could" edit the file with sed/awk/bash and REMOVE those duplicates that way......but that's another post altogether Wink



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
orphius
New Member


Joined: 25 Sep 2024
Posts: 9

PostPosted: Fri Sep 26, 2024 7:43 pm    Post subject: Reply with quote

crouse. I will try it again, the way you show and let you know if it works. I am beginning to think it is somehow related to my version of linux.



_________________
ArchLinux x86_64
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse