By Alvin Alexander. Last updated: March 25, 2020
As a brief “note to self,” this is the Bourne shell script I use to copy images from my Drupal 8 sites directory to the same directory on my new “Static Drupal” website:
tarFile=newImagesFromDrupalSitesDir.tar drupalHtmlDir=/drupal8/html staticHtmlDir=/staticDrupal/html cd $drupalHtmlDir rm $tarFile 2> /dev/null # create a tar file containing all new images find sites -type f \( -name "*.jpg" -o -name "*.jpeg" -o -name "*.png" -o -name "*.gif" \) -mtime -2 -print0 | xargs -0 tar rvf $tarFile # TODO make sure the tar file exists if [ -e $tarFile ] then echo "tar file exists, moving it to $staticHtmlDir" mv $tarFile $staticHtmlDir cd $staticHtmlDir tar xvf $tarFile rm $tarFile else echo "POSSIBLE ERROR: the tar file DOES NOT exist" fi
I changed the three initial variable names, but the rest of the script shows one possible way to copy all of the images in the original sites directory into the new Static Drupal directory. If you wanted to see things such as how to use multiple filenames with the Linux find
command, or how to use the find
command to create a tar file, I hope this example is helpful.