在工作中经常遇到在一个文件中记录了许多文件名或者图片名,在指定的目录下对需要找到此文件中所有文件,但指定目录下并没有文件中记录的所有名字,此时需要在指定目录下找到此文件中记录了的所有文件,如果不存在则对此文件进行记录!

脚本实例:

   在pic.txt记录了所有需要找到的文件名

[root@shvpicserver tmp]# cat find_pic.sh 
#!/bin/bash
cat pic.txt | while read line
do
if [ -f /usr/local/war/static/ftp_product_img/$line ];then
    find /usr/local/war/static/ftp_product_img/ -name $line -exec cp {} /tmp/pic \;
else
    echo "$line not_exist!" >> /tmp/find_pic.log
fi
done