Skip to content

Instantly share code, notes, and snippets.

@mrcomoraes
Last active May 10, 2024 12:07
Show Gist options
  • Save mrcomoraes/c83a2745ef8b73f9530f2ec0433772b7 to your computer and use it in GitHub Desktop.
Save mrcomoraes/c83a2745ef8b73f9530f2ec0433772b7 to your computer and use it in GitHub Desktop.
Clear cache Microsoft Teams on Linux
#!/bin/bash
# This script cleans all cache for Microsoft Teams on Linux
# Tested on Ubuntu-like, Debian by @necrifede, Arch Linux by @lucas-dclrcq and Manjaro with flatpak by @danie1k. Feel free to test/use in other distributions.
# Tested Teams via snap package.
# Tested Teams via flatpak package.
#
# How to use in terminal:
# ./clear_cache_MS_Teams.sh ( deb-stable | deb-insider | snap | flatpak )
# or
# bash clear_cache_MS_Teams.sh ( deb-stable | deb-insider | snap | flatpak )
# 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
;;
flatpak)
export TEAMS_PROCESS=teams
cd "$HOME"/.var/app/com.microsoft.Teams/config/Microsoft/Microsoft\ Teams || exit 1
;;
*)
echo "Use $0 ( deb-stable | deb-insider | snap | flatpak ) 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
@jtmackoy
Copy link

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
Copy link

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
Copy link
Author

@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
Copy link
Author

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

@IbanMM
Copy link

IbanMM commented May 24, 2021

Thank you!! Very useful

@NicoBoos
Copy link

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
Copy link

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

@mrcomoraes
Copy link
Author

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

@vigneshragupathy
Copy link

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
Copy link

peter279k commented Sep 23, 2021

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

@jayora
Copy link

jayora commented Oct 7, 2021

Thanks, the script is easy and fantastic

@raddevus
Copy link

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
Copy link

Thank you for the script. Saved my day 👍

@ms0ft-git
Copy link

It works perfectly, thanks a lot!

@lucas-dclrcq
Copy link

Working like a charm in Arch Linux using "debian-stable".Thanks !

@mrcomoraes
Copy link
Author

Thak you @lucas-dclrcq . I will update script comments.

@koolg63
Copy link

koolg63 commented Dec 28, 2021

Best script of the world ! especially to remove bad/bugging conversation draft.

@luisprox
Copy link

Saved me here too. I was not able to change users. Thanks for sharing.

@benfr1
Copy link

benfr1 commented Mar 23, 2022

this works like a charm on ubuntu 20.04. Thanks !!

@kjdavidson
Copy link

This is the best thing I've found on Github all day, thank you very much! Script works perfectly, Teams 1.4.00.26453, Ubuntu 20.04.4 LTS

@danie1k
Copy link

danie1k commented Aug 12, 2022

Works like a charm! But in my case directory is very different:

$HOME/.var/app/com.microsoft.Teams/config/Microsoft/Microsoft\ Teams

OS: Manjaro, Teams installed through flatpak.

@mrcomoraes
Copy link
Author

@danie1k I have not tested on flatpak Teams package. I will update script with flatpak support.

@fremling
Copy link

Hmm... weird, when i fun it in bash i get the following error....

fremling@Sill:~$ ./clear_cache_MS_Teams.sh deb-stable
./clear_cache_MS_Teams.sh: line 31: syntax error near unexpected token )' ./clear_cache_MS_Teams.sh: line 31: *)'

@mrcomoraes
Copy link
Author

mrcomoraes commented Sep 19, 2022

@fremling I have fix a block code that causes errors.

Please, update script and run again.

@gabrielmocanu
Copy link

@mrcomoraes
Any reasons why the process needs to be running?
I am thinking that maybe someone wants to clear the cache without Teams running.

@mrcomoraes
Copy link
Author

@gabrielmocanu
In last test, when Teams aren't running and start clean cache, some data of authentication is cleared too.

Currently I'm not tested. Feel free to validate.

@MarekGajdosik
Copy link

My snap installation has following location - $HOME/snap/teams-for-linux/current/.config/teams-for-linux/

@maksimdzmitryew
Copy link

My Ubuntu 23 snap installation Cache has following location $HOME/snap/teams-for-linux/current/.config/teams-for-linux/Partitions/teams-4-linux/ and the process to be killed is named teams-for-linux

@mrcomoraes
Copy link
Author

@MarekGajdosik and @maksimdzmitryew this "Teams for Linux" snap is a unofficial project that using Electron for deliver MS Teams. I beleive Microsoft removed Teams snap packages. I guess do a upgrade in snap option to support unofficial version.

@SirStifler
Copy link

Here is my first time on GitHub.
However, here is my contribution to this topic.
I have Ubuntu as my SO, and my teams-for-Linux is a fork on the Snap.

I changed lines 24, 25, and 26 to:

snap)
export TEAMS_PROCESS_NAME=teams-for-linux
cd /snap/teams-for-linux || exit 1

Why?
run ps to find your teams-for-linux process and you will see that:

$ ps -ef |grep teams-for-linux
me 324126 323853 0 12:32 ? 00:00:00 /snap/teams-for-linux/523/teams-for-linux --type=utility --utility-sub

So my teams-for-linux is on directory /snap/teams-for-linux
and the TEAMS_PROCESS_NAME is teams-for-linux and not just teams

Cheers!

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