Currently this should take care of most locations but as needed the list will be updated.
Bash
#!/bin/bash
# Common Firefox profile locations on Unix/Linux
# You can add to this list by opening up Firefox and going to "about:profiles"
locations=(
"$HOME/.mozilla/firefox" # Main profile data (bookmarks, history, extensions)
"$HOME/.cache/mozilla/firefox" # Cache data
"$HOME/snap/firefox/common/.mozilla/firefox" # Snap package profile location
"$HOME/flatpak/org.mozilla.firefox/.mozilla/firefox" # Flatpak profile location
"$HOME/Library/Application Support/Firefox" # macOS HomeBrew Root Directory
"$HOME/Library/Caches/Firefox/" # macOS HomeBrew Local Directory
# "$HOME/Library/Caches/Mozilla/updates/Applications/Firefox" # macOS HomeBrew Local Directory
"$HOME/Library/Caches/Mozilla" # macOS HomeBrew Local Directory
)
pkill firefox
# Ensure /etc/os-release exists
if [[ -f /etc/os-release ]]; then
# Load OS info into variables
source /etc/os-release
OS_ID=${ID,,} # Lowercase
OS_LIKE=${ID_LIKE,,} # Lowercase
if [[ "$OS_ID" =~ (rhel|centos|fedora|rocky|almalinux) ]] || [[ "$OS_LIKE" =~ (rhel|fedora) ]]; then
echo "RHEL-based"
sudo dnf purge firefox
elif [[ "$OS_ID" =~ (debian|ubuntu|linuxmint) ]] ||
[[ "$OS_LIKE" =~ debian ]]; then
echo "Debian-based"
sudo apt -y purge firefox && sudo apt autoremove -y
else
echo "Unknown Linux distribution: $PRETTY_NAME"
fi
# Fallback for older systems without /etc/os-release
elif [[ -f /etc/redhat-release ]]; then
echo "RHEL-based"
sudo dnf purge firefox
elif [[ -f /etc/debian_version ]]; then
echo "Debian-based"
sudo apt -y purge firefox && sudo apt autoremove -y
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "Mac OSX"
if brew list --cask | grep -q "^firefox$"; then
brew remove -f firefox
brew cleanup --prune=all
fi
else
echo "Unable to determine OS type"
fi
for dir in "${locations[@]}"; do
if [ -d "$dir" ]; then
rm -Rfv "$dir"
fi
done
# Delete Empty Files/Directories - Current Directory/SubDirectories
# Delete empty files
find $HOME -depth -empty -type f -delete
# Remove .DS_Store and more files before delete empty directories so it actually removes empty directories
find $HOME -depth \( -name "Thumbs.db" -o -name "desktop.ini" -o -name "error_log" -o -name ".DS_Store" -o -name "._*" -o -name "SyncToy*.dat" -o -name "Picasa.ini" \) -type f -exec rm -rfv {} \;
# Remove empty files in general before delete empty directories
find $HOME -depth -empty -type f -exec rm -rfv {} \;
# Delete empty directories
#find . -depth -empty -type d -delete
find $HOME -depth -empty -type d -exec rm -rfv {} \;
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.