:::: MENU ::::

Add a function in shell on Linux (make dmesg timestamps human readable)

  • Jan 22 / 2015
  • 0
Linux

Add a function in shell on Linux (make dmesg timestamps human readable)

You want to add a specific function on your shell which is not available in standard functions and you would like to be able to call it anywhere you want without the need to specify the script location? That’s quite easy to do, with some simple tricks 😉 !

We will here work with a simple example of a useful function:

When you are calling the dmesg command, you got a timestamp which is not human readable and it can be hard to align these logs with the logs of another application running on the server for example. We will create a function called dmesghr (for dmesg human readable) that will allow us to call exactly the same than the dmesg command but with a timestamp human readable.

First of all, we will create our function under our profile at the end of file ~/.bashrc after all the already existing declarations:

Once this done, we will reload the profile file and export our new function so we can use it anywhere:

Right now, we can call it directly from our shell and use it as a standard function:

Comments are closed.

Question ? Contact