To prevent the system from idle sleeping, use caffeinate -i.
To prevent the display from sleeping, use caffeinate -d. There are other arguments you can apply to the caffeinate command as well. Using & allows us to continue to use the terminal while the caffeinate command runs in the background. We’ve added an ampersand ( &) to the end of the argument so that the command runs in the background. In this case, we’re allowing the computer to stay awake for 3600 seconds (or one hour). In this case, we’ve specified we want to add a duration using the switch -t plus time in seconds. In fact, unlike Caffeine, you can choose any duration you like, not just a specific duration from a list. No problem, the Terminal can do that too.