Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I want to make a .desktop file like described here.

[Desktop Entry]
Name=Sublime Text 2
GenericName=Sublime Text 2
Comment=Edit text files
Exec=/home/user/opt/sublime/Sublime Text 2/sublime_text %U

However, running that from Nautilus's context menu using Open with this gives me

Could not find '/home/user/opt/sublime/Sublime'

So I tried

Exec="/home/user/opt/sublime/Sublime Text 2/sublime_text" %U

and got

Text ended before matching quote was found for ". (The text was '"/home/user/opt/sublime/Sublime')

What is the correct way to escape spaces in the Exec line of .desktop files?

share|improve this question

Precede each space by a backslash:

[Desktop Entry]
Name=Sublime Text 2
GenericName=Sublime Text 2
Comment=Edit text files
Exec=/home/user/opt/sublime/Sublime\ Text\ 2/sublime_text %U
share|improve this answer
That does not work: Text ended just after a '\' character. (The text was '/home/user/opt/sublime/Sublime\') – nh2 Sep 18 '12 at 21:11
Funny, it works for me. – January Sep 18 '12 at 21:17
Do we use the same versions? GNOME nautilus 3.4.2 on 12.04. – nh2 Sep 19 '12 at 12:45

I was having exactly the same problem! After trying various escaping/quoting patterns, I decided the simplest solution was to have a symbolic link to sublime_text on my $PATH (or you could use a command-line alias).

[Desktop Entry]
Icon[C]=/usr/share/Sublime Text 2/Icon/256x256/sublime_text.png
Name[C]=Sublime Text 2
Exec=Sublime-Text-2 %U
Comment[C]=Text Editor
Name=Sublime Text 2
Comment=Text Editor
Icon=/usr/share/Sublime Text 2/Icon/256x256/sublime_text.png
share|improve this answer
This is a sensible workaround, but we still don't know how we are meant to use spaces in .desktop files. – nh2 Jan 23 '13 at 17:34
Agreed, although to me it just seems buggy in the way Exec is parsed, rather than us implementing incorrectly. It interprets a space as the end of the value, which is odd, since you can use unescaped spaces / unquoted strings for paths in the other properties! – c24w Jan 24 '13 at 11:39

I've got the same problem when following installation instructions from ( site.. So my solution was:

  1. Remove/delete the soft link called "sublime" from /usr/bin

  2. Remove all whitespaces of "Sublime Text 2" folder by renaming it to "SublimeText2"

  3. Re Create a soft link in /usr/bin/:

    sudo ln -s /opt/SublimeText2/sublime_text /usr/bin/sublime
  4. Make the .desktop file including:

    Exec=/opt/SublimeText2/sublime_text %U
share|improve this answer

Have you tried using ' ' quotes instead of " " quotes? I have a customised .desktop file with spaces in the Exec line, and mine works with ' ' quotes.

share|improve this answer

I ran into the same problem using GNOME nautilus 3.4.2 in Ubuntu 12.04. I found this alternative workaround in a bug report for the same issue in Moblin UI Framework which I prefer to the one mentioned where you need to add every single folder to the $PATH.

The workaround is simply:
"Create a symbolic link in a path that does not have spaces, and point the EXEC field to that link."

share|improve this answer

For detailed explanations howto escape from some desktop file arguments, click here!

share|improve this answer
Please give a gist of the solution here. – i08in Nov 12 '13 at 5:39
Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Eric Carvalho Nov 12 '13 at 9:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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