简体   繁体   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?

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.

相关问题 使用 shell 脚本删除目录下的所有文件,将文件目录作为参数传递但不想删除文件夹本身 - Deleting all the files under a directory using shell script, passing file directory as an argument but do not want to delete the folder itself 如何编写将一个目录下的所有文件和目录复制到另一个目录的linux脚本? - How to write a linux script that copies all the files and directories under one directory to another directory? 我想使用 shell 脚本删除目录下的所有文件,将文件目录作为参数传递 - I want to delete all the files under a directory using shell script, passing file directory as an argument 如何使用 shell 脚本解压缩目录中的所有文件? - How to unzip all files in directory using shell script? 将目录中存在的所有功能动态导入到脚本中 - Import All Function present in directory Dynamically into a script Unix shell脚本:更新所有子目录和子文件的时间戳,包括带空格的子目录和子文件 - Unix shell script: Update timestamp on all sub-directories and sub-files, including those with spaces shell 脚本:我有一个包含几个其他目录的主目录,我想打印这些目录中的所有文件 - shell scripting : I have a main directory which contain few other directories and I want to print all files inside those directories 如何使用 linux 中的 bash shell 脚本递归地重命名文件中的所有目录、文件和文本 - How to rename all directories , files and text in the files recursively using bash shell script in linux 如何在所有目录中的特定文件之间循环shell脚本? - How to loop a shell script across a specific file in all directories? Shell脚本可在包含特定扩展名文件的文件夹中递归列出所有子目录 - Shell script to list all subdirectories recursively within a folder that contains files with an specific extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM