Skip to content

Instantly share code, notes, and snippets.

@autotel
Last active June 17, 2021 08:02
Show Gist options
  • Save autotel/97f55ec5ec054e78512472fe82451593 to your computer and use it in GitHub Desktop.
Save autotel/97f55ec5ec054e78512472fe82451593 to your computer and use it in GitHub Desktop.
#
# recursively find .haccess files, starting from the script's folder, and copy them into DOT.htaccess
# this is needed in order to be able to sync apache directories on nextcloud,
# for example, if you are a php or wordpress developer who uses nextcloud.
# most of the code was not written by me, but was taken from here:
# https://superuser.com/questions/1472837/rename-all-htaccess-files
# author: https://superuser.com/users/990044/freddy
# If you call it with "revert" as argument, it will do the reverse operation, namely
# renaming all DOT.htaccess into .htaccess
# I suggest having this on the root of each web project, and calling it every time you
# do changes to the htaccess files. Call this script with the "revert" argument when
# you clone your backup down again.
if [ "$1" = "revert" ]; then
echo "copying all 'DOT.htaccess' files into '.htaccess'"
find ./ -name "DOT.htaccess" -type f -exec bash -c '
for file; do cp "$file" "${file/DOT.htaccess/.htaccess}"; done
' bash {} +
else
echo "copying all '.htaccess' files into 'DOT.htaccess'"
find ./ -name ".htaccess" -type f -exec bash -c '
for file; do cp "$file" "${file/.htaccess/DOT.htaccess}"; done
' bash {} +
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment