mardi 2 juin 2020

Returning True or False from find command

I need to check if a given file, with specific filename, exists in a directory (including sub-directories), and then perform an action if it exists, and another if not. Is there a way to use find command, returning True or False, as a condition for an if statement? I'm struggling to get it to work, but I don't know if it's just a problem of syntax or if there is a better way to approach the problem.

My specific problem is that I have a folder with lots of pictures in it, altogether. And I have a second folder where part of the same pictures are organized by subject on subfolders. So I want to delete, in the first folder, all the pictures that already are in the second folder.

What I'm trying to do is:

for file in "/first/folder"/*; do
filename=`basename $file`

if [find /second/folder -name $filename]
then
    rm $file
fi

Aucun commentaire:

Enregistrer un commentaire