Skip to content

Instantly share code, notes, and snippets.

@mayukojpn
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save mayukojpn/aea046a26e98d672d89f to your computer and use it in GitHub Desktop.

Select an option

Save mayukojpn/aea046a26e98d672d89f to your computer and use it in GitHub Desktop.
"12345/12345.jpg" みたいな形式の名前のファイルを、親ディレクトリに出してあげる。
files="*"
for filepath in ${files}
do
if [ -e ${filepath}/${filepath}.jpg ]; then
mv ${filepath}/${filepath}.jpg ${filepath}.jpg
rm -rf ${filepath}
echo "UPDATE wp_posts SET post_content=REPLACE(post_content,'${filepath}/${filepath}.jpg','${filepath}.jpg');" >> sql_replace.sql
echo ${filepath}.jpg removed >> log.txt
else
if [ -e ${filepath}/${filepath}.png ]; then
mv ${filepath}/${filepath}.png ${filepath}.png
rm -rf ${filepath}
echo "UPDATE wp_posts SET post_content=REPLACE(post_content,'${filepath}/${filepath}.png','${filepath}.png');" >> sql_replace.sql
echo ${filepath}.png removed >> log.txt
else
echo ${filepath} not removed >> log.txt
fi
fi
done
read wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment