export bash history to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting export bash history to file
# 1  
Old 05-05-2012
export bash history to file

Hi,
I want to export bash history to a file, I used the following command
Code:
 history > /home/administrator/bashHistory

But the exported file only contains commands with line number from 996 to the last one, How to export all the commands including commands before line 996?

Thanks a lot.
Roy987
# 2  
Old 05-06-2012
The man page for history says that using a negative number as the first parameter on the command line (e.g. -1000) will print the most recent (1000 in this example) lines. This isn't working with my version of bash.

Bash keeps it's history in the clear, so you should be able to run this command:

Code:
grep -v "^#" $HISTFILE >output-file

Hope this helps a bit.

EDIT:After some playing history 10000 printed my complete history (which is less than 10000 lines).

Last edited by agama; 05-06-2012 at 01:08 AM.. Reason: Additional info.
This User Gave Thanks to agama For This Post:
# 3  
Old 05-06-2012
Thanks a lot, this one
Code:
 grep -v "^#" $HISTFILE >output-file

works for me.
Although,
Code:
history 10000

still outputs most recent 1000 lines on my machine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

I have a backdoor in my OS X? This is what I found in my bash history

That's what appears at the beginning of my bash history (when you type "open .bash_history" in terminal) sudo -k export PS1="";sudo echo AUTHENTICATED;echo RETRY exit export PS1="" sudo echo AUTHENTICATED ; sudo -k ; echo AUTHENTIKILL ; echo PROCESSEDAUTHENTICATION sudo ls;sudo -k;exit;echo... (1 Reply)
Discussion started by: jonathansmith
1 Replies

2. UNIX for Dummies Questions & Answers

History to Another file [local user history , but root access]

Hi all, My need is : 1. To know who , when , which command used. 2. Local user should not delete this information. I mean , with an example , i can say i have a user user1 i need to give all the following permissions to user1, : a. A specific directory other than his home... (1 Reply)
Discussion started by: sriky86
1 Replies

3. UNIX for Advanced & Expert Users

History to Another file [local user history , but root access]

Hi all, My need is : 1. To know who , when , which command used. 2. Local user should not delete this information. I mean , with an example , i can say i have a user user1 i need to give all the following permissions to user1, : a. A specific directory other than his home... (3 Replies)
Discussion started by: linuxadmin
3 Replies

4. UNIX for Advanced & Expert Users

Bash script with export variables

Hi all guys, how you can read in thread title, I'm deploying a bash script in which I have to export some variables inside it. But (I think you know) the export command works only inside the script and so, on exit command, the variables aren't set like I set inside the script. Consequently in... (8 Replies)
Discussion started by: idro
8 Replies

5. Shell Programming and Scripting

bash mysql export to file

I'm trying to export a mysql query to a .csv file, right now I'm running a successful query like: us_id=`mysql -u $USER_NAME --password=$PASSWORD -D "databasename" \ -e "SELECT * \ FROM databasename.table \ WHERE somefield >0 AND otherfield ='$ctry' \ ORDER BY... (1 Reply)
Discussion started by: unclecameron
1 Replies

6. Shell Programming and Scripting

export not working in Bash shell

Hi Friends, I am presently migrating shell scripts writter in KSH to SH.I am stuck at this place and i am not able to find a work around:- Let the script name is x.sh Below are some of the codes in it... export abc=hello export abc=hi export abc=how When i am trying to compile the script ... (6 Replies)
Discussion started by: amit.behera
6 Replies

7. UNIX for Dummies Questions & Answers

AIX bash history recall

Is it possible to use the keyboard UP ARROW in place of k to recall history? If so, how/what do I need to do change terminal emulation, etc.? TIA, George (7 Replies)
Discussion started by: gwfay
7 Replies

8. UNIX for Dummies Questions & Answers

bash history - each session in different file

Hello How to configure, or where to have each session history in different file Example: someone is connecting as root and at this time is creating file in which we have history of executed command to server is connecting another user and is created another file with command executed by... (1 Reply)
Discussion started by: vikus
1 Replies

9. Shell Programming and Scripting

History for custom BASH function

Hello all, I have a bash function that opens Safari (I'm on OS X) with a specified argument. Here it is : function safari { #Safari bash function TLDS=( "http://www." ".com" ".org" ".net" ".gov" ".edu" ) if ; then open -a Safari ${TLDS}$2${TLDS} elif ; then open -a Safari... (0 Replies)
Discussion started by: inquen
0 Replies

10. Shell Programming and Scripting

Mimic bash history behavior

Does anyone know of a way to mimic the up arrow/down arrow type bash behavior within a shell script? Say I have a scripted menu, and would like to be able to up arrow to bring up the last X number of lines of user input? Thanks to anybody with a suggestion. :) (0 Replies)
Discussion started by: sysera
0 Replies
Login or Register to Ask a Question