By default the "history" command displays only the command order number and the command used, for example:
history 478 bundle exec jekyll serves 479 tar Jxvf icons-freebsd.tar.xz 480 ssh [email protected] 481 emerge -s thumbnailer 482 etc-update –automode -5
To execute a history command, simply use an 'exclamation mark' ! and the command number, example: ! 480, the shell will execute the corresponding number command.
Sometimes you run a command and forget the syntax to make it run, so you have to look in history. To facilitate this "search", you can customize your history adding, for example, date and time in the execution of commands.
There is an environment variable that the HISTTIMEFORMAT , if you add a specific format to it, in this case for date and time, your history save the history of the commands with date and time.
For example, copy and paste this content into your terminal and then run the command history, check that the output of the commands now have a date and time, however, they will all be the same, because you didn't have it before and are only using the tty you are, so that if you close and reopen the terminal the settings will be lost.
For this format to record the date and time of command execution from then on, and without getting lost when closing the terminal, add it to your .bashrc:
echo 'export HISTTIMEFORMAT = "% d /% m /% y% T"' >> ~ / .bashrc
From then on your command history will be recorded the date and time of execution! Learn more by running the commands:
man 3 strftime
If you don't know much about Shell Script yet and are looking for an effective way to learn from scratch? Or maybe you already have shell knowledge but want to evolve and learn how to create manuals, processes, games, animations, installers and more?
See you next time and good studies! _____________________________________________________________________________ See any errors or would you like to add any suggestions to this article? Collaborate, click here.