com.apple.bird/session/g

This is one of the very few non amateur radio related items on this site.  I’m posting it because it’s a useful tip and I hope that it will assist fellow Mac users.

I noticed about three years ago that a particular cache folder on my iMac was getting larger and larger.  I did some research on this and finally was able to track down where it comes from and what’s causing it.  It only affects people who are using WhatsApp on an iPhone with backup to iCloud enabled.

WhatsApp uses a cache folder in your library whenever it does a backup to iCloud and it doesn’t tidy up properly after itself.  When I bought a MacBook late last year, I forgot to do anything about this cache and when I remembered and checked, the folder had grown to over 50Gb!  It’s just wasted space and it’s perfectly OK to delete it.

Your library folder is hidden by default but you can easily check it by opening Finder, clicking on Go in the menu bar and then holding down the option (alt) key.  This will cause Library to show in the list below, click on it and then work your way into Caches, then com.apple.bird, then session and finally g.

For the last year or so, I’ve run some AppleScript to tidy this folder up on a regular basis and I’ve experienced no problems whatsoever doing it.  Everything still works properly, I just have a folder which doesn’t grow every time WhatsApp does a backup.   After I took delivery of a new iMac a few weeks ago, I decided to clean this cache in a different way (partly because I couldn’t remember how to get it working with launchd).

I’ve written a short script which I run via cron.

To do this is very easy.  I’ll show you how to create a scripts folder, change to that folder, write a simple script and then how to add a cron job to run that script on a regular basis.  I’m sure there are other ways to do this but this method is simple and it works.

Be careful when you do this.  You’re going to be using a Unix command which can be very nasty if you get it wrong.  Providing you check and double check everything, you should be OK.  I will take no responsibility for trashed systems if you make a mistake.  Always have a backup before you do this sort of thing.

Open a terminal and type the following commands:

cd documents
mkdir scripts
cd scripts
sudo nano delete-cache.sh

Your Mac will now offer you a “Password:” prompt. Type the password for your account and you’ll be presented with a blank window like this:

Nano editor window

Nano editor window

Copy the following text and paste it in the editor window, making sure you change “your_home_folder” to be the name of your home folder.

#!/bin/bash
cd /users/your_home_folder/library/Caches/com.apple.bird/session
rm -rf g

Mine looks like this:

My script to delete the unwanted com apple bird session g folder

My script to delete the unwanted com apple bird session g folder

Press control-x then y and finally hit the enter key to save the file.

Now type the following:

sudo chmod +x delete-cache.sh

This is to make the script executable. You may be asked for your password again.

Finally, you need to edit cron to execute this script on a regular basis.  My iMac is never switched off so I run it once a day in the early hours of the morning.  If there’s a time you know your computer is likely to be switched on then you can change the time.  It doesn’t matter if it gets missed sometimes.  I like to run it daily just to keep that cache empty.  If you’re not sure when your Mac will be switched on, you could even run it hourly with no problems.  I’ve been deleting this cache on a daily basis for years with no ill effects.

sudo crontab -e

You may be asked for your password again, if so, then enter it.

This time, you won’t be using the nano editor, you’ll be using an editor that can be very powerful but also quite confusing so I’ll be precise.

Press ESC and then the i key.  At the bottom of the screen you should see the word –INSERT–

Type or paste the following, again replacing “your_home_folder” with the name of your home folder as before.

10 2 * * * /users/your_home_folder/documents/scripts/delete-cache.sh

This will run at 02:10 every day.  If you want it to run at a different time then change the first two numbers.  The first number is the minutes past the hour and the second number is the hour.  So if you want it to run at 09:30 every day then the first two numbers will be 30 9

When you have done this press ESC again so that –INSERT– disappears and then hold down the SHIFT key and press Z twice, so SHIFT ZZ

That’s it.  You’ve created a script, edited it, made it executable and configured your Mac to run that script on a regular basis.

If you own more than one Mac and you have your documents folder synced to iCloud then you only need to add the line into cron on the other computers as the script will be shared between them (assuming your user account is the same name on all of them).

2 Comments

Add a Comment
  1. Thanks so much for this, I was looking for a solution to my 46gb Whatsapp com.apple.bird folder. One question.. is it possible to run the script manually to check it works before adding to cron? If I just type ‘delete-cache.sh’ into terminal I get ‘command not found’

    Ta

    1. Hi Paul,

      To run it manually you need to add ./ before the command.
      So when you’re in the terminal, you need to type

      ./delete-cache.sh

      Hope that helps.
      Keith

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.