Tag Archives: ubuntu

How to run a command on Startup on Linux (works on CentOS & Ubuntu)

Hi there,

In this example I had a need to record boot up times in a file that i could access easily. To do so I decided to run a command on startup. This tutorial tool place on CentOS but the commands should also work on Ubuntu.

Step 1

Edit the rc.local file in vi by running:

sudo vi /etc/rc.local

Step 2

Add the following line to the file, update the home directory to represent your home directory.

  • Press i to go into insert mode
  • Enter the line:
    • echo “the computer booted up at” `date` >> /home/darren/bootup.log
  • Press ESC and then wq! and enter to save and quit the file.

Step 3

Give the executable  permission to the rc.local file by running the following command:

chmod +x /etc/rc.d/rc.local

Step 4

Reboot the system by running:

sudo init 6

Step 5

When the machine reboots run the following command to insure the file has been created and that there is content in the file:

cat /home/darren/bootup.log

A full video tutorial can be found here: