3

Let's say I have a text file my-text-file.txt and the file is in the ~/Documents directory. How can I create a desktop shortcut to that file?

In other words, I want to have an icon on my desktop that by double-clicking on it will open and edit my-text-file.txt file located in the ~/Documents directory.

I"m running live Ubuntu USB with Persistent Storage, version 18.04.4 LTS.

4

Most text files are associated with a text file editor such as Gedit. This means that if you double click on such a file in the File Manager, the file will be opened in Gedit.

If that is the case in your system, you could enter this command:

ln -s ~/Documents/my-text-file.txt ~/Desktop/my-text-file.txt

It is called a symbolic link. This will give you an icon on the desktop which will, when clicked, open the file in your default text editor. It will still be the file in Documents though.

You can replace the second my-text-file.txt with anything you fancy: this only changes what it will say on your desktop. It doesn't even have to end in .txt.

| improve this answer | |
  • 1
    Far easier solution. Editors (gedit and nano) appear to preserve the link when saving to it - this was not always the case in former times. – vanadium Jun 4 at 14:53
  • I wonder - now that I've created a symbolic link (using ln -s target source), is it possible to add it to the Favorites section? – BlueSkies Jun 4 at 19:45
  • 2
    You can also create a symbolic link on the desktop using the GUI. Open the directory with the file in GNOME Files (formerly known as Nautilus), drag the file's icon over the desktop, press <ALT>, release the mouse button, and select "Link Here". Given that OP talks about "double-clicking", they might prefer this method. – Matthew Jun 5 at 0:42
  • 1
    @Matthew: Is it possible to remove a symbolic link on Desktop using GUI? – BlueSkies Jun 5 at 18:54
  • 1
    Yes, just right-click and select "Move to Rubbish Bin" (in the en_gb localization; other Englishes may vary). – Matthew Jun 6 at 1:41
3

Create a .desktop file, and include the following Exec= line:

Exec=xdg-open /path/to/your/document

This will yield a launcher that when started, will open your document with the default application registered for that file type.

You can also explicity provide an application, as in

Exec=evince "/home/myuser/Documents/My Document.pdf"

When placing the launcher on your desktop in Ubuntu, you first need to right-click it and indicate that you allow execution of the launcher.

The minimum you need for a working launcher is a file containing:

[Desktop Entry]
Name=[Name that will appear in the menu]
Exec=[command to execute]
Type=Application
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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