TransWikia.com

How to create a desktop shortcut to a data file in Ubuntu 18.04.4 LTS?

Ask Ubuntu Asked by BlueSkies on November 9, 2021

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.

3 Answers

Besides symbolic links and custom launchers (i.e. application-type desktop files), there is another option, which is to use a link-type (type 2) desktop file with a file:// URL. The example-content package includes one; for your example, it would look like this:

[Desktop Entry]
Name=my-text-file.txt
Type=Link
URL=file:///home/my-user-name/Documents/my-text-file.txt
Icon=text-x-generic

(You will, of course, need to change my-user-name so that it matches the actual path of your home directory. The file:// URL scheme requires absolute paths.)

Name the file my-text-file.desktop (or anything else that ends with .desktop) and put it in ~/Desktop/. It will look like this:

Desktop showing Trash icon and link to my-text-file.txt

Double-clicking the shortcut will open the text file with your default text editor.

example text file open in Gedit

If you need to make any changes, you can edit the desktop file with a normal text editor. Just right-click and choose "Open With Other Application" and select your text editor of choice.

desktop file in Gedit

If you want a different icon, you can choose from many default options or provide a path to your image file of choice.

Answered by Nathaniel M. Beaver on November 9, 2021

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.

Answered by Jos on November 9, 2021

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

Answered by vanadium on November 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP