在 Bash 中获取目录的父目录 [英] Getting the parent of a directory in Bash
本文介绍了在 Bash 中获取目录的父目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个文件路径,例如...
If I have a file path such as...
/home/smith/Desktop/Test
/home/smith/Desktop/Test/
如何更改字符串以使其成为父目录?
How do I change the string so it will be the parent directory?
例如
/home/smith/Desktop
/home/smith/Desktop/
推荐答案
dir=/home/smith/Desktop/Test
parentdir="$(dirname "$dir")"
如果有斜杠也可以使用.
Works if there is a trailing slash, too.
这篇关于在 Bash 中获取目录的父目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文