xxx

Saturday 12 March 2022

Making the .cache folder a temporary folder under linux

HDD and Memory chip

 A lot of people complain about the size of the ~/.cache folder and many people ask if the folder can be deleted. The answer is "Yes, with some caveats". If that folder can be deleted, why is it a permanent folder and not a temporary one?

The answer usually is "Because storage space is cheap and computing power isn't". And that is a good answer. However, that is only valid if you are accessing the same files over and over day after day. For most of us, we do different things every day, browse different websites, see different pictures, read different emails, etc. So new files are cached and the old ones remain just taking space.

Here I will show two ways to make the .cache folder temporary: Deleting old files regularly and storing the .cache folder in ram.

Neither of these methods require sudo or root access. However, they require that you use systemd.

In reality you could use this method to make any other folder temporary, for example,  a user's temp folder or the Downloads folder.


Delete old files regularly

Advantages

  • The folder does not keep ballooning

Caveats

  • If you have an application which incorrectly assumes .cache is permanent, it may malfunction
  • If you have an application which generates a lot of cache files for things that you regularly use it may take a bit more time (usually negligible), next time it needs the files as it needs to recreate them.

How to cleanup .cache regularly

Get the user identifiers by executing 

 id

Create a file under ~/.local/share/user-tmpfiles.d with a rule to clean up the folder at a particular interval, for example, every week. Replace <uid>, <groupname> and <username> with the numeric user DI, the user group and the user name respectively.

mkdir -p ~/.local/share/user-tmpfiles.d
echo "D /run/user/<uid> /cache 0700 <groupname> <username> 1w" > ~/.local/share/user-tmpfiles.d/cachetmp.conf

For example, to clean john's cache every week:

mkdir -p ~/.local/share/user-tmpfiles.d
echo "D /run/user/1000 /cache 0700 john john 1w" > ~/.local/share/user-tmpfiles.d/cachetmp.conf

Note: You can find more information about the parameters in the tmpfiles.d man page 

man tmpfiles.d

Enable and start the cleanup service

systemctl --user enable systemd-tmpfiles-clean.timer
systemctl --user start  systemd-tmpfiles-clean.timer

And that's it.

 

Storing the .cache folder in ram

Advantages

  • Browsing is faster as all files are cached in memory
  • If you use SDD, it doesn't wear that much
  • If you use HDD, it doesn't trash the disk that much
  • It extends your battery time as HDD usage is reduced
  • The folder doesn't keep growing with crud from previous sessions as all the files are gone when the computer shuts down.
  • Increased privacy. All the cached files are gone when you shutdown. This includes thumb images.

Caveats

  • If a program caches large files you may consume your ram. This may not be noticeable most of the time but you need to be aware of it
  • If you have an application which incorrectly assumes .cache is permanent, it may malfunction
  • All the If you have an application which generates a lot of cache files for things that you regularly use it may take a bit more time (usually negligible), next time it needs the files as it needs to recreate them. Given that the files are stored in ram, generation is usually very fast.

How to create the .cache folder in ramdisk

Get the user identifiers by executing 

 id

 Create a file under ~/.local/share/user-tmpfiles.d with a rule to create the folder and clean it up at a particular interval, for example, every week. (the cleanup is only necesary if you don't reboot your computer frequently. Replace <uid>, <groupname> and <username> with the numeric user DI, the user group and the user name respectively.

mkdir -p ~/.local/share/user-tmpfiles.d
echo "D /run/user/<uid>/cache 0700 <groupname> <username> 1w
L+ /home/<username>/.cache - - - - /run/user/
<uid>/cache" > ~/.local/share/user-tmpfiles.d/cachetmp.conf

For example

echo "D /run/user/1000/cache 0700 john john 1w
L+ /home/john/.cache - - - - /run/user/1000/cache" > ~/.local/share/user-tmpfiles.d/cachetmp.conf

Note: You can find more information about the parameters in the tmpfiles.d man page

man tmpfiles.d

For example, the age parameter can be a number and ms,mu,s,m,h,d,w for miliseconds, microseconds, seconds, minutes, hours, days and weeks.

Enable and start the creation and cleanup services

systemctl --user enable systemd-tmpfiles-setup.service systemd-tmpfiles-clean.timer
systemctl --user start  systemd-tmpfiles-setup.service systemd-tmpfiles-clean.timer

 

Restoring the .cache folder to it's original state

If an application is giving you trouble or find that your cache is using all your memory, you just need to disable the services and delete the cachetmp.conf file

systemctl --user stop    systemd-tmpfiles-setup.service systemd-tmpfiles-clean.timer
systemctl --user disable systemd-tmpfiles-setup.service systemd-tmpfiles-clean.timer
rm ~/.local/share/user-tmpfiles.d/cachetmp.conf

If at next boot the .cache folder is not created, just create it manually.

And that's it.

Read More

Sunday 17 January 2021

The falacy of the mythical grandma

(Image courtesy of Wikimedia shared under the Creative Commons Attribution 2.0 Generic license)
 

There is a very common phenomenon occurring, mostly, with people who are new-ish to Linux. They love  Linux but given that they are new, they think it's hard.

 

They envision a version of Linux that is "Easy enough for Grandma".

 

I dislike this phrase with passion.

 

Why "Grandma" and not "Grandpa"? 

There is blatant sexism of the phrase. 

Somehow Grandma is less knowledgeable, less experienced or plainly less intelligent. It gives me the impression that, whoever says that, gives her Grandma an blender so she can be happier in the kitchen. It assumes that Grandpa will just "get it" and Grandma can't possibly do it. I know situations where it is the other way around.

 

Why "Grandma" and not "Children"?

There is blatant ageism in the phrase.

It is 2020, computers have been around for decades. By now, many women who are Grandmas have had successful careers using computers. But many have other interests that have nothing to do with computers.

 

Why "easy for Grandma" and not "easy for you"?

There is blatant smugness in the phrase.

Somehow the person saying that phrase "got it" as a new user. Was able to install Linux and use it, but other people couldn't possible "get it", right? They must be above average intelligent.

 

Maybe it is not about being a Grandma but about being interested in computers. My mom claimed to be a technophobe. At 60 I gave her a laptop and configured it with three buttons, one for the browser, one for the email and another to shut down. Well, she was not interested in browsing things or emailing people (I live in Canada, she lives in Mexico). That laptop just collected dust.

 

However, at 78, my mother, who is a very social person, got her first smart phone. She still does not browse or send emails but she uses Facebook, Messenger, Whatsapp and the camera because that's what her friends and family use. She is 83 now and still using her smart phone, initiating and answering video calls to me and her grand children.

 

I know other grandmas who like to write and have learned to use the computer to open the text editor and write to their hearts content. Even publish books.

 

So, give more credit to grandmas and more credit to Linux.

There are distributions who are usable with little training by non-technical users. If they don't use the computer is usually because they don't want to. Not because they can't.

 


Read More

Saturday 16 January 2021

Guide: A safe, clean and easy way to update LinuxMint



From all the general usage Linux desktop distribution, my favourite one is Linux Mint. In all my set-ups it seems to just work.

 

However, one of the main concerns is that it is not a rolling release, so to get to the latest version one needs to do a full upgrade.

 

This can be achieved in two ways

  1. Do an upgrade in place using the tools provided by the distribution. While this method works well most of the time. Sometimes there are big breaking changes, when moving between different Ubuntu bases but also minor annoyances for simpler releases.
  2. Do a clean installation. Some people don't like this option because they need to reconfigure their whole OS.

For many releases now, I have used a solution which gives me mostly the best of both worlds. One that gives me all the benefits of installing from scratch and at the same time allows me to keep all my settings and applications. This solution also minimizes my down time in case of I find an issue.


Here is what I do:

 

I have a partition setup that allows me to follow this method release after release, among other benefits.

  • 20 GB btrfs root partition. You may choose a larger size if you install lots of apps.
  • Separate ext4 /home large partition
  • One 20 GB spare partition for distro-hopping. You may choose a larger size if you install lots of apps.

When it's time to upgrade:

  1. Backup my list of apps (using the LinuxMint backup application).
  2. Update or disable applets and extensions that have known issues in the new version of LinuxMint .
  3. Install the new version in the spare partition reformatting it and selecting to use the existing  /home partition.
  4. Boot into the new version and verify if it works OK.
  5. Restore my applications using the backed up application list. (Using the backup app).
  6. Reinstall any flatpaks I may have installed before and "make install" anything I may have installed from source.

From beginning to end, 30 minutes, all my apps and settings exactly as the previous version.

 

If I find an issue with the new version I have two options

  • If I am pressed for time to use my computer, I restore grub to point to the previous version and I am up and running in a few minutes.
  • If I have time to troubleshoot, most of the time the easiest solution is to backup and remove some .config files which may have incompatible settings.

After I'm comfortable, I wipe-out and repurpose the "original" partition for distro-hopping until the next time I want to upgrade.


Read More
© 2014 Using FOSS. Designed by Bloggertheme9
Powered by Blogger.