Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clear cache Microsoft Teams on Linux
#!/bin/bash
# This script cleans all cache for Microsoft Teams on Linux
# Tested on Ubuntu-like and Debian by @necrifede. Feel free to test/use in other distributions.
# Tested with Teams via snap package.
#
# How to use in terminal:
# ./clear_cache_MS_Teams.sh ( deb-stable | deb-insider | snap )
# or
# bash clear_cache_MS_Teams.sh ( deb-stable | deb-insider | snap )
# Variable process name is defined on case statement.
case $1 in
deb-stable)
export TEAMS_PROCESS_NAME=teams
cd "$HOME"/.config/Microsoft/Microsoft\ Teams || exit 1
;;
deb-insider)
export TEAMS_PROCESS_NAME=teams-insiders
cd "$HOME"/.config/Microsoft/Microsoft\ Teams\ -\ Insiders || exit 1
;;
snap)
export TEAMS_PROCESS_NAME=teams
cd "$HOME"/snap/teams/current/.config/Microsoft/Microsoft\ Teams || exit 1
;;
*)
echo "Use $0 ( deb-stable | deb-insider | snap) as parameter."
exit 1
;;
esac
# Test if Microsoft Teams is running
if [ "$(pgrep ${TEAMS_PROCESS_NAME} | wc -l)" -gt 1 ]
then
rm -rf Application\ Cache/Cache/*
rm -rf blob_storage/*
rm -rf Cache/* # Main cache
rm -rf Code\ Cache/js/*
rm -rf databases/*
rm -rf GPUCache/*
rm -rf IndexedDB/*
rm -rf Local\ Storage/*
#rm -rf backgrounds/* # Background function presents on Teams for Windows only.
find ./ -maxdepth 1 -type f -name "*log*" -exec rm {} \;
sleep 5
killall ${TEAMS_PROCESS_NAME}
# After this, MS Teams will open again.
else
echo "Microsoft Teams is not running."
exit
fi
@fredrikljung93

This comment has been minimized.

Copy link

@fredrikljung93 fredrikljung93 commented Jan 5, 2021

This script just helped me out when I had problems switching to a newly added organization and worked like a charm for me on Ubuntu 20.04! Thanks!

@mrcomoraes

This comment has been minimized.

Copy link
Owner Author

@mrcomoraes mrcomoraes commented Jan 6, 2021

This script just helped me out when I had problems switching to a newly added organization and worked like a charm for me on Ubuntu 20.04! Thanks!

Glad to help you.

@necrifede

This comment has been minimized.

Copy link

@necrifede necrifede commented Jan 10, 2021

same here, thank you... log out of teams were not working on teams, but thanks to your script I am able to change user, I am using Debian 10

@mrcomoraes

This comment has been minimized.

Copy link
Owner Author

@mrcomoraes mrcomoraes commented Jan 12, 2021

same here, thank you... log out of teams were not working on teams, but thanks to your script I am able to change user, I am using Debian 10

Thanks for your feedback. I will update script comment.

@felixvuo

This comment has been minimized.

Copy link

@felixvuo felixvuo commented Jan 19, 2021

Massive help, thank you. I was getting notifications about activity in "teams"(channels) where I was a guest, but the actual posts were not showing up. This cache clearing has sorted it :-D

@leflamm

This comment has been minimized.

Copy link

@leflamm leflamm commented Jan 27, 2021

Tiny remark.. depending on wich teams version you are using it might alternatively be called "teams-insiders". Thx!

@mrcomoraes

This comment has been minimized.

Copy link
Owner Author

@mrcomoraes mrcomoraes commented Jan 27, 2021

Tiny remark.. depending on wich teams version you are using it might alternatively be called "teams-insiders". Thx!

teams-insiders I have not tested. Is it change process name, @leflamm ?

@leflamm

This comment has been minimized.

Copy link

@leflamm leflamm commented Jan 27, 2021

@mrcomoraes, yes, the process name is different ("teams-insiders"), the directory names are still the same. Cheers!

@mrcomoraes

This comment has been minimized.

Copy link
Owner Author

@mrcomoraes mrcomoraes commented Jan 27, 2021

@mrcomoraes, yes, the process name is different ("teams-insiders"), the directory names are still the same. Cheers!

Nice! I have updated script to modify process name. Thx @leflamm

@rmharrison

This comment has been minimized.

Copy link

@rmharrison rmharrison commented Mar 15, 2021

Thank you!

@mrcomoraes A comment on what's stored in the various cache directories may be useful, e.g.

rm -rf Local\ Storage/* # Password screen cached here
@artemkozlenkov

This comment has been minimized.

Copy link

@artemkozlenkov artemkozlenkov commented Mar 25, 2021

works well, just a short readme.md would be nice to have to get started

@dg1223

This comment has been minimized.

Copy link

@dg1223 dg1223 commented Mar 28, 2021

Awesome script. Works like a charm!

@hilsestroeer

This comment has been minimized.

Copy link

@hilsestroeer hilsestroeer commented Mar 29, 2021

Works on Linux Mint 19.3 Cinnamon as well! Thank you very much!

@mrcomoraes

This comment has been minimized.

Copy link
Owner Author

@mrcomoraes mrcomoraes commented Mar 30, 2021

@artemkozlenkov I added some comments explaining how to use. I hope helped.

@jtmackoy

This comment has been minimized.

Copy link

@jtmackoy jtmackoy commented Apr 5, 2021

@mrcomoraes - check out my fork, I've added support for the Insiders build of MS Teams via DEB install. There's a snap for that too, but I don't use it and haven't accounted for it in my revisions.

@armujahid

This comment has been minimized.

Copy link

@armujahid armujahid commented Apr 6, 2021

Why do we need to run teams before using this script? Cache clearing should work even if teams isn't running. BTW awesome work 👍

@mrcomoraes

This comment has been minimized.

Copy link
Owner Author

@mrcomoraes mrcomoraes commented Apr 6, 2021

@armujahid
In past, when I run clear cache script with MS Teams closed, it's removed auth and names of the chats, staying only IDs instead names.
So I read some MS Teams on Windows forums and they run clear cache scripts for Windows with Teams running.

@mrcomoraes

This comment has been minimized.

Copy link
Owner Author

@mrcomoraes mrcomoraes commented Apr 6, 2021

Good fork, @jtmackoy . I have made some improvements for change process name variable during case statement.

@IbanMM

This comment has been minimized.

Copy link

@IbanMM IbanMM commented May 24, 2021

Thank you!! Very useful

@NicoBoos

This comment has been minimized.

Copy link

@NicoBoos NicoBoos commented Jun 1, 2021

Perfect, thank you! 👍
It improved the search performance. Waiting to see if it also fixes the unexpected crashes during calls and screen shares.

@Nevindus

This comment has been minimized.

Copy link

@Nevindus Nevindus commented Jul 18, 2021

How do i make this script work, can someone guide me the process to do it

@mrcomoraes

This comment has been minimized.

Copy link
Owner Author

@mrcomoraes mrcomoraes commented Jul 21, 2021

@Nevindus you can read the comments in script starting on line 8.

@vigneshragupathy

This comment has been minimized.

Copy link

@vigneshragupathy vigneshragupathy commented Sep 15, 2021

Thanks, I was trying to signout from my inactive work account. Even after reinstalling teams i landed up in same old signin page. This script helped me to clear cache and switch to new account in Linux.

@peter279k

This comment has been minimized.

Copy link

@peter279k peter279k commented Sep 23, 2021

Thanks for your useful shell script! It's very helpful for me to reset my teams settings!

@jayora

This comment has been minimized.

Copy link

@jayora jayora commented Oct 7, 2021

Thanks, the script is easy and fantastic

@raddevus

This comment has been minimized.

Copy link

@raddevus raddevus commented Oct 18, 2021

Thanks for the script. I was having issues after upgrading to Ubuntu 21.04 (from 20.04).
Just adding some notes for others -- in case they see the issues similar to mine.
The app would load but never showing any chat messages.
I ran this script multiple times and saw the files were deleted, however, it never would show the messages.
finally, I ran the script and cleared everything and uninstalled and re-installed Teams and it finally worked.

@ngandrass

This comment has been minimized.

Copy link

@ngandrass ngandrass commented Oct 19, 2021

Thank you for the script. Saved my day 👍

@ms0ft-git

This comment has been minimized.

Copy link

@ms0ft-git ms0ft-git commented Nov 18, 2021

It works perfectly, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment