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,
LVL 11
Guru JiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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.
0
serialbandCommented:
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.
0
Guru JiAuthor Commented:
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
0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

serialbandCommented:
You should remove the preferences as well.
rm ~/Library/Preferences/com.apple.Safari*

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



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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Guru JiAuthor Commented:
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
0
serialbandCommented:
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.
0
Guru JiAuthor Commented:
No we don't use the keychain app and there is no entry in it either
0
Guru JiAuthor Commented:
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
0
serialbandCommented:
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*
0
Guru JiAuthor Commented:
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.
0
Guru JiAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Safari

From novice to tech pro — start learning today.