Hot answers tagged

550

┌── 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/...


74

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


33

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.


28

It's just ln -s <source> <destination>.


18

sudo ln -s /Users /home will work with additional configuration, but I don't think that is a good idea as you should access home via ~ in shell or $HOME. Also /home might be a Linux standard and often used in Unix but not always so better to rely on information that is guaranteed to work not something that works only most of the time if everyone has kept to ...


15

You can use a directory hard link, but only on HFS+ file system. You'll need GNU ln to use the -d option. This can be installed using Homebrew: brew install coreutils, then run: sudo gln -d "/path/to/original" "/path/to/drive/folder" You will be asked for your password. This command creates a hard link to the file/folder itself rather than how a symlink ...


12

Let's try a few experiments, and look at a few things. In a terminal emulator, such as Terminal.app in /Applications/Utilities, go to your home directory (cd ~) and create a directory (mkdir [directory]). Make sure you go in the directory we just created (cd [directory]). cd ~ mkdir directory cd directory After that, make a file; a simple text file will ...


10

I had the same problem, and it seems the problem in LaunchService in OS X. To clear it "cache" try this command in terminal /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user ; and then killall Finder; killall Dock; In Mavericks it should work ...


7

In command line you´ve more power with the following code line cd ~ && unlink steve so you´re shure that only the symlink will be deleted and not the complete home path :)


6

I don't know why, but I have figured it out that if I make the symlink to the Contents directory, then associations work fine. That is I do the following in a terminal window, using my personal Applications folder as an example: % mkdir ~/Applications/Emacs.app % ln -s /usr/local/Cellar/emacs/23.2/Emacs.app/Contents ~/Applications/Emacs.app Something ...


5

Do you have several versions of Node installed via homebrew? Every time it updates node homebrew puts the newest version alongside the old one and then updates the symlinks to the newest version. Running the brew cleanup should reduce that up a bit for you.


5

It's a better idea to copy the iTunes Media folder to your external hard drive, then go to iTunes Preferences > Advanced tab and change the iTunes Media folder location to the one on your external disk. You can also move the library file itself (in ~/Music/iTunes/ on my system), but I don't recommend doing both at the same time. There're other questions ...


5

I regret this answer is not exactly authoritative, since I've never actually done this myself--though I have used a similar automounter on other Unix systems--but here's my understanding as to what /home is used for on OS X. So, let's follow the trail: If you first type mount in Terminal to show active mounts, you'll see this line: map auto_home on /home (...


5

You can delete the symlink the same way as any other file. It will not follow the link. You can do this in finder by moving the link to the trash, or from the command line using rm path/to/symlink. Do not attempt to remove all symlinks on your computer. They are used by the system in some places, such as frameworks.


5

Goto your Home Folder > Library > Preferences and delete the files: com.apple.finder.plist com.apple.sidebarlists.plist If you can't find the files use this method: from the Finder menu bar, select Go > Go to Folder and copy the following line into the text box that opens: ~/Library/Preferences/com.apple.finder.plist Then, restart, or log out and in ...


5

From the top of my head (and without any testing at all): Create a text file with the following content #!/bin/bash find "$1" -type l | while read symlink; do if [ ! -e "$symlink" ]; then old_path=$(readlink "$symlink") new_path=${old_path/Old Drive/New Drive} ln -f -s "$new_path" "$symlink" fi done Make it executable by ...


5

In a bash shell, to set a variable, simply use set NAME=bob or set VITAL_SIGNS=none. You can also set a variable using the output of a command by calling the bash-builtin function read to assign the output to a named variable. This works well in a pipe stream like so: ls -l | wc -l | read NUMBER_OF_LINES Or you can assign the output directly to a variable ...


5

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.


5

Simply running rm ~/steve is safe: specifying "~/steve" (not "~/steve/", with a trailing slash) means rm will work directly on the link and not follow it, as it would if you enter "~/steve/". even if you mistyped "~/steve/", deleting with rm will not delete a directory unless you give it a "-r" option.


5

Cask does not clean up old versions by default. It stages the installs in /opt/homebrew-cask/Caskroom/$APPNAME and then symlinks them in to ~/Applications or /Applications depending on the brew recipe. And then it leaves the old versions around until you run brew cleanup. You can see old installs of OpenOffice under /opt/homebrew-cask/Caskroom/openoffice. ...


5

The default directory for third-party executables in macOS is /usr/local/bin. Since this directory already is in the PATH you don't have to modify anything except sudo linking the executable to this dir. If the directory doesn't exist, create it with sudo mkdir /usr/local/bin. If you plan to install brew later, it's recommended to change the owner of the ...


5

The method you described involves installing a third party ln command that allows you to ask the kernel to create a hard-link for a directory. The ln command from coreutils ends up executing the linkat() function in the Darwin kernel, where the source code includes the following comment: /* * Normally, linking to directories is not supported. * However, ...


4

if you are on Snow leopard or on Lion the way to do it is as follows: go to /etc/paths.d then sudo touch pypy then edit the pypy file (with vim, nano or whatever) to include the path to pypy /path/to/pypy the restart the terminal. For instance, I installed julia (http://julialang.org/) and I added a julia file in paths.d $ cd /etc/paths.d $ ls 50-X11 ...


4

As Vincent points out, the proper command is ln -s, not ls -s. In addition to that, ln will throw an error if the target of the link (in this case, the Mydocs folder in Dropbox) already exists. The proper way to do this is to delete /Users/Joe/Dropbox/Mydocs, then run ln -s /Users/Joe/Documents/Mydocs /Users/Joe/Dropbox/Mydocs.


4

Do a chmod on the symlink to give you the rights. do shell script "chmod 755 /usr/bin/ant" with administrator privileges


4

Got it! Turns out ln is the answer after all, but I had an error in my path. Here is a functional command line for anyone who might need to edit a symlink "in place" in the future: ln -f -s /path/to/new/location/of/original /path/to/location/of/broken/symlink/ Notice that you're not actually pointing all the way to the broken symlink itself, but to the ...


4

You can do this with Symlinks: ln -s /path/to/original/location /path/to/intended/shortcut For example, if you want ~/Scripts to go to ~/Dropbox/Documents/Scripts you can do… ln -s ~/Dropbox/Documents/Scripts ~/Scripts Then open ~/Scripts/test.sh will open the file at ~/Dropbox/Documents/Scripts/test.sh. To see the symlink you can run ls -laPGh ~/...


4

You can always create a symlink in /usr/local/bin manually, which (depending on the order of path components in $PATH) will then shadow the standard binary in /usr/bin. As nano is used interactively only, the risk of breaking anything is probably rather small.


4

Aliases store two pieces of information about the destination file - both the location and a file identifier. Symbolic links only store the other location. For that reason, if you move a file, Aliases are superior since they can often still point at the correct file when a change happens. Dropbox or moving the files to another filesystem is where things get ...


4

/usr/bin is, as a lot of directories installed by default, protected by SIP and can't be modified by any user. There are ways to disable SIP, but the better approach is to use the directories beneath /usr/local for user-installed things sudo mkdir /usr/local/bin sudo ln -s /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 /usr/local/bin/ sudo sh ...


Only top voted, non community-wiki answers of a minimum length are eligible