Recording the commands that you work on the Linux command line can be beneficial for two crucial reasons. For one, the taped commands provide a method to evaluate your command line activity, which is very useful if something didn’t work as expected and you need to take a more detailed look. In addition, recording commands can make it simple to duplicate the commands or to turn them into scripts or aliases for long-lasting reuse. This post takes a look at 2 ways that you can quickly tape-record and recycle commands.Command history The history
command makes it very easy to tape-record commands that you enter upon the command line due to the fact that it occurs automatically. The only thing you might wish to check is the setting that identifies how many commands are retained and, for that reason, for how long they’re going to remain around for seeing and reusing. The command below will show your command history buffer size. If it’s 1,000 like that shown, it will maintain the last 1,000 commands that you entered.
$ echo $HISTSIZE 1000
The history command below programs the most recent 2 commands that were run. Because the list ends with command number 1013, it will have started with 14.
$ history|tail -2 1012 05/04/ 23 14:26:11 vi myfile 1013 05/04/ 23 14:28:30 history|tail -2
When you first open a session on the command line, the oldest commands in your history buffer will be numbered 1 and 2. Earliest commands are shown first.
$ history|head -2 1 04/03/ 23 11:35:11 vi getdocs 2 04/03/ 23 11:35:30 getdocs
Passing the output of the history command to more will scroll through your taped commands a screenful at a time.
To avoid conserving all of your commands in your command history buffer, you can utilize the HISTSIGNORE variable. I utilize one like this to avoid saving commands that I do not want to preserve, leaving more space for those I do.
$ grep HISTIGNORE ~/. bashrc HISTIGNORE=”pwd: clear: cd: ls: man: history”
Reusing commands from your history buffer
Any command in the history buffer can be rerun by entering its command number following an exclamation point (e.g.,! 927). Commands will retain their history command numbers throughout a single login session.You can also use your up arrow key to support over any variety of current commands. When you reach the one that you wish to rerun, push the get in key and it will be run again. Using the script command The script
command offers a way to record as lots of commands as you want” on the fly “. To put it simply, type”script “and each command that you get in will instantly be saved in a file. The file will be called “typescript “unless you offer it a various name by including it to the command like this:$script script11 If you wish to add the commands you are preparing to get in and their output to an existing output file, you can use the-a (append) option to your script command. Here’s an example:$ script -a script11
Extra details about the script command
The script command will run your.bashrc start-up file when you start your command recording. It will conserve the commands you go into along with the output created by them. The file utilized to save entered commands will not be offered perform consent. If you want to turn the commands into a script, you can set that up after eliminating …