Actions

Difference between revisions of "Create a Symlink"

From InfoTechPedia

(update)
(Create or Update a Symlink: updare)
Line 16: Line 16:
 
<pre>
 
<pre>
 
admin@server:~$ ln -sf /path/to/file /path/to/symlink
 
admin@server:~$ ln -sf /path/to/file /path/to/symlink
 +
</pre>
 +
 +
<pre>
 +
admin@server:~$ ln -sf /home/user/Upload/file.php /home/user/project/file.php
 +
</pre>
 +
 +
If you are in the directory you are linking, ex. <code>/project</code>, no need to give the absolute path.
 +
 +
<pre>
 +
admin@server:~/project$ ln -sf /home/user/Upload/file.php file.php
 
</pre>
 
</pre>
  

Revision as of 10:58, 10 March 2018

In computing, a symbolic link (also symlink or soft link) is a term for any file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution.[1]

The standard format is: ln -s absolute_path_source_file absolute_path_target_file

Create a New Symlink

To create a new symlink (will fail if symlink exists already):[2]

admin@server:~$ ln -s /home/server/a_directory/file.ext /home/server/public_html/file.ext

Create or Update a Symlink

To create or update a symlink:[2]

admin@server:~$ ln -sf /path/to/file /path/to/symlink
admin@server:~$ ln -sf /home/user/Upload/file.php /home/user/project/file.php

If you are in the directory you are linking, ex. /project, no need to give the absolute path.

admin@server:~/project$ ln -sf /home/user/Upload/file.php file.php

Output

This is an example of a directory listing using ls -la. Files and directories that are symlinked will show an arrow like this -> to indicate it is symlinked. See the output below.

admin@server:~/public_html/Upload$ ls -la
total 24
drwxr-xr-x  5 admin admin 4096 Feb 25 10:47 .
drwxr-x--- 24 admin admin 4096 Feb 25 04:02 ..
lrwxrwxrwx  1 admin admin   60 Feb 25 10:47 .bulk_file_upload.sh -> /home/admin/GitRepo/Upload/.bulk_file_upload.sh
lrwxrwxrwx  1 admin admin   49 Feb 25 10:46 .htaccess -> /home/admin/GitRepo/Upload/.htaccess
drwxr-xr-x  3 admin admin 4096 Feb  7 16:29 Images
lrwxrwxrwx  1 admin admin   50 Feb 25 10:46 .index.php -> /home/admin/GitRepo/Upload/.index.php
drwxr-xr-x  3 admin admin 4096 Feb  7 16:56 Saved_Images-> ../GitRepo/Upload/Saved_Images
lrwxrwxrwx  1 admin admin   51 Feb 25 10:46 .script.php -> /home/admin/GitRepo/Upload/.script.php
admin@server:~/public_html/Upload$

References