Blog → Post


(NEWS) Recovering Space, Part 2
Additional things to check for, when trying to free-up disk space on Linux.
by @admin, september 11, 2024, 11:15am utc

This post builds on our prior "Recovering Space" post, which can be found (here).

A summary of the steps covered in the first article is:
  1. Clean Log File Folder
  2. Trim Email Logs
  3. Pare Fail2ban Database
  4. Remove Archive (.deb) Files
  5. Run QDirStat, ncdu
  1. First, we'll add a couple of CLI commands for our previous step 4, "Archive (.deb) file cleanup".

    Here is how to clear the deb cache (container packages of installed or upgraded apps) and delete everything from /var/cache/apt/archives/ where they are kept.

    102K Feb 25 2022 libsasl2-modules_2.1.27+dfsg-2.1+deb11u1_amd64.deb 68K Feb 25 2022 libsasl2-modules-db_2.1.27+dfsg-2.1+deb11u1_amd64.deb 48K Dec 11 2021 libseccomp2_2.5.1-1+deb11u1_amd64.deb 154K Jan 22 2022 libsmartcols1_2.36.1-8+deb11u1_amd64.deb 1.5M Mar 14 2022 libssl1.1_1.1.1k-1+deb11u2_amd64.deb 1.5M Mar 19 2022 libssl1.1_1.1.1n-0+deb11u1_amd64.deb 1.5M May 10 2022 libssl1.1_1.1.1n-0+deb11u2_amd64.deb 1.5M Jun 25 2022 libssl1.1_1.1.1n-0+deb11u3_amd64.deb 1.5M Feb 7 2023 libssl1.1_1.1.1n-0+deb11u4_amd64.deb 1.5M May 29 2023 libssl1.1_1.1.1n-0+deb11u5_amd64.deb 368K Mar 21 2022 libsystemd0_247.3-7_amd64.deb 367K Aug 28 2022 libsystemd0_247.3-7+deb11u1_amd64.deb 368K Apr 7 2023 libsystemd0_247.3-7+deb11u2_amd64.deb 54K Nov 26 2022 libtasn1-6_4.16.0-2+deb11u1_amd64.deb 333K Feb 23 2023 libtinfo6_6.2+20201114-2+deb11u1_amd64.deb
    figure — example portion of archive package files.

    The sudo apt clean or sudo apt-get clean command clears the /var/cache/apt/archives/ directory of retrieved package files, except for the lock file.

    OR

    sudo apt-get autoclean

    Like clean, autoclean clears out the local repository of retrieved package files. but only of the package files that can no longer be downloaded. This lets you keep packages to roll back to, or otherwise use offline.



  2. Image Thumbnails

    Your system (largely the file managers) creates and stores thumbnail (small-sized) versions of photos, album covers and other images.

    These thumbnails greatly speed up opening the file managers, but as you can imagine, the number, and total file size of these thumbnails can accumulate quickly.

    The folder that these are stored in ~/.cache/thumbnails and you can safely remove them to save space. The thumbnails will be recreated, as needed.

    $ du -ch ~/.cache/thumbnails 41M /home/user/.cache/thumbnails/large 20M /home/user/.cache/thumbnails/normal 180K /home/user/.cache/thumbnails/fail/mate-thumbnail-factory 88K /home/user/.cache/thumbnails/fail/gnome-thumbnail-factory 272K /home/user/.cache/thumbnails/fail 61M /home/user/.cache/thumbnails 61M total

    As you may guess, start with /large. The most disk space will be used by this thumbnail subfolder.

  3. jdupes jdupes is a forked and much faster version of fdupes, a utility to find duplicate files on your system. jdupes is up to 7x faster than fdupes. Both of these utilities allow you to delete any duplicates; or you can redirect the results into a text file, so that you can more selectively choose what to delete. For more jdupes info, run:
    apt show jdupes

    To use jdupes:

    sudo apt install jdupes jdupes [first folder or drive to check] [opt. additional folder or drive to check] [etc]

    For example:

    # First, list out the connected drives. sudo df -h Filesystem Size Used Avail Use% Mounted on /dev/sdc1 4.6T 4.5T 17G 100% /media/user/Current Work /dev/sdd2 4.6T 4.5T 104G 98% /media/user/One Touch /dev/sdb1 1.9T 1.8T 55G 98% /media/user/Seagate Backup Plus Drive
    # Now run jdupes to find matching files. # This will look for duplicates across /dev/sdc1 (.)and /dev/sdd2 # -S was added to show the size of duplicate files. # -r --recurse to look in every sub-directory.

    jdupes -S -r /m/b/C* /m/b/O*
    852882 bytes each: ./IMG_20110310_205619.jpg ./NIKON-Pictures (back-up)/DCIM/Camera/IMG_20110310_205619.jpg ./NIKON-Pictures (back-up)/2015/backups/IMG_20110310_205619.jpg
    3243133 bytes each: ./2024/06/IMG_20240612_125030915.jpg ./2024/Moto Photos/IMG_20240612_125030915.jpg
    3797570 bytes each: ./2024/09/IMG_20240326_190436955_HDR.jpg ./2024/Moto Photos/IMG_20240326_190436955_HDR.jpg

    Finally, pick the files from those shown to delete using rm.

    Sadly, while you can sort by modified date or filename, jdupes does not let you sort by Size. We will add sorting to jdupes in an upcoming post. (edit. see: jdupes.sh)


  4. systemd journal entries

    systemd can store GBs of past binary journal entries in /var/log/journal/. These files are used by admins to figure out system issues. You generally only need to keep the most recent ones around. The rest can be removed.

    To see how much space these journal files are currently using, run:

    sudo journalctl --disk-usage Archived and active journals take up 213.9M in the file system.
    or
    du -sh /var/log/journal 215M /var/log/journal

    To cut down the number of journal files, run these steps.

    1. mark the currently active journal logs as "archived" and create brand new logs.
      sudo journalctl --rotate
    2. This will keep just the last 3 weeks (3w) of journal entries.
      sudo journalctl --vacuum-time=3w

      You can vary the number and the length-of-time of files to keep. e.g. 2w saves 2 weeks worth of journal files, or 2d (2 days) worth, or 30m (30 minutes) worth.

    Going forward, you can alter systemd's journal configuration to automatically keep a smaller number of journal files.

    To do so: Make a backup of the journal config and edit the file.

    sudo cp /etc/systemd/journald.conf /etc/systemd/journald.conf.back

    sudo nano /etc/systemd/journald.conf

    Uncomment (remove the '#') from one of these two settings. We recommend SystemMaxUse=500M to always retain the most recent 500MB of journal entries.

    [Journal] Setting Description
    \# SystemMaxUse Max disk space logs can take
    \# SystemMaxFiles Max number of log files

    Save the config file and restart journaling to reload the changed config:

    sudo systemctl restart systemd-journald
    You can also change a parameter in the config file from the command line, with sed.

    sudo sed -i 's/#SystemMaxUse=100M/SystemMaxUse=500M/g' /etc/systemd/journald.conf

    For more info on journal files, see https://linuxhandbook.com/clear-systemd-journal-logs/.




     

  5. tune2fs

    If you are working with a large hard drive, this one will probably get back the most space of anything in this article.

    By default, Linux drives use the EXT file system. Also by default, EXT reserves 5% of the disk space to itself. This was done to give administrators some room to work if a system ran out of space. The amount 5% was chosen back when hard drives were very small but today, with TB-size drives, 5% represents a large chunk of space. For example, 5% of a 5TB drive is around 250GB.

    BEFORE tune2fs
    /dev/sdb1 4.6T 28K 4.6T 1% /media/user/5TB
    AFTER tune2fs
    /dev/sdb1 4.6T 28K 4.3T 1% /media/user/5TB

    First, get the list of partitions:
    df -h

    Next, use tune2fs with grep to see if blocks are reserved on your EXT drives. Replace /dev/sdb2 below with your device.
    sudo tune2fs -l /dev/sdb2 | grep 'Reserved'

    Reserved block count: 0
    Reserved GDT blocks: 1024
    Reserved blocks uid: 0 (user root)
    Reserved blocks gid: 0 (group root)

    Finally, run tun2fs and set the number of reserved blocks to 0.

    sudo tune2fs -m 0 /dev/sdb2

    tune2fs 1.46.2 (28-Feb-2021)
    Setting reserved blocks count to 0
  6. Lastly, and perhaps obviously, don't forget to empty the trash. You can sometimes accumulate GBs of deleted files in there.

    Empty the Trash


reference links:
* du file space
* df report file space
* sed stream editor
* rm remove files or directories
*
GNU Core Utilities
* GNU Software

See also,
Recovering Space
Recovering Space, Part 2 (this file)
Recovering Space, Part 3: jdupes.sh
tags: All users, News
Footer done in Inkscape