簡體   English   中英

如何使用根目錄中存在的所有目錄下特定文件夾中的Shell腳本列出所有文件?

[英]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?

我想列出根目錄中存在的所有當前目錄下特定文件夾中存在的所有文件。
說我的根目錄是. 並且存在多個文件夾,例如a1,b1,c1........a2,b2
現在,在所有這些文件夾中都有一個特定的文件夾 ,它是source/因此就像

a1/source/
b1/source/
.
.
a2/source/
b2/source/

包含所有必要文件的位置。 我可以在中的文件中列出所有文件嗎. 目錄由shell腳本源文件及其絕對路徑組成?

StackOverflow並不是真正的“為我編寫代碼”服務。 但這在Perl中非常簡單。

假設source目錄只出現在同一級別:

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

在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM