Results 1 to 10 of 23
Hello!
When I'm in a terminal I can type history -c , and all the typed commands for a given user will be cleared.
Is it possible to do the ...
- 06-24-2009 #1Just Joined!
- Join Date
- Jun 2009
- Posts
- 44
[SOLVED] Clear history in bash
Hello!
When I'm in a terminal I can type history -c, and all the typed commands for a given user will be cleared.
Is it possible to do the same, using a bash script?
My code is:
#!/bin/bash
su -c "history -c"
But this doesn't seem to work.
When I execute the script, it does ask me form my root pass, but then nothing happens, since I can still access my old typed commands.
Ideas?
Thank you
PS: As you can see, I'm a Linux begginer.
- 06-24-2009 #2
If you logged in as "root" , you can omit "su -c" just try using plain
history -c (instead of "history -c" - I don't think you need to have double quotes .)
Little more info. history command takes input from file called ".bash_history"
it will be available on users home directory.
You can edit this file too likecat ~/.bash_history
will clear the data.cat /dev/null > ~/.bash_history
you can also set the history size in ~/.bashrc by placing the following lines
export HISTFILESIZE=0- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 06-24-2009 #3Just Joined!
- Join Date
- Jun 2009
- Posts
- 44
Hello Lakshmipathi.G
Thanks for the answer.
I'll try your suggestions (at this exact moment I'm on a WYNDOUZ machine).
Thank you
ADFC
- 06-24-2009 #4forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,095
Ditto what Lak said... either of the following commands work for me as root, or user:
Post back with any errors, should you get any.Code:history -c >~/.bash_history
oz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.
- 06-24-2009 #5Just Joined!
- Join Date
- Jun 2009
- Posts
- 44
Hello!
I'm using openSUSE 11.1 and Gnome (running gnome-terminal).
In the bash script, simply putting history -c doesn't work!
It does not return any error, but when the script finishes, I can still access my typed commands using the keyboard cursor (upper key).
If I try to execute ~/.bash_history in the terminal it returns:
bash: /home/user/.bash_history: Permission denied
If I try to execute >~/.bash_history in the terminal it does not return any error, but it doesn't do anything.
I can still access my typed commands using the keyboard cursor (upper key).
If I try to execute cat /dev/null > ~/.bash_history in the terminal it does not return any error, but it doesn't do anything.
I can still access my typed commands using the keyboard cursor (upper key).
I ran all of those commands as normal user (which is what I need
) in the gnome-terminal and not in bash mode for the moment.
Any more suggestions?
Thank you.
- 06-24-2009 #6forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,095
Try the history -c command again, then log out and right back in, and then see if your files changed.
oz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.
- 06-24-2009 #7Just Joined!
- Join Date
- Jun 2009
- Posts
- 44
No, it doesn't work in the bash script (after log-out and log-in).
It only works in terminal (manually typing the command and pressing enter).
I'm confused.
Ideas?
Hum... I tried in a different PC (with a Debian based distro) and I have the exact same problem!
Have you tried making the bash shell script yourself?
I'm probably doing something wrong, but what??
Thank you
- 06-24-2009 #8forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,095
Not sure what might be wrong, then. I always run history -c from the console and whenever I log into X the history file has been emptied and started again fresh, except for the startx command just issued to enter into graphics mode.
oz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.
- 06-24-2009 #9Just Joined!
- Join Date
- Jun 2009
- Posts
- 44
- 06-24-2009 #10forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,095
Ah, I'm with you now. No, I've not tried it in a script because I don't use the command that often and haven't needed a script. I thought you meant the command itself wasn't working. Sorry for any confusion.
oz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.



