显示以字母t开头的文件名

时间:2018-03-15 00:18:50

标签: perl

任何人都知道如何显示/ etc目录的长列表,其文件名以字母t开头,然后打印文件名列,指示您要打印的内容?

Example) perl.pl
/etc
filename: terminfo
filename: fruit 
filename: time
filename: birds

1 个答案:

答案 0 :(得分:2)

您可以使用

find /etc -maxdepth 1 -name 't*'

find /etc -maxdepth 1 -name 't*' -type f        # Plain files only

find /etc -name 't*' -type f                    # Recursive search

在Perl中,此功能由File::Find::Rule提供。

say for File::Find::Rule->maxdepth(1)->name('t*')->in('/etc');

say for File::Find::Rule->maxdepth(1)->name('t*')->file->in('/etc');

say for File::Find::Rule->name('t*')->file->in('/etc');