How To: Reset Mac OS X Lion/Mountain Lion to factory default

How to reset Mac OS X Lion/Mountain Lion to Factory Default
Always make a fresh backup before you will get under the hood of your MAC!
BE VERY CAREFUL WHEN USING THE “rm” command as you may delete your whole drive!
DO THIS AT YOUR OWN RISK. I TAKE NO RESPONSIBILITY FOR ACCIDENTAL LOST OF DATA.
BACKUP IF DOING THIS WHERE THERE IS DATA ON THE DRIVE NEEDED TO BE SAVED
REQUIRED USER LEVEL: USER WITH ADVANCED KNOWLEDGE OF THE MAC OS X AND SELL !
Recently I have a client which asked me to reset his MBP to factory default. This client purchased latest Retina MBP and want to sell old one.
first of all you need to clean your Do
One of the important thing which you need to do –deauthorizing a computer. Open your iTunes and go to Store and click on the “Deauthorize This computer…” then if you have Audible account go to Advanced and “Deauthorize Audible Account…”

You will need to start your mac in Single User mode to clean disk and system . Reboot your system and immediately after Mac startup sound press and hold following combination: ⌘+S
Users of Mac-mini with non Apple keyboard: I cannot guaranty you will be able to get in to single user mode.
1.
For beginning to prevent any OS damage please execute following command
/sbin/fsck-fy
/sbin/mount-uw /
Now it is time to load OpenDirectory service:
For MAC OS X up to 10.6
launchctl load/System/Library/LaunchDaemons/com.apple.DirectoryServices.plist
If you have Mac OS X 10.7 and newer:
launchctl load/System/Library/LaunchDaemons/com.apple.opendirectoryd.plist
2.
To check in which groups you are listed, enter:
dscl . -list/groupsGroupMembership |grepyourusername
Most likely you will receive following respond from the system.
root#dscl . -list/groupsGroupMembership |grepyourusername_appserveradmyourusername
_appserverusryourusername
_lpadminyourusername
admin rootyourusername
com.apple.sharepoint.group.1yourusername
stuffyourusername
dscl . delete/groups/groupnameGroupMembershipyourusername
dscl . delete/groups/yourusername
dscl . delete/users/yourusername
rm/private/var/db/dslocal/nodes/Default/users/yourusername.plist
rm-rf/Users/yourusername
rm-rf/Library/Preferences/*
rm-rf/Library/Logs/*
rm-rf/private/var/log/*
rm-rf/Library/Caches/*
rm-rf/System/Library/Caches/*
rm/private/var/vm/swapfile*
rm-rf/private/var/folders/*
rm/private/var/db/.AppleSetupDone
rm -rf /private/var/root/*
shutdown -h now