How to Create softlink with ln command on Linux

In Linux, a softlink, also known as a symbolic link, is a type of file that acts as a reference or shortcut to another file or directory. Softlinks are useful for organizing and accessing files and directories, especially when they are located in different directories or on different file systems. In this guide, we will show you how to create a softlink using the ln command on Linux.

Step 1: Navigate to the Directory

First, navigate to the directory where you want to create the softlink. You can use the cd command to change directories. For example, if you want to create a softlink to a file in your home directory, you can use the following command:

cd ~

This command will take you to your home directory.

See also  How to Mount CDROM Media on CentOS 5/CentOS 6/CentOS 7

Step 2: Create the Softlink

Once you are in the directory where you want to create the softlink, you can use the ln command to create it. The syntax of the ln command is as follows:

ln -s source_file_or_directory link_name

Here, source_file_or_directory is the path to the file or directory you want to link to, and link_name is the name of the softlink.

For example, if you want to create a softlink to a file called example.txt in your home directory and name the softlink mylink, you can use the following command:

ln -s ~/example.txt mylink

This command will create a softlink called mylink in the current directory that points to the example.txt file in your home directory.

See also  How to Install VMware Tools on CentOS 6.3

Step 3: Verify the Softlink

To verify that the softlink has been created successfully, you can use the ls command with the -l option to show the file details:

ls -l

This command will show a list of files in the current directory, including the softlink you just created. The output will look something like this:

lrwxrwxrwx  1 user user       12 Apr 13 14:30 mylink -> ~/example.txt

The first letter in the output, l, indicates that mylink is a softlink. The arrow symbol -> indicates that it points to the example.txt file in your home directory.

See also  How to Add Atomic Repository to RHEL 6

Another Example

[root@centos62 ~]# ln -s /public/index.html /home/howto/index.html

After creating the symbolic link above, /public/index.html will point to /home/howto/index.html.

Commands Mentioned:

  • cd – Change directory
  • ln -s – Create a softlink
  • ls -l – Show file details

Conclusion

In this guide, we have shown you how to create a softlink using the ln command on Linux. Softlinks are useful for creating shortcuts to files and directories and organizing your file system. By following these steps, you can create softlinks on your Linux system and access files and directories easily.

If you have any comments or suggestions for improvements, please feel free to share them below.

Comments

1 Comment

  • Avatar stephane says:

    Hi !

    I wanna add an external storage to my linux 6.4 centos server ( ZPANEL ), not really familiar with linux disk formats and how to move the public/html files…

    How do i move the public/html files ( website files ) to point to my external drive ?

    I will format the external drive in wich structure ? ( i Know that Linux has plenties… and not really really clear for me as i mostly used pc’s and mac’s in the last 20 years… )

Leave a Reply

Your email address will not be published. Required fields are marked *