List of recent commands on Octave console
In this lesson, I'll walk you through the steps to view the historical list of operations you've performed on the Octave console.
Display command history in Octave
If you're on the console, type the command history and press enter:
>> history
This command displays a chronological list of all commands executed on the Octave console.
This is a FIFO (First Input First Output) list. Therefore, the most recent commands are located at the bottom of the list.
The list could be very long as it includes all sessions and not just the current one.
Note. This is also an advantage because it allows you to see the commands typed in previous sessions.
Display only the most recent commands
To view only the commands that have been recently typed, enter the "history" command followed by the number of the last operations you want to display.
For example, to view the last ten operations, enter history 10
>> history 10
This way you can display only the most recent commands.
Note. The "history" command displays a numbered list of previous commands executed in Octave. However, this can become problematic if you want to copy and paste commands to execute them again. In the next paragraph, I will explain how to remove the numbering.
Hide command numbers in list view
To avoid adding numbers to the command list, add the -q parameter.
>> history 10 -q
Alternatively, you can use this syntax:
>> history("10","-q")
In both cases, the output result is an unordered list of the last ten operations.
What's the purpose of the unordered list? The list of commands without numbers allows you to copy and paste it, re-execute it, or insert it into a script.
Clear command history
To clear command history, add the -c option to the history command
>> history -c
Executing this command will reset the command history list to zero.
Save command history to a file
To write the command history to a file instead of displaying it on the screen, use the -w parameter
>> history -w nomefile
This command writes the list of commands to the specified text file (filename).