| Lesson 4
| Symbolic links
|Use Symbolic Links to simplify Software Maintenance.
Use Symbolic Links to simplify Software Maintenance
A symbolic link represents an alias for a file. A symbolic link shows up in
ls -l directory listings like this:
lrwxrwxrwx 1 root system 21 Aug 14 1996
unix -> /usr/lib/unix
This means that the link named
unix points to the file /usr/lib/unix. A reference to the link name is transformed into a reference to the target file.
Creating a symbolic link
Links are created with the
ln –s $HOME/project/command $HOME/bin/command
The syntax of the
ln command is like that of the
The above command creates a file $HOME/bin/command, which is a symbolic link to the file $HOME/project/command.
You must use the
–s option of the
ln command to create a symbolic link because this will allow you to link across filesystems and see the name of the link when you run
Without the ability to see the name of the link, you have no way of knowing the name to which a file is linked.
Any finite set of training data also contains sampling error.
Creating and using Symbolic Links
Here are the steps you followed to create a symbolic link:
- First, determine if the
nmap installation file is in your home directory. Use
ls -l to list all files and directories.
- You now know that the
nmap application is in your home directory. Test the
nmap setup program by typing
nmap -h. This runs the Help file. Notice from the Help file that this is
nmap version 1.0.
- You now wish to allow users to access the
nmap file. However, you do not wish to update multiple directories with the file constantly, and thus you want to create a symbolic link. To do this, first assert root privileges so you can create a folder for user2.
su and enter the root password.
- Using a full pathname in the command (for example, /home/user2/), create a new directory named
nmap in the user2 folder.
- Change the owner of this directory from root to user2, using a full pathname in the
chown user2 /home/user2/nmap
- Still working as root, change the group for the /home/user2/
nmap directory so that it belongs to the user2 group.
chgrp user2 /home/user2/nmap
- You are still in the user1 directory. Create a symbolic link from the nmap file in your home directory to the
For this step, use
$HOME to refer to your home directory, and /home/user2/nmap when creating the symbolic link. Hint: Do not forget to specify the name of the symbolic link in the second part of your
ln -s $HOME/nmap /home/user2/nmap/nmap
- Verify that the link now exists in the /home/user2/nmap directory by using
ls -l and the full path.
ls -l /home/user2/nmap
- You are still in the /home/user1 directory. To prepare for the new nmap 2.0 program, delete the
nmap file. Hint: Do not delete the link in
Delete the actual file by using a full directory path.
- Confirm that you wish to delete the file.
- Verify that the /home/user2/nmap link still exists in the /home/user2/nmap directory using
ls -l /home/user2/nmap
- You still have a symbolic link in the user2 directory, but as of now, it does not link to an existing file. This is because you have deleted the source
nmap file. You are still in the user1 home directory.
mv command, move the new
nmap file from the
home directory to the /home/user1 directory. For this step, enter the full directory pathname (for example, /home/user1/setupfiles/nmap).
mv /home/user1/setupfiles/nmap /home/user1/nmap
- Verify that you have moved the new
nmap file to the /home/user1 home directory with
ls-l again, verify that the link in the /home/user2/nmap directory still exists. Hint: Use /home/user2/nmap in the command.
ls -l /home/user2/nmap
The link in /home/user2/nmap is again valid, because you have placed a new file into the user1 directory. Creating symbolic links can help you save valuable time as a systems administrator, because it allows you to store files centrally, while still allowing users to access them. Now, go to the /home/user2/nmap directory.
- Issue the
nmap -h command.
- Notice that you are now using version 2.0 of the program. The
nmap -h command works because you have created a symbolic link from the /home/user2/nmap subdirectory to the /home/user1 directory. You can keep replacing the nmap program with newer versions, and as long as the name of the program remains the same, all users will be able to access that program without any further administration on your part. Now, surrender root privileges.
How does a System Admin use symbolic links to simplify Software Maintenance
System administrators often use symbolic links (symlinks) as a strategic tool to simplify software maintenance and system management. These links, essentially shortcuts or references to files or directories located elsewhere, can be used to streamline various administrative tasks, enhance interoperability, mitigate downtime during updates, and create flexible development environments.
Here's how a system admin can use symbolic links for software maintenance:
- Version Management: Software applications often receive updates, leading to different versions coexisting on the same system. By creating a symbolic link to the currently active version, admins can smoothly switch between software versions without altering the application paths used by users or scripts. When it's time to update, they just need to change the symlink to point to the new version. This strategy can reduce downtime and errors during software updates.
- Software Consolidation: In multi-user or network environments, the same software may be needed in multiple locations. Instead of duplicating the software, symlinks can be used to point to a central instance of the software, saving disk space and ensuring consistent behavior across all instances.
- Improved Interoperability: Some software might require data or other software components to exist in specific locations. If the needed files are elsewhere, moving them might disrupt other processes. In such cases, a symbolic link can create a virtual path that meets the software's expectations without disturbing the actual file or directory location.
- Simplifying Complex Directory Structures:
Sysadmins often deal with software that uses complicated directory structures. By using symbolic links, they can create simplified, intuitive paths for users and scripts. This can also help when training new users or scripting repetitive tasks.
- Creating Portable Development Environments: In development environments, symlinks can be used to abstract the paths to libraries, dependencies, or datasets. This allows developers to work in a consistent environment, even as underlying software or data change. If properly designed, the environment can be easily replicated on new machines, simply by setting up the appropriate symlinks.
- Linking Configuration Files: Configuration files are often updated, copied, or moved. To manage this, symlinks can point to the current or 'live' configuration, while the actual files are stored in version control or backup systems. This allows easy rollback of changes and ensures that the live system always points to a valid configuration.
When using symbolic links, system administrators need to remember that these are just pointers and do not contain any actual data. If the source file or directory is deleted, the link will be broken. Also, excessive use of symlinks can make a system difficult to understand and maintain, so they should be used judiciously and documented well. Lastly, symlinks can pose security risks if misused, as they can be used to circumvent file system permissions, so appropriate safeguards need to be in place.
The concept of a link in UNIX is for file sharing
. A link file is created by the system when a symbolic link is created to an existing file. The link file points to the existing file, which allows the users to rename an existing file and share it without duplicating its contents. For the kernel, every file has one inode, but it may have several names of links, all of which map into the inode. The concept of the symbolic link
in UNIX is a creation of BSD but is presently available on almost all versions of UNIX .
The symbolic link is also called soft link and a symbolic link
may be a file containing the pathname of another file or directory, and it can cross file system boundaries. In contrast to soft link, it is a hard link.
There are two typical hard links:
one is written as .; the other is ..
- . in a directory is a hard link to the directory itself, and
- .. of the directory is a hard link to its parent directory.