Difference between revisions of "Create a Symlink"
From InfoTechPedia
TomHutchison (talk | contribs) (improving) |
TomHutchison (talk | contribs) (→Create or Update a Symlink: example heading) |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| + | 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.<ref>[http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 Pathname resolution].</ref> | ||
| + | |||
The standard format is: <code>ln -s absolute_path_source_file absolute_path_target_file</code> | The standard format is: <code>ln -s absolute_path_source_file absolute_path_target_file</code> | ||
| − | To create a new symlink (will fail if symlink exists already): | + | == Create a New Symlink == |
| + | To create a new symlink (will fail if symlink exists already):<ref name="stack">[https://stackoverflow.com/questions/1951742/how-to-symlink-a-file-in-linux Stackoverflow, How to Symlink a File]</ref> | ||
<pre> | <pre> | ||
| Line 7: | Line 10: | ||
</pre> | </pre> | ||
| − | To create or update a symlink: | + | == Create or Update a Symlink == |
| + | |||
| + | To create or update a symlink:<ref name="stack"></ref> | ||
<pre> | <pre> | ||
admin@server:~$ ln -sf /path/to/file /path/to/symlink | admin@server:~$ ln -sf /path/to/file /path/to/symlink | ||
</pre> | </pre> | ||
| + | |||
| + | == Example == | ||
| + | Real world example of what to do | ||
| + | <pre> | ||
| + | admin@server:~$ ln -sf /home/admin/Upload/file.php /home/admin/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/admin/Upload/file.php file.php | ||
| + | </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> | ||
| + | |||
| + | == References == | ||
| + | <references/> | ||
[[Category:Linux]] | [[Category:Linux]] | ||
Latest revision as of 11:59, 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
Example
Real world example of what to do
admin@server:~$ ln -sf /home/admin/Upload/file.php /home/admin/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/admin/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$
