LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-07-2012, 09:46 PM   #1
kevinx
LQ Newbie
 
Registered: Feb 2012
Location: Bangkok
Posts: 4

Rep: Reputation: Disabled
How to kill the Bash process without clearing the history?


I'm using Fedora and taking a Intro to Linux course. My teacher requests that we submit screen shots of our output so she can verify we are doing everything correctly. Sometimes, when the commands are long, or the information doesn't really stay on the page, she requests that we submit a screen shot of the history command.

Something is wrong, the history is gone, and she marked me off. She says the commands should be there. I've searched the internet, but can't really find anything that answers this.

Here's what's going on. I open the terminal and log in as root. I enter a few commands around displaying process (like, ps -eF | grep bash). Then I enter a series of kill commands, 3, 15, and 9.

Nothing seems to happen when I use 3 or 15 (I'm assuming they aren't "strong" enough to kill themselves , but when I enter the command "kill -9 PID", the current terminal closes, and I am logged back in as my user name.

All of this makes sense to me, except that when then I log back in to root and run a history command. Nothing I entered from the previous session is there. It only displays commands from previous sessions.

So, I have two questions. First, is the teacher wrong? and second, is it possible to kill the terminal with option 9 and retain the history?

Thanks,
Kevin
 
Old 02-07-2012, 09:59 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
history for the root user is stored separately from the normal user's history. If issuing commands as root, then run history command as root to see the root user's history.
 
Old 02-07-2012, 10:01 PM   #3
kevinx
LQ Newbie
 
Registered: Feb 2012
Location: Bangkok
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks bigrigdriver, but I am logging back in as root.
 
Old 02-07-2012, 10:12 PM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
My bad. Try adding this to your user's and root user's .bashrc:

Code:
# append to the history file, don't overwrite it
shopt -s histappend
 
Old 02-07-2012, 11:29 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
FWIW I actually use
Code:
shopt -s histappend
export PROMPT_COMMAND='history -a'
 
Old 02-08-2012, 02:29 AM   #6
kevinx
LQ Newbie
 
Registered: Feb 2012
Location: Bangkok
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for your replies. So I'm assuming that the command I was using is working correctly and that the teacher is having a brain fart or something. I'll have to look up what the command shopt does, but the rest I understand. Thanks again!
 
Old 02-08-2012, 04:01 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
kill -9 kills the named process immediately; if the process is a bash shell, it has no chance to flush its history buffer to the history file or anything else.

unSpawn's technique works because it flushes the history buffer to the history file every time bash generates a command prompt.

Last edited by catkin; 02-08-2012 at 04:01 AM. Reason: kilsl -> kills
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ominous text [ PROMPT_COMMAND='pwd>&8;kill -STOP $$'] in my bash history file. zapo Linux - Security 2 01-12-2011 01:28 AM
bash `kill`: process 'B' silently dies; but process 'A' = `kill` spews back debris! GrapefruiTgirl Programming 9 06-23-2009 09:42 AM
Clearing history AumDiar Linux - Newbie 7 01-03-2005 11:05 PM
how do i kill a process from inside a bash script? mikaelo Programming 4 05-28-2004 08:51 AM
BASH script inform user and kill process mounters Programming 3 02-11-2002 04:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration