http://www.techradar.com/pro/linux March 2020 LXF260 71
Control config files TUTORIALS
In this picture, you
can see the /home
folder file sizes
visualised by the
Gnome disk usage
application. It is
easy to drill down
to see which files
are the largest.
AUTOTRASH – TAKE OUT THE TRASH
you need to dig down with a few more tools. The
command line is your friend when checking sizes
quickly, though Disk Usage Analyzer from Gnome is
great at visualising the disk.
Get to it!
The regular tools to run are du, ranger and ncdu. The
first is the disk usage command native to Linux, the
second a file manager, and finally you have the graphical
version of du. It uses ncurses to make it graphical on the
command line. Except for these tools, you want to use
either rm or a graphical file manager to throw things
away. The command line tool is faster but always
definitive. With the GUI, (Files in Gnome), you have a
Trash bin that you can restore from.
So your mission here is to cut the size of your
home directory without losing functionality or style
of your computing experience. To know if you have
accomplished the mission, you need to know where
you are starting from. Check your configuration files
and the size they use right now.
To see if you are improving anything, you need to
check what you currently have. The best way is to use
the du command:
$ du -csh ~
This shows the sum of all your files in the home
directory, so next you should check what is your own
data and what is configuration. This is usually tedious,
so make sure you know what others are sharing and
look at what they have. You can often clear up a lot of
your questions just by studying others. Use the
--exclude parameter to filter out the files you do not
want to count:
$ du -h --exclude Documents/*
If you want to be very exact, you can create a file that
points to the directories you will not count – your own
files, for example.
You can also use the ncdu package to analyse your
disk to find the large files. Most of your configuration
files are without passwords and other identifying
information, so make sure you watch out for what is in
the cache.
This information can be used to track you and do
other nasty things. Where does this information go? You
have two main places; /etc/, which is for your system
itself, and your home directory. Most files in your home
are dotfiles’ the ones that are hidden with the help of a
dot at the beginning of the name. This is used with
directories too.
Since your system starts outside of your user
directory, begin with your system files. While the
majority of settings are in /etc/, be aware that many
other files exist in /var/ and other parts. Most files in
/var/ contains logs, caches and transient data of other
kinds. If your disk is filling up, investigate this to see if
any of it is too old and is no longer used.
In Linux, the global files are well protected from
corruption and from becoming too big. In your home
directory, you need to be careful, though. Many
applications store cache data here, and not all of them
clean up well after themselves.
To check /etc/, you should look for and compare
what applications you have installed. Because we can
use package managers, this job is easily taken care of
for you.
Nothing is ever flawless, however, so make sure you
can list your applications according to the list we made
earlier and check what files should be there.
Developers have agreed on some standards, so the
majority will be focused in certain sub-directories. The
well-known ones are .config, .cache and .local. Starting
backwards, .local contains Trash, mail and a lot of data
that is shared for Gnome and KDE.
Most browsers will have their cache located in
.cache. You can check this effectively by clearing the
cache and comparing the size of your directory.
Chrome, for example, can clear it with an option in your
browser. It shows you how much you can remove and
also if you want to remove it from only this device or all
of them.
Check your Trash and set your policies. Your desktop
has a standard Trash bin, the Freedesktop standard sets
it to ~/.local/Trash/. Gnome has no special policy to
remove the Trash according to any patterns, so you
have to look at autotrash (see below) for that.
To keep your home directory clean, you may consider autotrash. This
is a handy utility that checks the age and/or filename and erases
according to your settings.
You can run the utility by hand, but more likely you will want to
make a crontab entry that clears the Trash on a regular basis. The
simplest way to use it is to add autotrash -d 30 in your crontab at
regular intervals. This will remove all files that are older than 30 days
from the Trash. You can also choose more carefully how autotrash
does its job. One example is to make autotrash empty the Trash when
there is less than a certain amount of space left on the volume. The
parameter is --max-free to start removing files when you have that
amount of megabytes left on the volume.
Combining this with --min-free, can empty Trash to have at least
that amount left. Finally, you can choose regular expressions to delete
certain files before others. -D or --delete-first tells autotrash to
delete those files first. --delete-first ‘*.\.bak’ will delete all files with
the extension bak first. A good entry in crontab looks like this:
@weekly /usr/bin/autotrash --max-free 4000 --min-free 2048 -d 30
-D ‘.*\.bak’ -D ‘.*\.mpg’
7770March 2 h0rIt’shI’imeol March 2020 LXF260 71
Control config files TUTORIALS
In this picture, you
can see the /home
folder file sizes
visualised by the
Gnome disk usage
application. It is
easy to drill down
to see which files
are the largest.
AUTOTRASH– TAKEOUTTHETRASH
you need to dig down with a few more tools. The
command line is your friend when checking sizes
quickly, though Disk Usage Analyzer from Gnome is
great at visualising the disk.
Get to it!
The regular tools to run are du, ranger and ncdu. The
first is the disk usage command native to Linux, the
second a file manager, and finally you have the graphical
version of du. It uses ncurses to make it graphical on the
command line. Except for these tools, you want to use
either rm or a graphical file manager to throw things
away. The command line tool is faster but always
definitive. With the GUI, (Files in Gnome), you have a
Trash bin that you can restore from.
So your mission here is to cut the size of your
home directory without losing functionality or style
of your computing experience. To know if you have
accomplished the mission, you need to know where
you are starting from. Check your configuration files
and the size they use right now.
To see if you are improving anything, you need to
check what you currently have. The best way is to use
the du command:
$ du -csh ~
This shows the sum of all your files in the home
directory, so next you should check what is your own
data and what is configuration. This is usually tedious,
so make sure you know what others are sharing and
look at what they have. You can often clear up a lot of
your questions just by studying others. Use the
--exclude parameter to filter out the files you do not
want to count:
$ du -h --exclude Documents/*
If you want to be very exact, you can create a file that
points to the directories you will not count – your own
files, for example.
You can also use the ncdu package to analyse your
disk to find the large files. Most of your configuration
files are without passwords and other identifying
information, so make sure you watch out for what is in
the cache.
This information can be used to track you and do
other nasty things. Where does this information go? You
have two main places; /etc/, which is for your system
itself, and your home directory. Most files in your home
are dotfiles’ the ones that are hidden with the help of a
dot at the beginning of the name. This is used with
directories too.
Since your system starts outside of your user
directory, begin with your system files. While the
majority of settings are in /etc/, be aware that many
other files exist in /var/ and other parts. Most files in
/var/ contains logs, caches and transient data of other
kinds. If your disk is filling up, investigate this to see if
any of it is too old and is no longer used.
In Linux, the global files are well protected from
corruption and from becoming too big. In your home
directory, you need to be careful, though. Many
applications store cache data here, and not all of them
clean up well after themselves.
To check /etc/, you should look for and compare
what applications you have installed. Because we can
use package managers, this job is easily taken care of
for you.
Nothing is ever flawless, however, so make sure you
can list your applications according to the list we made
earlier and check what files should be there.
Developers have agreed on some standards, so the
majority will be focused in certain sub-directories. The
well-known ones are .config, .cache and .local. Starting
backwards, .local contains Trash, mail and a lot of data
that is shared for Gnome and KDE.
Most browsers will have their cache located in
.cache. You can check this effectively by clearing the
cache and comparing the size of your directory.
Chrome, for example, can clear it with an option in your
browser. It shows you how much you can remove and
also if you want to remove it from only this device or all
of them.
Check your Trash and set your policies. Your desktop
has a standard Trash bin, the Freedesktop standard sets
it to ~/.local/Trash/. Gnome has no special policy to
remove the Trash according to any patterns, so you
have to look at autotrash (see below) for that.
To keep your home directory clean, you may consider autotrash. This
is a handy utility that checks the age and/or filename and erases
according to your settings.
You can run the utility by hand, but more likely you will want to
make a crontab entry that clears the Trash on a regular basis. The
simplest way to use it is to add autotrash -d 30 in your crontab at
regular intervals. This will remove all files that are older than 30 days
from the Trash. You can also choose more carefully how autotrash
does its job. One example is to make autotrash empty the Trash when
there is less than a certain amount of space left on the volume. The
parameter is --max-free to start removing files when you have that
amount of megabytes left on the volume.
Combining this with --min-free, can empty Trash to have at least
that amount left. Finally, you can choose regular expressions to delete
certain files before others. -D or --delete-first tells autotrash to
delete those files first. --delete-first ‘*.\.bak’ will delete all files with
the extension bak first. A good entry in crontab looks like this:
@weekly /usr/bin/autotrash --max-free 4000 --min-free 2048 -d 30
-D ‘.*\.bak’ -D ‘.*\.mpg’