Using Bleachbit in a shell script


I moved the topic here from the forum at

andrewziem wrote:


Regarding "bleachbit --user xyz" you can try this command

HOME=/home/bob sudo bob --delete firefox.cache

When run as root, that changes the HOME variable to /home/bob, changes to the
user bob, and runs the command.


Thanks for the suggestion. I hadn't got round to trying out the CLI until now.

I set up a shell script as follows:

cd $HOME
bleachbit --delete evolution.cache
bleachbit --delete firefox.cache
bleachbit --delete evolution.cache
bleachbit --delete firefox.cache

etc ...

It works well, although it's a little slow (I didn't need to set the user and I probably don't need the cd $HOME), but it was a little complicated to set up. I took the entries from the various .config/bleachbit/bleachbit.ini's and edited them. This means that if bleachbit.ini changes I have to alter my script accordingly. I could have probably parsed the bleachbit.ini automatically and done the calls to bleachbit in a loop but my skills don't go that far. Maybe I really should learn more about scripting ;-)

I can live with this but it would be nice if I could just say

bleachbit --user xyz
bleachbit --user abc

and have bleachbit do it all for me. I live in hope.

Thanks again for all your effort.

I finally got to try this myself :) and this simpler command works

sudo -H -u nicklord bleachbit --preview firefox.cache

The -H sets the home environment variable and -u sets the username. Do you want to modify bleachbit.ini so each user has the same preferences as root?

BTW, you can use HTML <blockquote>blah blah</blockquote> to quote.

Andrew, lead developer

The problem is not that I need to set the username. If I'm running as root I don't need to do this. It works if I just set the home environment variable. What I find tedious is that I have to call BleachBit for each cleaner I want to use for each user, instead of calling BleachBit once for each user and BleachBit using each user's bleachbit.ini file to call the cleaners that the user has checked, so that cleaning is done on an individual basis for each user - not all my users use Firefox or Beagle, for example, so I could save time by not cleaning those for those particular users. This is a "nice to have" rather than a "must have" as I can work around the problem. I just thought it would be a nice feature.

Thanks Andrew. My wish has been fulfilled with the --preset option in Version 0.8.7. Nice work!