vendredi 25 septembre 2015

How to delete file and its folder if there is one, in shell?

I have a shell script that is copying some files for a S3 bucket (aws) on local, then it is copying it to another place (it cannot do it directly, because of some authorization), but the idea is that the image may be in some folder and the shell is creating it locally, but it is deleting just the image and I found that after execution I have some empty folders. So my question is how to delete the folder too, if it is present in the name?

My shell part that copies and deletes:

aws s3 cp http://s3$SRC_BUCKET/$PHOTO_NAME $PHOTO_NAME --profile $SRC_PROFILE
# copy to other place
rm $PHOTO_NAME # here PHOTO_NAME may have the parent folder in it (a.jpg, 
               # or b/a.jpg) and I would like to delete the b folder too

Aucun commentaire:

Enregistrer un commentaire