Actions

Difference between revisions of "Create a Symlink"

From InfoTechPedia

(improving)
(additional text)
Line 11: Line 11:
 
<pre>
 
<pre>
 
admin@server:~$ ln -sf /path/to/file /path/to/symlink
 
admin@server:~$ ln -sf /path/to/file /path/to/symlink
 +
</pre>
 +
 +
== Output ==
 +
This is an example of a directory listing using <code>ls -la</code>. Files and directories that are symlinked will show an arrow like this <code>-></code> to indicate it is symlinked. See the output below.
 +
 +
<pre>
 +
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$
 
</pre>
 
</pre>
  
 
[[Category:Linux]]
 
[[Category:Linux]]

Revision as of 23:44, 25 February 2018

The standard format is: ln -s absolute_path_source_file absolute_path_target_file

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

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

To create or update a symlink:

admin@server:~$ ln -sf /path/to/file /path/to/symlink

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$