A technical troubleshooting blog about Oracle with other Databases & Cloud Technologies.

How to Create & Delete Symbolic Link (Symlink)?

2 min read

A symlink is a symbolic Linux/ UNIX is a special kind of file that points to another file on your machine/server, or a connected file system. It similar to a shortcut in WindowsOS.

Unlike a hard link, a symbolic link does not contain the data in the target file. It simply points to another entry somewhere in the file system. 

Symlinks can take two forms:

Soft links are similar to shortcuts, and can point to another file or directory in any file system.

Hard links are also shortcuts for files and folders, but a hard link cannot be created for a folder or file in a different file system. The Hard Link acts as a copy of the selected file. So even if the original file is deleted, the hard link to the file still contains the data for that file, so you can access the data.

Benefits of Symlink :

-- When creating links to files or directories on a different file system:
-- The links will have a different node and set of permissions compared to the original file or directory.
-- They typically occupy less space than the original.

How to Create a Symlink:

ln -s <path to the file/folder to be linked> <the path of the link to be created>
--Eg.

ln -s /path/to/file/to/be/linked symlink_name

ln is the link command.

The -s flag specifies that the link should be soft. -s can also be entered as -symbolic.

By default, ln command creates hard links. The next argument is path to the file (or folder) that you want to link. (That is, the file or folder you want to create a shortcut for.)

--Create symlinks for oracle user for sqlnet.ora, tnsnames.ora, listener.ora

[oracle@localhost ~]$ ln -s /u01/app/grid/19.0.0/gridhome_1/network/admin/tnsnames.ora /u01/app/oracle/database/19.0.0/dbhome_1/network/admin/tnsnames.ora

[oracle@localhost ~]$ ln -s /u01/app/grid/19.0.0/gridhome_1/network/admin/listener.ora /u01/app/oracle/database/19.0.0/dbhome_1/network/admin/listener.ora

[oracle@localhost ~]$ ln -s /u01/app/grid/19.0.0/gridhome_1/network/admin/sqlnet.ora /u01/app/oracle/database/19.0.0/dbhome_1/network/admin/sqlnet.ora
 
[oracle@localhost ~]$ ls -ltr 
	
	total 4
    -rw-r--r-- 1 oracle oinstall 1536 Feb 14  2018 shrept.lst
    drwxr-xr-x 2 oracle oinstall   64 Apr 17  2019 samples
    lrwxrwxrwx 1 oracle oinstall   58 Dec 28 05:27 tnsnames.ora -> /u01/app/grid/19.0.0/gridhome_1/network/admin/tnsnames.ora
    lrwxrwxrwx 1 oracle oinstall   58 Dec 28 05:27 listener.ora -> /u01/app/grid/19.0.0/gridhome_1/network/admin/listener.ora
    lrwxrwxrwx 1 oracle oinstall   56 Dec 28 05:27 sqlnet.ora -> /u01/app/grid/19.0.0/gridhome_1/network/admin/sqlnet.ora

How to Remove a Symlink:

Use either the unlink or rm commands to remove a symlink (symbolic link). If the command executes correctly, it displays no output.

rm /path/to/symlink
unlink /path/to/symlink

Hope it helped !! 🙂