• We did not send an email asking for donations - please read this post.

Way to append command line history to text file?

R

red

Guest
I use command line a lot (as I'm sure most of you do too). I was just wondering if there was a way I could take, for example, the last 100 commands (like you do with the UP arrow) I did and place them into a text file for later reference.

The reason I would like to do this is since I'm new to Linux, I'll be testing something on a VM and I would like to print out this file and make notes of where a certain string of commands did something I liked, or didn't like.
 


OP
G

grim76

Guest
In your /home/<username> look for a file .bash_history (Provided that is the shell you are using) that should contain the list of commands that have been issued. There is also the command history that will spit out the entire list.
 
OP
R

Rob

Guest
Sure..

[xcode=bash]
history > mycommands.txt
[/xcode]

Or.. last 100:
[xcode=bash]
history|tail -n 100 > mylast100commands.txt
[/xcode]
 
OP
H

hackinjack

Guest
Further to other answers, if you also want to know what time the commands were entered at, you can use:


Code:
HISTTIMEFORMAT="%d.%m.%y %T " history | tail  -100
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation


Top