linux一些使用技巧
linux一些使用技巧
- 文件名称和路径的提取
- 切换用户执行当前脚本
- 一行演示单引号与双引号的使用
- curl命令仅输出响应头信息,不输出body体
文件名称和路径的提取
文件路径为 /tmp/tkgup/test.sh
方式 | 获取文件名 | 获取文件路径 | 获取文件全路径 |
---|---|---|---|
方式一 | basename ${file} | dirname ${file} | realpath ${file} |
方式二 | echo ${file##*/} | echo ${file%/*} | readlink -f ${file} |
file=/tmp/tkgup/test.sh
basename $file # test.sh
echo ${file##*/} # test.sh
dirname ${file} #/ tmp/tkgup
echo ${file%/*} #/ tmp/tkgup
realpath ${file} # /tmp/tkgup/test.sh
readlink -f ${file} # /tmp/tkgup/test.sh
切换用户执行当前脚本
方式一,使用sudo: