The operating system used on Macs is developed in such way that it eliminates the need for a defragmentation unlike in Windows environment. OS X is developed to write files in one go and because of that the defragment operation is eliminated from the discussion.
Also, if you want a solution for cleaning the space, unnecessary files, temporary files, installation data, etc, then you can use a program like CleanMyMac which carefully analyzes the drive and eliminates the files you don't need thus freeing up the space in a simple way.