Clean .com.google.Chrome.* in /tmp
Recently, I found there were huge amount of files named
.com.google.Chrome.*
be created in my /tmp folder.
Obviously the culprit is Chrome. However, after some research no
solution is found to prevent Chrome creating these garbage.
/tmp$ du -csh .com.google.Chrome.*
8.0K .com.google.Chrome.00OKwD
104K .com.google.Chrome.013jYf
172K .com.google.Chrome.015x5t
...
48K .com.google.Chrome.Zytrhf
16K .com.google.Chrome.zz233G
36K .com.google.Chrome.ZzrsZY
163M total
/tmp$ find /tmp -name ".com.google.Chrome*" -ls| wc -l
3468
Update 2020/12/12 I found there are lots of
.com.google.Chrome.*
files in
/tmp/snap.chromium/tmp
:-( . Look at the
ncdu
results:
--- /tmp/snap.chromium/tmp -------------------------------------------------------------------------
/..
4.1 MiB [##########] /.com.google.Chrome.xTBobr
4.1 MiB [######### ] /.com.google.Chrome.0hcsFR
4.0 MiB [######### ] /.com.google.Chrome.YdhzL5
4.0 MiB [######### ] /.com.google.Chrome.nJ5W3A
4.0 MiB [######### ] /.com.google.Chrome.unS6es
...
Total disk usage: 6.8 GiB Apparent size: 12.1 GiB Items: 482530
Now the cleanup script has been
updated.
The listed files were created within two days! Looks that it's harmless, huh? Definitely NOT! By default, Linux will cleanup the /tmp at boot. If your system is rarely reboot:
- These files might make your disk full
- Huge amount of files in /tmp will block your system boot
Refer to this post: # A start job is running for Create Volatile Files and Directories
Therefore, I have to make a cron job to automatically cleanup /tmp
periodically. The cleanup script cleanuptmp.sh
:
#!/bin/bash
find /tmp -name ".com.google.Chrome*" -mtime +0.5 -exec rm -r {} \;
find /tmp/snap.chromium/tmp -name ".com.google.Chrome*" -mtime +0.5 -exec rm -r {} \;
The script will delete all .com.google.Chrome* directories with last modify time 12 hours before.
Since the /tmp/snap.chromium/tmp
folder has
restricted deletion flag
t
:
$ sudo ls -al /tmp/snap.chromium/
...
drwxrwxrwt 887 root root 1114112 Dec 12 11:40 tmp
We need to add a cron job entry to root
user by
sudo crontab -e
:
15 10,22 * * * /home/xxx/cleanuptmp.sh
It will cleanup the /tmp
at 10:15 and 22:15
everyday.