I have added a command in .bashrc to run a script at startup of my Raspberry Pi, but everytime I open a new terminal the same script executes again.

Is there any way I can make this script run only on startup / power up and not each time I open a new terminal?

  • Use a cron job and the @reboot option (man cron, man 5 crontab).
    – joan
    Feb 28, 2016 at 11:42
  • @joan Can you please provide an answer with a few more details? I'm not sure what a cron job actually is. Feb 28, 2016 at 11:44
  • @joan's answer is correct. bashrc is a configuration file for the bash shell, which means it gets called every time a bash terminal is started.
    – Jacobm001
    Feb 28, 2016 at 22:51

1 Answer 1


You can use a cron job.

Cron is used when you want to schedule jobs to run at specific times, e.g. every hour, every Sunday at 3 a.m. It stores the details in a table for each user called a crontab which is read during boot.

One of the "times" you can specify is at a reboot.

To list your crontab use the command

crontab -l

To edit/create your crontab use the command

crontab -e

On occasion you might want to run a script as root in which case precede the previous two commands with sudo.

Use the following commands for help

man cron
man -5 crontab

In your case you need a simple job like I use to mount a NFS disk at boot. My crontab contains the following:

@reboot              (sleep 60; /bin/mount /code)&

You need to use crontab -e and add the following to your crontab

@reboot              /home/pi/script

where /home/pi/script is the full path to the script you want to run.

  • Can you specify it to run every time it boots instead of only at a reboot? Jan 1, 2017 at 2:05
  • @reboot means when the Linux system is started (usually from power-up). What distinction are you making?
    – joan
    Jan 1, 2017 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.