How many times did someone give you the task “this system doesn’t have documentation, it had a failure and stopped and we don’t know how to put this system up again… help us!”?
It’s quite common when the knowledge management is not taken seriously inside the company and you have only weak documentation. The problem worsens when you have to handle legacy systems. Rely on me: i know what i’m telling you, so i give you my shoulder.
But calm down. If you have a terminal and you can access the machine where the system should be running, maybe we shall solve everything.
history
The history command really can save your life. It lists the last commands typed in the Linux terminal, by the current user.
So, in case you need access the list of commands typed by another user, please follow the sequence:
sudo su
su - user_who_typed_something_good
history
It’s suitable to say that when you type “su – user” you change the current user to user, but, more than that, you’ll be transported to his home directory with all of his environment variables and shell environment.
fc
It stands for “find command” and it will show you all the executed commands between two positions, like fc -l 100 200 that will show you the last commands between the positions 100 and 200.
Now, i think we know a lot about these commands and it’s time to dive deeply and see a practical case. Let’s say that the history command give us:

Unfortunately we had to scroll too much and we lost time (and eyes) doing that. If for example, we were looking for the occurrences of commands with the expression “fetch” we could, more wisely, use our famous grep command in order to pipe and filter the result of the history command:
history | grep fetch
Et voilà!
As of now, don’t forget: if you use an OS based in Linux, history and grep could save your life. Once upon a time, they saved mine.
By Igor Magalhães Oliveira
Leave a Reply