Delete Browser data command line in MAC OS Sierra

Guru Ji
Guru Ji used Ask the Experts™
I have a script .sh file which delete chrome data in iMAC and it works great.
How can I accomplish same for Firefox and Safari as I want all history and everything deleted and when current user opens firefox and safari it should open like a brand new one. Anyway to accomplish this via command line or script?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Different versions of every browser either provide this or you can... simulate it...

I've done this before by...

1) Stop FireFox.

2) Delete some or all contents of related files.

3) Restart FireFox.

Last time I did this... was a very long time ago...

Check the FireFox docs or if you get stumped, just search your profile.

In my case, with latest FireFox, history data lives in places.sqlite, so you'll either delete this file or run an sqlite3 command to clear it out.

You'll just have to test + see.

Use to be FireFox recreated any missing *.sqlite files at startup, so likely just nuke the file.
It sounds like you want everything deleted.  If you still want to script the deletion, you just need to remove the following profile directories and everythnig will be gone.
rm -rf ~/Library/Safari
rm -rf "~/Library/Application Support/Firefox/Profiles/*default"
rm -rf "~/Library/Application Support/Google/Chrome/Default"

Would it be simpler to force them to always start in private mode?  There would be less to delete.

I haven't done this, but it would be in the Preferences files.  You could change the settings to default open in Incognito or Private mode and copy the plist file to the user.
cd ~/Library/Preferences/
ls -l*  
-rw-------  1 serialband  staff     42 May  9 11:59
-rw-------  1 serialband  staff   2062 Mar 30 07:51
-rw-------  1 serialband  staff  10863 Sep 19 14:13
-rw-------  1 serialband  staff   2216 Sep 17 19:51
-rw-------  1 serialband  staff    118 Sep 12 20:14
 ls -al *firefox*
-rw-------  1 serialband  staff  315 Mar 12  2018 org.mozilla.firefox.plist
 ls -la *Chrome*
-rw-------  1 serialband  staff  393 Aug  1 18:27

You could force a computer systemwide default by copying them to /Library/Preferences/ and force it for all users on a computer.  Make sure you chmod 644 and chown root on the files you copy there, so the user can read the files but can't change it.

I used to force system wide default startup settings and extensions on all new user accounts for Windows, Linux and OS X at a previous job.


Thanks for your solution. I really want the script to work if possible and I tried above but Safari is still remembering my logged in gmail account when open after running the script.

I am also deleting everything inside user/Library/safari/* folder and it still remembers everything. Is there a folder I am missing.
I am including this folder as well rm -rf ~/Library/Safari but no luck!

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

You should remove the preferences as well.
rm ~/Library/Preferences/*

If you want to be thorough with Firefox and Chrome, then remove those as well
rm ~/Library/Preferences/{org.mozilla.firefox.plist,}

The tilde(~) will expand to the user home folder.  It's a standard unix/linux shortcut.


This is what I have but it still remembers my gmail logged into safari, I am logged in as user name "useraccount". Firefox clears up fine but safari is not working

killall -9 “firefox”
killall -9 “Safari”
rm -Rf ~/Library/Safari
rm -Rf ~/Library/Application\ Support/Firefox
rm -Rf ~/Library/Caches/Apple\ -\ Safari\ -\ Safari\ Extensions\ Gallery; \
rm -Rf ~/Library/Caches/Metadata/Safari; \
rm -Rf ~/Library/Caches; \
rm -Rf ~/Library/Caches/; \
rm -Rf ~/Library/Caches/; \
rm -Rf ~/Library/Cookies/rm -rf *Safari*;
rm -Rf ~/Library/Preferences/Apple\ -\ Safari\ -\ Safari\ Extensions\ Gallery; \
rm -Rf ~/Library/Preferences/; \
rm -Rf ~/Library/Preferences/; \
rm -Rf ~/Library/Preferences/; \
rm -Rf ~/Library/Preferences/; \
rm -Rf ~/Library/Preferences/; \
rm -Rf ~/Library/PubSub/Database; \
rm -Rf ~/Library/Saved\ Application\ State/
rm -Rf /Users/useraccount/Library/Safari/

#  remove document
#rm ~/Desktop/*
rm -rf ~/Documents/*
#rm ~/Downloads/*

rm -Rf /Users/useraccount/Library/Caches/Apple\ -\ Safari\ -\ Safari\ Extensions\ Gallery; \
rm -Rf /Users/useraccount/Library/Caches/Metadata/Safari; \
rm -Rf /Users/useraccount/Library/Caches; \
rm -Rf /Users/useraccount/Library/Caches/; \
rm -Rf /Users/useraccount/Library/Caches/; \
rm -Rf /Users/useraccount/Library/Cookies/rm -rf *Safari*;
rm -Rf /Users/useraccount/Library/Preferences/Apple\ -\ Safari\ -\ Safari\ Extensions\ Gallery; \
rm -Rf /Users/useraccount/Library/Preferences/; \
rm -Rf /Users/useraccount/Library/Preferences/; \
rm -Rf /Users/useraccount/Library/Preferences/; \
rm -Rf /Users/useraccount/Library/Preferences/; \
rm -Rf /Users/useraccount/Library/Preferences/; \
rm -Rf /Users/useraccount/Library/PubSub/Database; \
rm -Rf /Users/useraccount/Library/Saved\ Application\ State/
That's probably in the keychain.  Did you have it save your account and password?  That's actually separate from Safari.  You'll need to open Keychain Access.App and find the entry to delete.


No we don't use the keychain app and there is no entry in it either


Moreover if I use Safari history cleaner then its cleans all history and no more gmail logged in too. but somehow the commands I am running not cleaning things but I don't see anything in Safari holder either I have deleted all history db files and anything within that folder and on new launch of Safari it creates all those files but brings back my logged in gmail if I goto
Safari uses the keychain to save user accounts and passwords.  They'll have their own entries in the keychain.  You won't find it as *safarI*


Thanks but again there was nothing in keychain, its a new mac , I don't even see a single entry. No worries I will just work it out as is what I have accomplished. Thanks for all your help.



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial