[英]How to list all the files using shell script present in a specific folder under all the directories those are present in the root directory?
I want to list all the files that are present in a specific folder under all the present directories present in my root directory. 我想列出根目录中存在的所有当前目录下特定文件夹中存在的所有文件。
Say my root directory is .
说我的根目录是
.
and there multiples folders like a1,b1,c1........a2,b2
are present. 并且存在多个文件夹,例如
a1,b1,c1........a2,b2
。
Now in all those folders there is a specific folder which is source/
so that will be like 现在,在所有这些文件夹中都有一个特定的文件夹 ,它是
source/
因此就像
a1/source/
b1/source/
.
.
a2/source/
b2/source/
where all the necessary files are present. 包含所有必要文件的位置。 Can I list all the files in a file that is in the
.
我可以在中的文件中列出所有文件吗
.
directory by a shell script source file along with their absolute path? 目录由shell脚本源文件及其绝对路径组成?
StackOverflow isn't really a "write my code for me" service. StackOverflow并不是真正的“为我编写代码”服务。 But this is really simple in Perl.
但这在Perl中非常简单。
Assuming that the source
directories only ever appear at the same level: 假设
source
目录只出现在同一级别:
my @files = glob '*/source/*';
In Perl you could use File::Find
: 在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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.