Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I get a script to execute automatically when I log in? Not when the machine starts up, and not for all users, but only when I (or any specific user with the script) login via the GNOME UI.

From reading elsewhere I thought it was .bash_profile in my home directory, but for me it has no effect. When I manually execute it in a terminal window by typing ~/.bash_profile it works, but it won't run automatically when I log in.

I'm running Ubuntu 11.04. The file permission on my .bash_profile is -rwx------. No .bash_profile existed in my home directory before I created it today.

I seem to remember older versions of Linux having a .profile file for each user, but that doesn't work either.

How is it done? Do I need to configure something else to get the .bash_profile to work? Or does the per-user login script need to be in some other file?

share|improve this question
.bash_profile, .profile and .bashrc (Which is the one actually used by ubuntu) are loaded each time you open a bash terminal. So actually I'm not sure they will be loaded if you just login into GDM. – Juan Sebastian Totero Jun 20 '11 at 0:19
Posting your Ubuntu version might help. In Ubuntu 10.10 .bashrc "works for me (TM)." – Vlueboy Jun 20 '11 at 3:39
Do you mean when you log in to the GUI, or to the shell? – Flimzy Jun 20 '11 at 4:03
bash loads them when you start a new shell, so they will only get loaded when you open a terminal window or log into a virtual terminal, not when you log into Gnome (GDM). – shiftycow Jun 20 '11 at 4:24
I'm using Ubuntu 11.04, as I mentioned in the original question. – Mike Rowave Jun 20 '11 at 15:06
up vote 11 down vote accepted

You could simply add the following command into System > Preferences > Startup Applications:

bash /full/path/to/your/

That should do the trick ;)

share|improve this answer
You know what, I did that before and it didn't work ... except that I didn't write "bash" before the script's path! I'll try it with the bash later. Out of curiosity, when you enter something via the GUI into Startup Applications, in which file is it registered? – Mike Rowave Jun 20 '11 at 0:40
Startup programs should be registered in /etc/xdg/autostart – shiftycow Jun 20 '11 at 4:28
Adding bash /home/myusername/scriptname to "Startup Applications" worked! Thanks. However this might be specific to GNOME on Ubuntu, that's why I was wondering about where the entries in that "Startup Applications" menu item are registered, as that would be more likely to be similar in other modern versions of Linux. – Mike Rowave Jun 20 '11 at 15:05
/etc/xdg/autostart appears to be a system-wide file, not specific to a user. – Mike Rowave Jun 20 '11 at 15:09
For later versions of ubuntu see… – TooTone Oct 1 '13 at 12:09

So basically, as nodiscc suggested, create a desktop launcher: ~/.config/autostart/script.desktop with the following contents:

[Desktop Entry]
Name=Autostart Script

Then create the autostart script: ~/bin/autostart with your bash contents:

# Execute bash script below

Make sure that ~/bin/autostart is executable

share|improve this answer

You can add a line in crontab -

crontab -e

Then add this line to the file that opens up:

@reboot /path/to/your/cool/script

This will run the script at reboot. For more details see man crontab

share|improve this answer
I don't know why, but I can't execute .sh files on "start up applications" , therefore the easyest way to do it now, is cron – Albert Català May 18 at 16:27

Try ~/.xinitrc (some info here: ). Remember that anything you start in this script should be started / run in the background, or it could interfere with the X login.

share|improve this answer

Extending @JuanSebastianTotero answer.

Instead of:

bash /full/path/to/your/


sh /full/path/to/your/

bash didn't work for me on Ubuntu 13.04 and 14.04. But sh does.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .