When you talk about a Linux-based work environment, on many occasions it is necessary to access certain folders, files or documents that are in another location on the hard drive. For this purpose we use symlinks or symbolic links.
It is a type of file widely used in many operating systems, although under different names, since it has great similarity with the Windows shortcuts.
With the aim of facilitating the work experience and fluency in desktop environments, we will find ourselves very often in the need to use these soft links, and In this article we will explain how to create them, manage them, and navigate with them through your files.
What are symbolic links and what is the use of creating them in Linux?
A symbolic link, also known as symlink or soft link, is a file type that provides access to another file, which is located elsewhere on the hard drive, since they are usable on any partition or file system in storage space.
The Using symbolic links provides a very efficient method of file system expansion, so if, for example, we are working on a filesystem NTFS, we can access locations in a file system ext2, or any other file.
Symbolic Link vs Hard Link Which one is more practical and how are these links different?
Similar to a symbolic link, a hard link, or hard link, it is an access to physical data of a file or folder located in a different position of the hard disk. This access becomes an exact copy of the associated files, both in terms of permissions and data. However, unlike the soft links, cannot create a hard link for a location or folder that is on a different partition or file system than the original one.
Learn step by step how to create symbolic links on your computer with Linux operating system without errors
The need to connect and facilitate movement within Linux work environments is the main reason to use soft links.
So now we will explain step by step how to create symbolic links for your files or folders:
For a file
Creating a symbolic link for a file is a simple process, since it does not require more than a command line.
To create the symbolic links linked to files, use the command “In” and the option “–s”, so that the line would look something like this:
ln -s [archivo] [etiqueta simbólica]
This is the general command for create symbolic links in Linux, replacing [archivo]
with the name of the existing file for which the link is created, and [etiqueta simbólica]
with the name that will carry the symbolic link. For check symbolic links created on the computer, use the command ls –l
, which, once executed, it will display a detailed list with the symbolic links created.
For a folder
Generating a symbolic link for a folder takes the same amount of work as for a file, since it just requires a command line:
ln -s [Specific file/directory] [symlink name]
In this case, need to replace option [Specific file/directory]
, with the address of the folder to which you want to create a link, separated by a space and the symbol “/”
from the destination folder.
Thus, the command would look like this:
ln -s /user/local/documents /downloads
As soon as the command is run, a link to the Documents folder will be created, which will be attached to the directory Downloads.
These are other actions for file management that you can perform in Linux
Just as creating symbolic links is easily accomplished through the Linux command terminal, many other essential file handling actions are performed like this:
Copy
This action is done through the command cp
on Linux.
It works in all its distributions and allows you to copy files or files to a specified destination in the same command line, in this way:
cp [archivo1] [carpeta1]
This command will copy the [archivo1]
within [carpeta1]
if it exists in system. In case it does not exist, will create the specified folder.
It also has a series of options that are specified as follows:
-
-a
maintains the attributes of the copied files. -
-b
make a backup of the file or folder prior to copying. -
-d
makes a copy of a link, without copying the folder it refers to. -
-i
overwrites files after requesting confirmation. -
-p
keeps certificates of ownership, permit and date on copies. -
-R
copy files, folders and subfolders. -
-s
creates symlinks instead of copying folders. -
-u
the copy does not proceed unless the date of origin is later than the date of destination. -
v
displays file copy progress messages.
In this way, the copying process becomes more dynamic, allowing multiple procedures to be performed with a single command line.
If, for example, you want to make a backup copy, the command would be the following:
cp –r [carpeta1] [carpeta2]
Move and rename
For this action the command mv
In the terminal. This order run a double task: You can move files from one folder to another on your computer, or rename the files specified in the command.
The basic line of this command for the move action would look like this:
mv [fuente] [destino]
On the other hand, if your goal is to rename the file, the syntax changes slightly, looking like this:
mv [nombreviejo 1] [nombrenuevo 1]
Like many commands in Linux, the command mv
offers a series of options that multiply its usefulness allowing to carry out more actions in addition to the predefined ones of the command.
The list of actions for “mv” is as follows.
-
-d
makes a backup of the files to be moved or renamed. -
-f
delete files without confirmation. -
-v
Prompts for confirmation before overwriting files.
Create directories
It’s about the command mkdir
and it works by creating one or more directories within the file system. Since it only creates new folders with the specified name, if a directory with that name already exists, the command will not work.
The command syntax will look like this:
mkdir [directorio1]
mkdir [directorio1] [directorio2]…
it’s possible create multiple managers at the same time. The command mkdir
includes options to specify the parameters of the created directories and display details of the folder creation process.
Let’s see next:
-
-m
Allows you to assign the permission settings of the new directory. -
-p
creates the directories related to the new folder, if they do not exist.