How to Create Shortcuts in Linux – Symbolic Links

Table of Contents

Windows users are used to being able to create shortcuts to have fast access to their files and folders easily. This is especially useful when these are buried deep in their filesystem. This feature isn’t as obvious on most Linux systems as it is on Windows.

In this post, I’ll show you how to create a shortcut on a Unix-like operating system using a symlink.

Create Symlink in Linux

Terminal way (the link will appear in the folder the terminal points to):

ln -s <target file or folder> <link name - which can be a file or folder>

Example: I’ll create a shortcut to link the phpMyAdmin folder /usr/share/phpmyadmin to the root of the website folder /var/www/bonguides.me.

sudo ln -s /usr/share/phpmyadmin /var/www/bonguides.me

Check the link was created using ls command:

# ls -l /var/www/bonguides.me
-rw-r--r--.  1 nginx nginx   405 Feb  6  2020 index.php
-rw-r--r--.  1 nginx nginx 19915 Dec 31  2021 license.txt
lrwxrwxrwx   1 root  root     21 Nov  3 22:47 phpmyadmin -> /usr/share/phpmyadmin
-rw-r--r--.  1 nginx nginx  7389 Sep 16 18:27 readme.html
-rw-r--r--.  1 nginx nginx  7205 Sep 16 19:13 wp-activate.php
drwxr-xr-x.  9 nginx nginx  4096 Nov  1 20:06 wp-admin
-rw-r--r--.  1 nginx nginx   351 Feb  6  2020 wp-blog-header.php

Create Symlink in Linux using SCP

If you’re using a SCP tool like WinSCP, FileZilla…You can create a shortcut using GUI.

Note

In this post, I use WinSCP to connect to a Linux server.

1. Navigate to the destination directory and right click on the blank area then create a new Link.

How to Create Shortcuts in Linux - Symbolic Links

2. Enter the link’s name and the destination file/folder that the link will be point to:

How to Create Shortcuts in Linux - Symbolic Links

3. The shortcut/symlink was created in the destination directory, in my cases it’s created in /var/www/bonguides.me.

How to Create Shortcuts in Linux - Symbolic Links

Finally, if you click on the symlink, it’ll redirect you to the source directory. In my case, it redirects you to /usr/share/phpmyadmin.

How to Create Shortcuts in Linux - Symbolic Links

Remove Symbolic Links

To delete a symlink, invoke the rm command followed by the symbolic link name as an argument. On success, the command exits with zero and displays no output.

rm symlink_name

If the symbolic link points to a directory, do not append thetrailing slash at the end. Otherwise, you will get an error:

Note

If the name of the argument ends with /, the rm command assumes that the file is a directory. The error happens because, when used without the -d or -r option, rm cannot delete directories.

rm: cannot remove 'symlink_to_dir/': Is a directory
# rm /var/www/bonguides.me/phpmyadmin
rm: remove symbolic link ‘/var/www/bonguides.me/phpmyadmin’?

Leave a Comment

Required fields are marked *