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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With