What command is used to create a symbolic link/soft link?
7 Answers
┌── ln(1) link, ln -- make links │ ┌── Create a symbolic link. │ │ ┌── the optional path to the intended symlink │ │ │ if omitted, symlink is in . named as destination │ │ │ can use . or ~ or other relative paths │ │ ┌─────┴────────┐ ln -s /path/to/original /path/to/symlink └───────┬───────┘ └── the path to the original file/folder can use . or ~ or other relative paths $ echo content > original $ ln -s original symlink $ ls -la original symlink -rw-r--r-- 1 grgarside staff 8 28 Jan 18:44 original lrwxr-xr-x 1 grgarside staff 8 28 Jan 18:44 symlink -> original $ cat symlink content For more information about ln(1) see the man page:
$ man ln The path to the symlink is optional; if omitted, ln defaults to making a link with the same name as the destination, in the current directory:
$ cd ~/Documents $ ln -s ../Pictures $ ls -l Pictures lrwxr-xr-x 1 user staff 11 Feb 1 17:05 Pictures -> ../Pictures To create a symlink to replace a system directory (e.g. if you want to have /Users pointing to another disk drive), you need to disable System Integrity Protection. You can re-enable it after the symlink is set up.
- 93If only man pages were as clear as your answer!Adrian Lynch– Adrian Lynch2016-01-27 07:00:04 +00:00Commented Jan 27, 2016 at 7:00
- If only man page writers had thought to use the term "original"! Just like everything in life, the original always comes first.jschmitter– jschmitter2023-10-16 19:22:59 +00:00Commented Oct 16, 2023 at 19:22
The command is called ln. If used with the option -s it will create a symbolic link in the current directory:
ln -s /any/file/on/the/disk linked-file If you want to overwrite an already existing target (linked-file), use
ln -Fs /any/file/on/the/disk linked-file I know this question is explicitly asking about the Terminal, but if you're in GUI Land and don't want to enter Terminal Land, you can use SymbolicLinker. This puts a "Make Symbolic Link" option in your Services menu in Finder.
- 4I'd love to know why this was downvoted so I can make higher-quality answers from now on :)Ky -– Ky -2016-04-27 22:43:47 +00:00Commented Apr 27, 2016 at 22:43
- 16probably because the question was "How can I create a symbolic link in Terminal?" But I am not downvoting you :)vedrano– vedrano2016-04-29 14:55:43 +00:00Commented Apr 29, 2016 at 14:55
- 2@EdwardFalk I think in El Capitan, you can hold
Command+Optionwhile dragging a file... will update the answer laterKy -– Ky -2016-11-09 14:27:14 +00:00Commented Nov 9, 2016 at 14:27 - 5@BenLeggiero That makes an alias.Andy Stewart– Andy Stewart2016-12-29 15:11:18 +00:00Commented Dec 29, 2016 at 15:11
- 3@BenLeggerio, The difference is explained here: apple.stackexchange.com/questions/2991/…MiB– MiB2017-02-25 03:25:28 +00:00Commented Feb 25, 2017 at 3:25
ln -s /some/dir/ ~/Desktop/dir
You can also create a symlink for directory using the same command
ln -s "$(pwd)" ~/Desktop/dir
To create symlink to current directory you are in.
- 4A simple
.(dot) will give the pwd. No fancy arguments needed :)mylogon– mylogon2018-04-20 19:37:22 +00:00Commented Apr 20, 2018 at 19:37 - @mylogon hahaha i like to overthink sometimes. simplified my answer!Gerald– Gerald2018-06-17 08:23:32 +00:00Commented Jun 17, 2018 at 8:23
- @mylogon i just realised that
.doesnt work on macOS. didnt try on linux yet. using./resulted in thisfoo -> ./foowhich points to itself.Gerald– Gerald2018-07-12 06:10:24 +00:00Commented Jul 12, 2018 at 6:10 - What is the full command you typed out?mylogon– mylogon2018-07-12 06:20:30 +00:00Commented Jul 12, 2018 at 6:20
Unless the source path is relative to your destination, use an absolute path to your source path, and put it in single quotes
$ ln -s '/any file/could have (special chars)/or spaces/test' '/some/other place/file' You can always figure out the current full unescaped path to something by going to that folder in the terminal, then typing
$ pwd As a heads up to anyone, you must use full path names. This wasn't immediately clear to me, as I felt I could symlink relative paths in a folder that I was running the command inside. I could be wrong (I'm a macOS novice).
For example, if I try to symlink my Pictures folder inside of my Downloads folder, while cd'd in my user home directory, this will not work:
Users\stevebauman >_ ln -s Pictures Downloads Instead, you must use:
Users\stevebauman >_ ln -s /Users/stevebauman/Pictures /Users/stevebauman/Downloads - 2Not exactly - the link has to be expanded from where it is so ln -s ../Pictures Pictures works. The link works as if you cd to where you store the linkmmmmmm– mmmmmm2021-02-01 12:14:12 +00:00Commented Feb 1, 2021 at 12:14

