Skip to content

Instantly share code, notes, and snippets.

@sxiii
Last active March 8, 2024 17:41
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sxiii/674ccd0cbefe25b240e9ef4955442c73 to your computer and use it in GitHub Desktop.
Save sxiii/674ccd0cbefe25b240e9ef4955442c73 to your computer and use it in GitHub Desktop.
Remove Unnecessary Locales Fedora

Small guide that helps to free up space by removing unneccessary locales from Fedora
With some additional information on how to make more space on your system (advices in the end)
Tried on Fedora 34, but should work on other distros as well (RPM-Based?)

Step 0. Bonus step -- check available space before procedure:

df -lh

Step 1. Enter the locales directory

cd /usr/share/locale/

Step 2. Check that there is files to remove

ls

Previous step should show a lot of directories.

Step 3. Create temporary storage for locales YOU NEED (we'll move away locales WE NEED)

mkdir /tmp/locales

Now, you need to decide which locales you need to save.
We'll move them to another place, so we don't delete them.
I decided to save all EN* locales as well as RU* (Russian)
Add locales you want to save to the command below (after en* and/or instead of ru*)

Step 4. Temporary move away the locales you want to save to another place

sudo mv en* ru* locale.alias /tmp/locales

Step 5. Remove all left-over locales that we don't need (be very careful with this command!)

This command removes all files in current directory.
sudo rm -rf ./*

Step 6. Move locales back (there is dot in the end of this command!)

sudo mv /tmp/locales/* .

Step 7. Bonus step -- check available space after procedure:

df -lh

Now you should have more space on your HDD/SSD!

Other advices

  • Additionally, it should be pretty safe to remove all files from /var/tmp/* as well as /tmp/*:
    rm -rf /var/tmp/* /tmp/*
  • If you have Docker installed, you can remove unused containers as well: docker system prune -a
  • You can clear additional space by removing older parts of system journal: sudo journalctl --vacuum-size=100M
  • Clean DNF packages with: sudo dnf clean packages
  • You can install additional GUI tool called bleachbit to clean up more space (however, check what you remove with it, it can remove some useful stuff too): sudo dnf install bleacnbit && sudo bleachbit
  • Very important tool to clean up some space is Baobab: sudo dnf install baobab && sudo baobab
@GogoFC
Copy link

GogoFC commented May 14, 2023

Skipped Step 6. by accident

@ilioni
Copy link

ilioni commented May 18, 2023

Step 1.
sudo rm /usr/share/locale/!(ru*|en*|*alias)
Step 2.
sudo sed -i 's/%_install_langs.*all/%_install_langs ru:en/g' /usr/lib/rpm/macros


 #   A colon separated list of desired locales to be installed;
 #   "all" means install all locale specific files.
 #   
 %_install_langs all
   

@PasaOpasen
Copy link

find /usr/share/locale \
    -not -name "ru" -not -name "ru_*" \
    -not -name "en" -not -name "en_*" -not -name "en@*" -delete

@c-tamias35
Copy link

c-tamias35 commented Dec 20, 2023

One-step example
To only print directories to be deleted ("dry-run") :

find /usr/share/locale/* \
    -maxdepth 0 \
    -type d \
    -not -iname "en*" \
    -not -iname "ru*" \
    -exec echo {} \;

To delete for real (add sudo and change the last line of -exec...) :

sudo find /usr/share/locale/* \
    -maxdepth 0 \
    -type d \
    -not -iname "en*" \
    -not -iname "ru*" \
    -exec rm -r {} \;

That won't remove locale.alias file, but only directories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment