make a symbolic link
Make a name that points to another file or folder, see where a link points, and change or remove it.
danger Steps marked in red delete, overwrite or stop something. Read each one before you run it.
Steps
-
ln -s /path/to/target linknamemake linkname point to the target
-
ls -l linknamesee where it points
-
readlink -f linknamethe full path it ends up at, through every link
-
ln -sfn /path/to/other linknamepoint an existing link somewhere else
-
rm linknamedanger remove the link; the target stays
-
ln /path/to/file hardlinka hard link instead: another name for the same file, same disk only
Notes
- Remove a link to a folder with
rm linkname, without a slash at the end:rm -r linkname/would delete what is inside the target. - A relative target is taken from where the link is, not from where you are.
Commands used
lnreadlinkls
Each has a page in lore: lore ln opens it.
Related recipes
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- argument list too long"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.
- change permissions of a folder and everything in itGive a folder, its subfolders and its files the permissions or the owner they need, without making them open to everyone.
- check a file's permissionsSee who may read, write and run a file or a folder, and why a path is refused.