5
How to back-up an active session’s command history without closing IDL
Background Information:
The Command History in IDL tracks the recent commands you've entered in the IDL Console. It's a handy tool for reviewing, reusing, or editing past commands without having to retype them. Just use the up and down arrow keys to sift through prior commands. In the IDL Workbench, the Command History can also be viewed in a tab to the right of the Console. You can read more about IDL’s Command History functionality HERE.

Problem:
While IDL is running, recent commands are stored in the command recall buffer (i.e. in system memory). When IDL closes, those commands are written to disk into a user specific text file within your .idl directory:
- Windows: C:\Users\YourUsername\.idl\idl\rbuf\history
- Mac OS: /Users/YourUsername/.idl/idl/rbuf/history
- Linux: /home/yourusername/.idl/idl/rbuf/history
Subsequent IDL invocations read this history file to initialize their buffer.
However, it's important to note that IDL only writes the contents of its command recall buffer to this history file when IDL closes gracefully. Thus, if the IDL session unexpectedly terminates, whether it be an IDL crash or a system shutdown or power outage, any commands entered in that session will be lost.
Work-around:
Unfortunately, there isn't really a way to force IDL to write the contents of the command history buffer into the history file on demand while the session is actively running.
However, you can use the RECALL_COMMANDS function to manually save the contents of the session's active command buffer to a (separate) file through a custom routine. Perhaps something like this:
PRO exportCommandHistory
fName = 'command_history.pro'
OPENW,unit,fName,/GET_LUN
PRINTF,unit,RECALL_COMMANDS(),FORMAT='(a)'
FREE_LUN,unit
PRINT, 'Command History Saved to File: '+fName
END
WARNING: Do not try to overwrite the default IDL command history file inside of the .idl folder using this method. This will not work and may cause your existing command history to be lost or corrupted.
To automatically and periodically save the contents of the command history buffer to a file while IDL is running, this can all be set it up inside of an asynchronous TIMER block. Something like this:
PRO exportCommandHistory, id, userData
fName = 'command_history.pro'
OPENW,unit,fName,/GET_LUN
PRINTF,unit,RECALL_COMMANDS(),FORMAT='(a)'
FREE_LUN,unit
PRINT, 'Command History Saved to File: '+fName
END
id = TIMER.Set(300, 'exportCommandHistory',/REPEAT) ;command history exported to file every 5 minutes (300 sec)
Finally, to configure the history-saving TIMER to run in the background every time IDL is launched, add that single timer command into your IDL startup script and make sure the "exportCommandHistory" routine is on your IDL search path.
HELPFUL TIP: Naming the output file with a .pro filename extension allows the file to be opened in the IDL Workbench. With this file open in the editor, selected commands can be executed directly (highlight, right-click, "Run Selected Text"). Also, if the file's contents are periodically updated by the TIMER, the Workbench editor will prompt you to refresh the content displayed whenever focus is returned to that editor window.
NOTE: While this work-around does archive your history of IDL commands entered in the active session, the created file on disk will not function like a true command history file. You won’t be able to bring up its contents into the IDL Console in any manner. It’s more for referencing and manually copying/pasting past commands if needed.
Created by BC-US (7/9/2025), Reviewed by JU (7/9/2025)