仅列出文件的公共父目录 [英] List only common parent directories for files
本文介绍了仅列出文件的公共父目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在搜索一个文件,比如file1.txt,并且find命令的输出如下所示。
/ home / nicool / Desktop / file1。 txt
/home/nicool/Desktop/dir1/file1.txt
/home/nicool/Desktop/dir1/dir2/file1.txt
在上面的例子中我只想要共同的父目录,在上面的例子中是/ home / nicool / Desktop。如何使用bash实现?请帮助找到这个问题的一般解决方案。
解决方案
我想这回答了你的问题。
http://stackoverflow.com/questions/12340846/bash-shell-script-to-find-the-closest-parent-directory-of-several-files [ ^ ]
I am searching for one file, say "file1.txt", and output of the find command is like below.
/home/nicool/Desktop/file1.txt /home/nicool/Desktop/dir1/file1.txt /home/nicool/Desktop/dir1/dir2/file1.txt
In above cases I want only common parent directory, which is "/home/nicool/Desktop" in above case. How it can be achieved using bash? Please help to find general solution for such problem.
解决方案
I think this answers your question.
http://stackoverflow.com/questions/12340846/bash-shell-script-to-find-the-closest-parent-directory-of-several-files[^]
这篇关于仅列出文件的公共父目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文