Shell:从路径中剥离目录
问题:
在 Linux shell 中,你有一个文件路径,你想剥离除文件名外的所有内容,例如你有路径 ../images/photo.jpg 只想要 photo.jpg
解决方案
假设文件名存储在 shell 变量 $filename 中,使用此代码片段:
strip-dir-from-path.sh
echo $filename | rev | cut -d/ -f1 | revCheck out similar posts by category:
Shell
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow