How to Create a Symbolic Link on Ubuntu

29/12/2020
In Linux, there are lots of powerful features that can make the life a lot easier. Linking is one of them that can allow you to perform your tasks a lot faster and more efficiently. You did hear the name “symbolic link”, or more common “symlink”, right? It’s a feature that allows linking to a physical directory or file.

For servers, symlinking is very useful. Are you a Linux user? Then symlink can also help you a lot. All you have to do is be creative with it to lessen your workload.

Power of symlink

There are a lot of complex directories in the file system of Linux, right? Remembering all of them can be a real hassle. Moreover, when you want to work with a file/directory that’s deep within directories and sub-directories, the file path length becomes longer.

It’s especially a pain when working with CLI where you have to specify the file paths. Here comes the symlink to help.

For example, you want to access “/home/<username>/Downloads/a/b/c/d/e.txt” file. This is an easy demo, but surely typing the entire file length isn’t something you want to do often, right? With the power of symlink, you can dramatically reduce the file path to “/home/e.txt”.

Here, the symlink feature allows you create a virtual file at “/home/e.txt” that indicates to the “/home/<username>/Downloads/a/b/c/d/e.txt”. Whenever you ask for “/home/e.txt” file to manipulate, the system will work on the original file.

The same method goes for directories as well.

Today, let’s check out all how to create a symlink and have fun with it.

Creating Symlink

On all the Linux systems, there’s a tool “ln”. Don’t confuse with natural logarithm! “ln” follows the same structure of “cp” and “mv”. Learn more about copying file(s) and directories on Linux.

ln -s <source_file_directory> <link_file_directory>

For example, let’s create a symlink of “/home/viktor/Downloads” to “/Downloads”.

sudo ln -s /home/viktor/Downloads /Downloads

It’s time to verify the result. Note that you can easily verify the result with a command that works using that directory or file. For example,

cd /Downloads

I’m now inside “/Downloads” directory. It’s actually not a new directory. Instead, it’s a link to the original “/home/viktor/Downloads” folder.

Verify that both are the same –

cd /home/viktor/Downloads
ls
cd /Downloads
ls

See? Both of them are the same!

Let’s do the same with a file. I have already set a demo file “pimusic.txt” on “/home/viktor/Desktop”. Let’s link it as “PIMUSIC”.

sudo ln -s /home/viktor/Desktop/pimusic.txt PIMUSIC

Verify the result –

cat PIMUSIC

Creating permanent symlink

Note that the symlinks you create aren’t permanent. Whenever you reboot your system, you have to recreate the symlink again. To make them permanent, simply remove the “-s” flag. Note that it will create a HARD LINK.

sudo ln /home/viktor/Desktop/pimusic.txt PIMUSIC

Verify the result after rebooting the system –

cat PIMUSIC

Enjoy!

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to use Quota on Ubuntu

Quota is a built in feature of the Linux kernel used to set a limit of how much disk space a user or a group can use. Quota...
29/12/2020

How to Install MenuLibre – Ubuntu Menu Editor on Ubuntu, Linux Mint

MenuLibre is an advanced menu editor that provides modern features in a clean, easy-to-use interface. In a nutshell, it enables...
28/12/2020

How to install Syncthing – Continuous File Synchronization on Ubuntu

Syncthing is a continuous file synchronization open source software, that synchronizes files between two or more computers...
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua proxy v4 chạy socks5 để chơi game an toàn, tốc độ cao ở đâu?
18/05/2024

Thuê mua proxy Telegram trọn gói, tốc độ cao, giá siêu hời
18/05/2024

Thuê mua proxy Viettel ở đâu uy tín, chất lượng và giá tốt? 
14/05/2024

Dịch vụ thuê mua proxy US UK uy tín, chất lượng số #1
13/05/2024

Thuê mua proxy Việt Nam: Báo giá & các thông tin MỚI NHẤT
13/05/2024