Linux 技术手札

Linux find 指令搜寻多个档名或副档名

在 Linux 下用 find 搜寻档案很好用, 当加入 -name 参数时, 只可以对单一档名或副档案进行搜寻, 以下会示范用上 -o 参数, 进行多个档名或副档名的操作。

例如想搜寻在 /var/www/html 目录下, 所有 .php 及 .txt 副档名的档案:

# find /var/www/html -type f \( -name “*.php” -o -name “*.txt” \)

上面的 “-type f” 部份, 指定搜寻范围为档案; -name 参数指定搜寻的档案名称, 而 -o 则是 “OR” 的意思。

根据上面的例子, 如果想搜寻两种以上副档案, 只要再次加上 -o 参数, 例如除了 .php 及 .txt 外, 一同搜寻 .dat 档案:

# find /var/www/html -type f \( -name “*.php” -o -name “*.txt” -o -name “*.dat” \)
Exit mobile version