Link to home
Start Free TrialLog in
Avatar of Guru Ji
Guru JiFlag for Canada

asked on

Delete Browser data command line in MAC OS Sierra

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?

Thanks,
Avatar of David Favor
David Favor
Flag of United States of America image

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.
https://www.askvg.com/how-to-always-start-your-favorite-web-browser-in-private-browsing-mode-by-default/
https://www.howtogeek.com/137466/how-to-always-start-any-browser-in-private-browsing-mode/

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 com.apple.Safari*  
-rw-------  1 serialband  staff     42 May  9 11:59 com.apple.Safari.Extensions.plist
-rw-------  1 serialband  staff   2062 Mar 30 07:51 com.apple.Safari.Support.plist
-rw-------  1 serialband  staff  10863 Sep 19 14:13 com.apple.Safari.plist
-rw-------  1 serialband  staff   2216 Sep 17 19:51 com.apple.SafariBookmarksSyncAgent.plist
-rw-------  1 serialband  staff    118 Sep 12 20:14 com.apple.SafariCloudHistoryPushAgent.plist
 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 com.google.Chrome.plist

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.
Avatar of Guru Ji

ASKER

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!

Thanks
ASKER CERTIFIED SOLUTION
Avatar of serialband
serialband
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Guru Ji

ASKER

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/com.apple.Safari; \
rm -Rf ~/Library/Caches/com.apple.WebKit.PluginProcess; \
rm -Rf ~/Library/Cookies/rm -rf *Safari*;
rm -Rf ~/Library/Preferences/Apple\ -\ Safari\ -\ Safari\ Extensions\ Gallery; \
rm -Rf ~/Library/Preferences/com.apple.Safari.LSSharedFileList.plist; \
rm -Rf ~/Library/Preferences/com.apple.Safari.RSS.plist; \
rm -Rf ~/Library/Preferences/com.apple.WebFoundation.plist; \
rm -Rf ~/Library/Preferences/com.apple.WebKit.PluginHost.plist; \
rm -Rf ~/Library/Preferences/com.apple.WebKit.PluginProcess.plist; \
rm -Rf ~/Library/PubSub/Database; \
rm -Rf ~/Library/Saved\ Application\ State/com.apple.Safari.savedState
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/com.apple.Safari; \
rm -Rf /Users/useraccount/Library/Caches/com.apple.WebKit.PluginProcess; \
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/com.apple.Safari.LSSharedFileList.plist; \
rm -Rf /Users/useraccount/Library/Preferences/com.apple.Safari.RSS.plist; \
rm -Rf /Users/useraccount/Library/Preferences/com.apple.WebFoundation.plist; \
rm -Rf /Users/useraccount/Library/Preferences/com.apple.WebKit.PluginHost.plist; \
rm -Rf /Users/useraccount/Library/Preferences/com.apple.WebKit.PluginProcess.plist; \
rm -Rf /Users/useraccount/Library/PubSub/Database; \
rm -Rf /Users/useraccount/Library/Saved\ Application\ State/com.apple.Safari.savedState
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.
Avatar of Guru Ji

ASKER

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

ASKER

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 gmail.com
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*
Avatar of Guru Ji

ASKER

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.
Avatar of Guru Ji

ASKER

Thanks