How to create and delete a symlink?

Optimizing and customizing your VPS/Dedicated server

How to create and delete a symlink?

Postby Mark » Wed Dec 23, 2009 2:41 pm

=>I] How to create symlink :=>
# cd /
# ln -s /home/user/example example
You would be creating a symbolic link called "example" in the root directory, and it would be a reference to the /home/user/example file.

To see this, you would:
# cd /
# ls -l

And the ls output would show you the standard directory listing with symbolic links maked with arrows, like this:
lrwxrwxrwx 1 user user 13 Aug 30 2006 example -> ../home/user/example
-----------------------------------------------------------
II] How to delete a symlink?
You can delete either by rm command or unlink command :
$ unlink symbolic_link
or
$ rm symbolic_link

NOTE :
When using the rm or unlink command to remove a symbolic link to a directory, make sure you don't end the target with a / character because it will create an error. Example:

$ mkdir dirfoo
$ ln -s dirfoo lnfoo
$ rm lnfoo/
rm cannot remove directory ‘lnfoo/’ : Is a directory
$ unlink lnfoo/
unlink: cannot unlink ‘lnfoo/’: Not a directory
$ unlink lnfoo
$
Mark
 
Posts: 124
Joined: Fri Dec 11, 2009 2:18 pm

Return to Configuring VPS/Dedicated servers

Who is online

Users browsing this forum: No registered users and 1 guest

cron