In Unix-like systems, symbolic links are common and we encounter a variety of processing work related to symbolic links.
This article for you to introduce some of the practice of symbolic links, I hope to write a shell script to bring some help, the need for friends may wish to refer to the following.
1. Symbolic links can be thought of as pointers to other files. It is functionally similar to an alias in Mac OS or a shortcut in Windows, and remember it is similar, not just oh.
2, delete the symbolic link will not affect the original file.
To create a symbolic link:
$ ln-s Target Symbolic_link_name
For example:
$ ln-s/var/www/~/web
This command creates a symbolic link named Web in the home directory of the logged-in user. This link points to/var/www/. This information can be seen from the following command output:
Copy Code code as follows:
$ ls Web
lrwxrwxrwx 1 slynux slynux 8 2013-02-07 19:16 Web->/var/www
The Web->/var/www indicates that the web is pointing to/var/www, as shown in the information above.
For each symbolic link, the permission tag section starts with the letter "L", which indicates that it is a symbolic link.
Therefore, to print out the symbolic links under the current directory, you can use the following command:
$ ls-l | grep "^l" | awk ' {print $} '
grep filters the output of the ls-l, showing only those rows starting with L. ^ is the string start tag. Awk is used to print out the 8th column, which is the filename part.
Another way is to use Find to print symbolic links, as follows:
$ find. -type L-print
In the above command, specify the type parameter of the Find command as "L", telling Discovery to search only for symbolic link files.
The-print option prints the list of symbolic links to standard output (stdout). and "." Indicates that the search starts at the current directory.
Use the following command to print out the pointing target of a symbolic link:
$ ls-l Web | awk ' {print $} '
/var/www
Each row of the ls-l command output corresponds to the details of one file.
The LS-L Web lists all the details of the symbolic link file Web. The 10th column of output contains the target that the file points to (if this is a symbolic link).
Therefore, in order to find the target associated with the symbolic link, we can print out the 10th column of the file's detailed list (ls-l output) in awk.
In addition, we can use the Readlink command to accomplish the same task. At some point, this is the most preferred usage, and its usage is as follows:
$ readlink Web
/var/www
OK, so here's the way to create and find symbolic links in bash, and hopefully it will help.