在Bash中获取目录的父目录 [英] Getting the parent of a directory in Bash

查看:53
本文介绍了在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")"

如果还有斜杠也可以.

这篇关于在Bash中获取目录的父目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆