There are a lot of applications that you can use/install to prevent your mac from sleeping such as Caffeine, Jiggler, or InsomniaX. But what if you do not want to install third-party application just to prevent your Mac from sleeping?
Well, the answer is by using a simple Terminal Command . To do this, open the Terminal (Applications > Utilities > Terminal) and enter the following command:
That’s it your Mac will not sleep so long as you do not close the Terminal. To enable your Mac to sleep again, simply hit Control + C or close the Terminal.