ln
Files and directories
Usage
ln -s [target] [linkname]Gives a file another name; a symlink made with -s can point anywhere but breaks when the target moves, and a relative target is read from the link's own directory.
Common flags
| Flag | Meaning |
|---|---|
| -s | Make a symbolic link instead of a hard link |
| -f | Replace the target if it already exists |
| -n | With -f, replace a symlink to a directory instead of writing inside it |
| -i | Ask before replacing |
| -v | Report each link created |
Examples
ln -s /opt/app/bin/app /usr/local/bin/appPuts the program on your PATH.
ln -sfn /srv/releases/v2 /srv/currentRepoints a current symlink at a new release.
ln data.csv hardlink.csvA second name for the same bytes on the same filesystem.
Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does ln do?
Gives a file another name; a symlink made with -s can point anywhere but breaks when the target moves, and a relative target is read from the link's own directory.
Q. How do I type it?
ln -s [target] [linkname] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
5 are listed here; the full set is in man ln. This command sits under Files and directories.
Related commands
man page: man ln