Search code examples
shellunlinkblacklist

Delete files based on backlist word


I am looking for bash on linux or php file

file: cron.php or cron.sh

dir: /files

blacklist: blacklist.txt

cron.php runs every minute and search for file names containing blacklist.

delete files based on file name

reason: clean download center from explicit files ;


$blacklist = 'blacklist.txt';
for each /files/*.*
echo 'deleted file: "$blacklist" <br>' ;

bash or php code for delete files based on backlist word


Solution

  • I am assuming the blacklist words are written in a file named blacklist.txt:

    #!/bin/bash
    while read line; do
    list=/files/*$line*
    for file in ${list[@]}
    do
    [[ -f $file ]] && rm $file
    done
    done < blacklist.txt