This post here served as a guide at my attempt to force the gedit Text Editor to open a specific file each time I startup my computer. Here are the steps I took:

  1. Create a sample directory and sample text file via mkdir ~/sample && touch ~/sample/sample.txt.
  2. Add the gedit Text Editor to my startup applications via the GNOME Tweak Tool.
  3. Modify the gedit startup command via Startup Applications Preferences. Change the startup command from gedit %U to gedit ~/sample/sample.txt. I also eventually tried gedit "~/sample/sample.txt", which didn't work.
  4. Save, Close, Restart

Upon reboot, gedit Text Editor is automatically launched, but the file opened is "Untitled Document 1". Why isn't gedit opening "~/sample/sample.txt" as I commanded it to? As a test I issued the gedit ~/sample/sample.txt command into GNOME Terminal and it did open "sample.txt" in gedit, as you'd expect.

What's wrong with my process described above? Why isn't "sample.txt" loading upon each restart of my computer, instead of "Untitled Document 1".

  • Have you tried it without the ~ home shortcut? e.g. gedit /home/whatever/sample/sample.txt
    – codlord
    Nov 15, 2021 at 18:06
  • @mikewhatever but theoretically should my process (#1 - #4) work above? Is this possibly a bug in the Startup Applications Preferences program?
    – jophuh
    Nov 15, 2021 at 18:27
  • Just tested it both ways with full path, and it works. Might want to give it a delay of several seconds. Nov 15, 2021 at 18:41
  • @mikewhatever "give it a delay", so should I change the startup command to sleep 60 && gedit /home/jophuh/sample/sample.txt in the Startup Applications Preferences program for a one minute delay? Is that what you meant?
    – jophuh
    Nov 15, 2021 at 19:04
  • Yes, but more like sleep 5, unless you want to wait a minute. Nov 15, 2021 at 21:24

1 Answer 1


If you meant open a file when you log in, then you could use the "Startup Applications", choose add a program and on the command field you type gedit /path/to/file. You could also add the startup action via terminal by doing the following:

echo '[Desktop Entry]
Exec=gedit /path/to/file
Comment[en_US]=Opens file using gedit
Comment=Opens file using gedit
' > $HOME/.config/autostart/filegedit.desktop
chmod +x $HOME/.config/autostart/filegedit.desktop

This adds the action you want to do to the list of startup programs. Note: You should not be using "~" to point to your home directory when creating a script/program, instead use /home/username/

Your Answer

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

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