How do I print all .pdf files names to an output file with command line?

前端 未结 5 1202
逝去的感伤
逝去的感伤 2021-02-04 08:53

This seems easy in Linux, but I\'m trying to print the names of *.pdf files within a directory and its subdirectories to an output file. I have Perl installed on my

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 09:31

    use strict;
    use warnings;
    use File::Find;
    
    my $dirname = shift or die "Usage: $0 dirname >outputfile";
    
    File::Find::find( sub {
        print $File::Find::name, "\n" if $File::Find::name =~ /\.pdf\z/
    }, $dirname );
    

提交回复
热议问题