1

I want to create a shortcut on my desktop from a txt file. How can I do that? I use Ubuntu 19.10. Thanks.

Niklas

Niklas
  • 21
  • 3

4 Answers4

1

Let's assume that your file's path is : /home/username/folder1/file.txt and you want to create a Desktop shortcut for that file.
You need to open the terminal and run the following command:

ln -s <absolute_path_of_the_file> <shortcut_path>

So in this example, it will be:

ln -s /home/username/folder1/file.txt /home/username/Desktop/

Don't forget to include the absolute path of the file, otherwise the shortcut will be broken.

singrium
  • 7,320
1

I found it too hard to create a shortcut via ubuntu, so I wrote a shell script myself. To insert this bash script into the bin dir, follow these steps: First, open the terminal. To enable desktop icons, the gnome tweak tool has to be installed first:

sudo apt-get install gnome-tweak-tool gnome-tweaks

In there, search for "icon", then go on Desktop and enable the option called "Desktop Symbols" Since aptitude is needed, if you don't have it already installed, install it via the terminal:

sudo apt-get install aptitude

Navigate to the Desktop via cd command in terminal Create a new file:

touch createshortcut.run

Open the newly created file in a text editor and copy the sourcecode of "createshortcut.run" into there. Then move file to /usr/bin with:

sudo mv createshortcut.run /usr/bin/createshortcut

Make the file executable:

sudo chmod +x /usr/bin/createshortcut

Everything is done so far!

To create shortcuts in .desktop format you just have to execute createshortcut when navigated in the desktop folder in the terminal (this can be done via the cd command or right-click on desktop -> "open terminal here") and follow the steps!

createshortcut.run:

#!/bin/bash
#set no results to false
nores=false
#get the name of the file to string
echo "Please enter the desired app name:"
read NAME
#empty line for overview
printf '\n'
#search for the name to get a package
echo "Packages found for ${NAME}:"
#search via aptitude
firstout=$(aptitude search '~i!~M '${NAME}'')
#get if the command returned empty string, if is so, search without the only user installed tag
if [[ $firstout ]]; then
    #successfully, echo
    echo $firstout
else
    #search without these tags
    secout=$(aptitude search ''${NAME}'')
    if [[ $secout ]]; then
        #echo the results
        echo $secout
    else
        echo "No results"
        #no res is true now
        nores=true
    fi
fi
#empty line for overview
printf '\n'
#chose one of them
echo "Enter one of the package names above"
echo "i.e. google-chrome-stable"
echo "If no result is shown, just enter the app name in lower case letters"
#get the command and icon to string
read COMM
#empty line for overview
printf '\n'
#if no result has been found, enter here path to an icon file
IMGP=${COMM}
if [ "$nores" = true ] ; then
    echo "Please download an icon of the app and insert it in the folder /home/${USER}/icons"
    echo "and enter the file's name"
    echo "i.e. spotify.png"
    #new empty line
    printf "\n"
    #create new direcory
    mkdir /home/${USER}/icons
    #list files in spotify
    echo "All files in icons:"
    ls /home/${USER}/icons
    #read the image name
    read IMGPL
    #set imgp to new value
    IMGP="/home/"${USER}"/icons/"${IMGPL}
fi
#set file name
FNAME=${NAME}.desktop
#create the new file
touch ${FNAME}
#write a desktop entry to the file
echo [Desktop Entry] >> ${FNAME}
echo Name=${NAME} >> ${FNAME}
echo Exec=${COMM} >> ${FNAME}
echo Icon=${IMGP} >> ${FNAME}
echo Type=Application >> ${FNAME}
echo "Categories=GTK;GNOME;" >> ${FNAME}
#file has been written
#now make the file executable with sudo
chmod +x ${FNAME}
#empty line for overview
printf '\n'
#last steps for the user
echo "Created new desktop shortcut for ${NAME}"
echo "Now right click ${FNAME} on the desktop and select:"
echo "Allow execution"
echo "Now your shortcut should be executable"

(on github)

larsaars
  • 111
0

Create link to file on Desktop or in Folder

use Nautilus, power key, files, the blue filing cabinet icon.

drag the file to desktoop holding down the alt key

release mouse key, choose link here.

pierrely
  • 725
0

One alternative is to have shortcuts directory on the desktop.

Moving a file from any other directory to the shortcuts directory is achieved by holding the Alt key. This gives one the option to move, copy or link the file that is being moved.

One issue with this is that one has to go right click on the shortcut and choose the software which will open the file.