LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-19-2009, 12:33 PM   #1
emzvargas
LQ Newbie
 
Registered: May 2009
Posts: 2

Rep: Reputation: 0
how to store command history using HISTFILE in 2 locations?


Hello im trying to write a bash script, and i need to know how i can save in 2 different locations using HISTFILE command??

Please any help??
 
Old 05-19-2009, 01:38 PM   #2
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

HISTFILE is not a command but a shell variable. You can change the location by simply assigning it a new path:
Code:
HISTFILE=/path/to/new/histfile
Jan
 
Old 05-19-2009, 05:48 PM   #3
emzvargas
LQ Newbie
 
Registered: May 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanx for the info..i really apreciate the quick response... but what i want to do is to save in 2 different locations the history command..meaning i want to keep the bash_history intact but at the same time store it in another directory for other purposes.

Last edited by emzvargas; 05-19-2009 at 05:50 PM.
 
Old 05-20-2009, 01:08 PM   #4
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

I don't know a method to write the history in 2 files at the same time (the history is hold in memory until the shell exits).

If you want to save a copy of the history file, you should do that on shell's exit - look at the bash manual for the information about the .bash_logout file.

Other possibilities are to use the shell builtins fc and history to get and store the current history contents to a file. But you have to do it manually in your scripts or at the prompt (or you write a function which does it for you).

Look at the bash manual to get more information (sections "HISTORY" and "SHELL BUILTIN COMMANDS"). To reach these sections quickly, use the search within "man bash": Type "/^HISTORY" to instantly go to this section.

Jan
 
Old 05-21-2009, 06:33 AM   #5
fusion1275
Member
 
Registered: Jul 2007
Location: Knaphill, Surrey
Distribution: Linux Mint
Posts: 310

Rep: Reputation: 36
Not sure what your "other purposes" are but couldn't you just make a soft link to your secondary destination? Then you have 2 of the same.
 
Old 01-30-2015, 02:51 AM   #6
karkotagan
LQ Newbie
 
Registered: Jan 2015
Posts: 3

Rep: Reputation: Disabled
How do I copy the history from command line to a file

How to copy the history from the cli to a file
 
Old 01-30-2015, 03:48 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Off: saving history (own or others') might be a security hole as history files might contain classified information.
 
  


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
query on history command manoj.linux Linux - Enterprise 1 04-08-2009 05:38 AM
HISTFILE versus HISTFILESIZE calutateo Linux - Newbie 1 07-25-2005 08:55 AM
History command amer_58 Linux - General 5 06-24-2005 12:26 PM
Command history? King4lex Linux - Newbie 4 09-03-2004 08:35 PM
History command, How to get the date? philipina Linux - General 2 08-05-2004 05:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:28 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