查找特定文件的文件夹

时间:2017-11-15 18:57:26

标签: regex unix sed find

我正在尝试查找特定文件的文件夹位置,例如<div class="col-lg-10 col-xs-10 ng-scope"> <div id="dashboard" class="container-fluid" ng-init="populateDropDown()" style="margin-right: 0px; margin-left: 0px;"> <div class="row"> <div class="col-lg-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <div style="color: white;"> <!-- ngRepeat: n in tapplications track by $index --> <span class="ng-scope" ng-repeat="n in tapplications track by $index"> <!-- end ngRepeat: n in tapplications track by $index --> <span class="ng-scope" ng-repeat="n in tapplications track by $index"> <!-- end ngRepeat: n in tapplications track by $index --> <span class="ng-scope" ng-repeat="n in tapplications track by $index"> <button class="btn ng-binding **btn-success**" ng-click="reload(n.app_seq)" ng-hide="n.app_name == 'GCP'" ng-class="{'btn-default':!CSI, 'btn- success':CSI}" type="button" style="">

到目前为止我尝试的是:

libgfortran.so

...会将以下内容输出到find 2>/dev/null / -name libgfortran.so (将stdout重定向到stderr):

/dev/null

由此我想只提取文件夹(没有尾随/usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.so ):

/

我尝试了类似的事情:

/usr/lib/gcc/x86_64-linux-gnu/4.8

...我希望能捕获第一个和最后一个find 2>/dev/null / -name libgfortran.so | sed 's/\(\/.*\/\)/\1/' 之间的内容(我需要删除最后一个/),但我得到的输出仍然是:

/

我如何实现我的目标?

4 个答案:

答案 0 :(得分:2)

find / -name libgfortran.so -exec dirname {} \; 2> /dev/null

答案 1 :(得分:1)

类似的东西:

dirname `find 2>/dev/null / -name libgfortran.so`

应该有用。

答案 2 :(得分:1)

如果您真的想使用result = [[x] * A.count(x) for x in set(A) if A.count(x) > 1]

sed

其中find 2>/dev/null / -name libgfortran.so | sed -E 's#(/.*)/(.*)#\1#g' 告诉sed使用正则表达式,所以你不必逃避这些副作用。小组-E是您的路径,\1是文件名。

答案 3 :(得分:0)

您可以使用grep:

以更简单的方式实现此目的
find 2>/dev/null / -name libgfortran.so | grep -o '\/.*\/'  
相关问题