# shell 学习笔记
#Create a temporary file or directory, safely, and print its name.
# -d, --directory create a directory, not a file
export TMP_DIR='mktemp -d'
# $? is used for checking return result
readlink :
readlink - print value of a symbolic link or canonical file name
-f, --canonicalize
canonicalize by following every symlink in every component of the given name recursively; all but the
last component must exist
一般使用 readlink -f .
-f 使用和不使用的区别是 -f 会 递归找最终的链接,不加 -f 就直接一级。
$ mkdir -p ~/wrwork/bash
$ cd ~/wrwork/bash
$ ln -s ~/Downloads test
$ ln -s test test1
$ readlink -f test1
/home/chenqiang/Downloads
$ readlink test1
test
which - locate a command
SYNOPSIS
which [-a] filename ...
DESCRIPTION
which returns the pathnames of the files (or links) which would be executed in the current environment, had
its arguments been given as commands in a strictly POSIX-conformant shell. It does this by searching the PATH
for executable files matching the names of the arguments. It does not follow symbolic links.
chenqiang@qiang:~/wrwork/bash$ which git >/dev/null
chenqiang@qiang:~/wrwork/bash$ echo $?
本文介绍了几个常用的Shell命令,包括创建临时文件或目录的mktemp、获取符号链接真实路径的readlink以及查找命令位置的which。通过示例展示了这些命令的具体用法及区别。
5043

被折叠的 条评论
为什么被折叠?



