💾 Archived View for darknesscode.xyz › notes › symlinks.gmi captured on 2024-02-05 at 09:46:09. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-05)

-=-=-=-=-=-=-

Symbolic links in Linux systems

Symbolic link, also know as a Symlink or soft link. Is a kind of shortcut that point to a specific file or directory.

Links Types

There are two types of links in Linux/UNIX systems:

How to Use the ln Command

The *ln* command syntax for creating symbolic links is as follows:

ln -s [OPTIONS] FILE LINK

Symlink To a File

To create a symbolic link to a given file, run:

ln -s source_file symbolic_link

The symbolic_link parameter is optional. If you do not specify the symbolic link, the ln command will create a new link in your current directory:

Symlinks To a Directory

To create a symbolic link to a directory is the same as when creating a symbolic link to a file, run:

ln -s /mnt/my_drive/anime ~/Videos/anime

Overwriting Symlinks

If you try to create a symbolic link that already exists, the ln command will print an error message.

ln -s my_file.txt my_link.txt
ln: failed to create symbolic link 'my_link.txt': File exists

To overwrite the destination path of the symlink, use the -f (--force) option.

ln -sf my_file.txt my_link.txt

Check if symlink was created

To verify that the symlink was successfully created, use the *ls* command:

ls -l

The output will look something like this:

my_link.txt -> my_file.txt

Removing or Deleting Symlinks

To delete/remove symbolic links use either the unlink or rm command. The syntax is simple:

unlink symlink_to_remove

Removing a symbolic link using the rm command:

rm symlink_to_remove

No matter which command you use, when removing a symbolic link not append the / trailing slash at the end of its name.

If you delete or move the source file to a different location, the symbolic file will be left broken and should be removed.

----------

Home

Linux

Notes

MicroLog

----------

© DarknessCode