如何测量一个文件系统路径的深度是多少? [英] How to measure the depth of a file system path?
本文介绍了如何测量一个文件系统路径的深度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方式来做到这一点在命令行上,因为这不是太难的的Java
或的Python <任务/ code>。
I'm looking for a way to do this on the command line, since this is not too hard a task in Java
or Python
.
是这样的:
$ measure_depth /a/b/c/d/e/f
6
$ measure_depth /a
1
此问题是功能上等同于有没有一种简单的方法来计算一个文件名斜线的数量?
This question is functionally equivalent to "is there an easy way to count the number of slashes in a filename?"
推荐答案
定义一个函数measure_depth:
Define a measure_depth function:
measure_depth() { echo "${*#/}" | awk -F/ '{print NF}'; }
然后,如下所示使用它:
Then, use it as follows:
$ measure_depth /a/b/c/d/e/f
6
$ measure_depth /a
1
这篇关于如何测量一个文件系统路径的深度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文