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?

LVL 11
Guru JiAsked:
Who is Participating?

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

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.
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.
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!

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.

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.

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/; \
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.
Guru JiAuthor Commented:
No we don't use the keychain app and there is no entry in it either
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
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*
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.
Guru JiAuthor Commented:
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

From novice to tech pro — start learning today.