Hi all hope you are well.
I am interested in a quick method (besides cut 'n' paste) of extracting my command history from a putty session (Linux version Red Hat Enterprise Linux ES release 3 (Taroon Update 9)) to a windows text file. Any ideas on that? Thanks for your time.

Dani AI

Generated

A few reliable ways to get your shell history into a Windows .txt without manual copy/paste. This builds on ’s suggestion to write the history out and on ’s quick in-shell redirect, and gives more robust, repeatable options that capture the current session and avoid lost lines.

First, flush the in-memory session history to disk and copy that file to Windows. Bash keeps recent commands in memory and may not save them to the history file until the session ends, so force a write and copy the result:

history -a
cp "$HISTFILE" /tmp/session-history.txt

Then download /tmp/session-history.txt from the server to Windows with a tool such as PuTTY’s pscp or a GUI like WinSCP.

Second, let PuTTY save everything locally. Before connecting, open PuTTY configuration → Session → Logging and choose “All session output” and a local filename. Everything printed in the terminal will be recorded to that Windows file — handy when you want a transcript without touching the remote host.

Third, capture the whole interactive session on the server with the standard recorder and then fetch that file:

script -q /tmp/full-session.log
# run commands...
exit

Copy /tmp/full-session.log to Windows the same way you would copy any remote file.

Quick tips: to avoid history overwrites when you use multiple shells, enable append mode (so remote sessions don’t clobber each other):

shopt -s histappend

And to add timestamps before saving, set a time format:

export HISTTIMEFORMAT="%F %T "

These approaches let you choose whether to export just the command list or the full terminal transcript, and they avoid manual selection errors.

Recommended Answers

All 5 Replies

Well, wherever your history log is stored, just use echo "whateverthehistoryis" > "XXX.txt" Or find the history log and copy and paste the file into a new directory.

commented: Thanks for the help will try it tomorrow! +2

That simple ? lol Thanks a lot for your response, very helpful!

Even better try this:

echo |history > history.txt

Yeah, I was stating that echo something > file.txt would do that.

oh I didnt realise you meant with the pipe!lol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.