Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I redirect history to a file?

Tags:

command-line

Is it possible to put the output of a command into a file? I tried doing a

echo history > history.txt

But it put the text history instead into that file.

like image 830
Jürgen Paul Avatar asked Oct 19 '25 08:10

Jürgen Paul


2 Answers

Just do history > history.txt without the echo. That should do it. When you do echo history, you are telling unix to print history to screen rather then execute it, which is why echo history > history.txt only contains the word history.

like image 98
user1413793 Avatar answered Oct 22 '25 03:10

user1413793


The example as given is probably unnecessary unless you want unwritten history from the current session. Your ~/.bash_history or similar file will already have your history from past sessions saved.

You can append the current session's history with history -w. Then your ~/.bash_history file will be up-to-date, including items from the current session.

like image 33
Todd A. Jacobs Avatar answered Oct 22 '25 03:10

Todd A. Jacobs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!