files
ln
Creates hard or symbolic links between files. Symbolic links point to a path; hard links share the same inode.
ln [OPTION]... TARGET LINK_NAME Common flags
| Flag | Purpose |
|---|---|
| -s | Create a symbolic (soft) link |
| -f | Remove an existing destination before linking |
| -n | Treat LINK_NAME as a normal file when it is a symlink to a directory |
| -r | Make symlinks relative to the link location |
| -v | Print the name of each linked file |
Examples
ln -s /opt/app/current app Create a symlink named app pointing at the release directory
ln -sf /etc/nginx/sites-available/site /etc/nginx/sites-enabled/site Atomically replace an existing enabled symlink
ln source.txt hardlink.txt Create a hard link that shares source.txt's inode
ln -srv ../shared lib/shared Create a verbose relative symlink
Gotcha
Hard links cannot span filesystems or point to directories; use -s for cross-mount or directory links.
Related commands
cp
Copies files and directories from one location to another. Preserves or transforms metadata depending on flags.
ls
Lists directory contents including files and subdirectories. Supports detailed views, sorting, and filtering to inspect the filesystem quickly.
mv
Moves or renames files and directories. Within a filesystem it just relinks; across filesystems it copies then deletes.
rm
Removes files and, with -r, directory trees. Deletions are immediate and not recoverable from the shell.
mkdir
Creates one or more directories. Can create nested paths and set the mode of new directories in a single call.