如何使用根目录中存在的所有目录下的特定文件夹中存在的shell脚本列出所有文件?

时间:2017-04-21 08:05:36

标签: linux perl shell unix

我想列出根目录中存在的所有当前目录下特定文件夹中存在的所有文件 假设我的根目录是.,并且存在多个像a1,b1,c1........a2,b2这样的文件夹 现在,在所有这些文件夹中都有一个特定文件夹,即source/,就像

一样
a1/source/
b1/source/
.
.
a2/source/
b2/source/

其中包含所有必需的文件。我可以列出shell脚本源文件在.目录中的文件中的所有文件及其绝对路径吗?

2 个答案:

答案 0 :(得分:1)

StackOverflow并非真的为我编写代码"服务。但这在Perl中非常简单。

假设source目录只出现在同一级别:

my @files = glob '*/source/*';

答案 1 :(得分:0)

在Perl中,您可以使用File::Find

use feature qw(say);
use strict;
use warnings;

use File::Basename qw(basename);
use File::Find;

find( \&wanted, '.') ;

sub wanted {
    my $name = $_;    
    my $parent_dir = basename( $File::Find::dir );
    if ( (-f $name) && ( $parent_dir eq "source") ) {
        say $File::Find::name;
    }
}
相关问题