There are times when you maybe uploading a YouTube video, downloading games on Steam and don’t want your Mac to fall asleep automatically. Instead of changing your Power Saver Preferences in System Preferences, you can use caffeinate and command Mac to not fall asleep until you say so.
Open Terminal and paste the following command:
caffeinate
To give your Mac a break hit Control + C in the Terminal or quit the Terminal altogether.
Now, to keep your Mac awake for specific time period. Use:
caffeinate -i -t {seconds}
So, if you need it to stay awake for 1 hour (1h = 3600s). Easy peasy. Right?