vendredi 30 juin 2017

BASH to pipe find output and check if it exists elsewhere

I am trying to identify files in a directory that are not links, and then check that the same filenames exists in another directory.

In my script below, it works for when find identifies only one file, but fails when there is more than one.

This is what i have:

FILENAME=`find /home/user/test1/ -maxdepth 1 -mindepth 1 \! -type l -printf "%f\n"`
if [ ! -f /home/user/test2/"$FILENAME" ]; then
    echo "File not found!"
fi

out put of echo $FILENAME

test.touch touch.2

Aucun commentaire:

Enregistrer un commentaire