In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use symbolic links under Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use symbolic links under Linux.
There are two kinds of link files under Linux, one is a file similar to the shortcut function of Windows, which allows you to quickly link to the target file (or directory), which is a soft link, and the other is to generate a new file name through the inode link of the file system, rather than a new file! This is called hard link (hard link). Types of symbolic links
There are two main types of symbolic links, namely:
* * hard links: * * hard links are direct pointers to files or directories in the file system. Hard links can only be created on the same file system as the target file.
* * soft link: * * A soft link is an indirect shortcut to a file or directory that can exist anywhere in the file system. Soft links can point to files in different file systems.
How to create symbolic links
To create symbolic links in Linux, we use the ln command. Executing a command without options creates a hard link to the specified target file.
The general syntax of the ln command is:
Ln [OPTIONS]
To create a soft link, you need to add the-s option:
Ln-s [OPTION] example 1: create a soft connection to a file
The following command creates a soft link to the / var/log/audit/audit.log file in our home directory:
[root@localhost] # ln-s / var/log/audit/audit.log ~ / audit.log
Example 2: create a soft connection to a directory
The following command creates a soft link to the / var/log directory in our home directory:
[root@localhost] # ln-s / var/log ~ / log
How to delete a symbolic link
To delete a symbolic link, we use the command unlink followed by the path of the symbolic link to be deleted.
[root@localhost] # unlink ~ / log
As you can see in the following figure, the shortcut for log is gone.
Note: if you delete the target file or directory, remember to delete the symbolic link, because the symbolic link will not be deleted as the file is deleted.
How to get the target file or directory of a symbolic link
Each symbolic link points to a target file or directory (unless corrupted). To get the target file / directory of the symbolic link, we use the readlink command to display the target of the symbolic link.
For example, to get the target of the audit.log file we created in the previous section, we can do the following:
[root@localhost ~] # readlink ~ / Bash script for getting symbolic links
We can create a simple bash script that accepts paths and lists all symbolic links and their target files or directories:
[root@localhost ~] # vim symlink.shrunk. Find: target_dircd $target_dirlinks=$ (find. -maxdepth 1-type l-ls | awk'{print $11}') for link in $linksdo echo "$link-> $(readlink $link)" done
The script first asks the user which directory to get. The script then goes to the directory provided and finds all the symbolic links in the directory and passes the output to the awk command.
Awk outputs and locates symbolic links and saves them to a variable called links.
Then we create a loop, grab each link in the links variable, and use the readlink command to get their target location.
Finally, the symbolic link and the target directory are displayed. Here is a sample output:
[root@localhost] #. / symlink.shProvide the directory to evaluate: / etc./rc.local-> rc.d/rc.local./redhat-release-> centos-release./system-release-> centos-release./init.d-> rc.d/init.d./rc0.d-> rc.d/rc0.d./rc1.d-> rc.d/rc1.d./rc2.d-> rc.d/rc2.d./rc3.d-> rc. D/rc3.d./rc4.d-> rc.d/rc4.d./rc5.d-> rc.d/rc5.d./rc6.d-> rc.d/rc6.d./localtime->.. / usr/share/zoneinfo/Asia/Shanghai./mtab->.. / proc/self/mounts./yum.conf-> dnf/dnf.conf./grub2.cfg->.. / boot/grub2/grub.cfg so far I believe you have a deeper understanding of "how to use symbolic links under Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.