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.
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:
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
.Create a
.desktop
file, and include the followingExec=
line: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
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:
When you copy the file to
~/.local/share/applications
it will show up in your launcher as well.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. Theexample-content
package includes one; for your example, it would look like this:(You will, of course, need to change
my-user-name
so that it matches the actual path of your home directory. Thefile://
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:Double-clicking the shortcut will open the text file with your default text editor.
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.
If you want a different icon, you can choose from many default options or provide a path to your image file of choice.