linux程序常见符号意思
Symbolic link or soft link files are very common and useful on Linux/Unix systems. It works as a alias file for a file. You can create a symbolic links and it can operate transparently for most operations just as normal files. Programs that read or write to files named by a symbolic link behaves as if operating directly on the target file.
符号链接或软链接文件在Linux / Unix 系统上非常常见且有用。 它用作文件的别名文件。 您可以创建一个符号链接,它可以像普通文件一样对大多数操作透明地运行。 读取或写入由符号链接命名的文件的程序的行为就像直接在目标文件上操作一样。
Let’s look at the common techniques and tools to play with symbolic link files on Linux.
让我们看一下在Linux上使用符号链接文件的常用技术和工具。
创建一个符号链接 (Create a symbolic link)
To create a symbolic link file in the current directory to a target file, say, ../target
:
要在当前目录中创建到目标文件的符号链接文件,例如../target
:
$ ln -s ../target
This will create a symbolic link file target
in the current directory.
这将在当前目录中创建一个符号链接文件target
。
You can also give it a different name, say tt
:
您也可以使用其他名称,例如tt
:
$ ln -s ../target ./tt
检查文件是否是Bash中的符号链接 (Check whether a file is a symbolic link in Bash)
In Bash script, we can easily test whether a file is a symbolic link by the file test operator -h
. For example:
在Bash脚本中,我们可以通过文件测试操作员-h
轻松测试文件是否为符号链接。 例如:
if [ -h $file ]; then
echo "a symbolic link"
fi
找出符号链接文件的目标 (Find out the target of a symbolic link file)
Use the readlink command.
使用readlink命令。
To find out the target of the ./tt
we created:
为了找出./tt
的目标,我们创建了:
$ readlink ./tt
With these basic tools, we can combine them with scripts to be some powerful tools.
使用这些基本工具,我们可以将它们与脚本结合起来成为一些强大的工具。
To find out the canonical target (dereference every symlink in every component) of the ./tt
we created:
为了找出我们创建的./tt
的规范目标(取消引用每个组件中的每个符号链接):
$ readlink -f ./tt
翻译自: https://www.systutorials.com/playing-with-symbolic-links-on-linux/
linux程序常见符号意思