The shutdown command comes in handy if you want to shutdown or reboot your Mac at a specific time. Here are some of the examples. You should be a super user to use these commands.

sudo shutdown [options] when [message]

Some examples.
Shutdown immediately:

sudo shutdown -h now

Restart immediately:

sudo shutdown -r now

Shutdown at 9 pm:

sudo shutdown -h 21:00

Shutdown in 5 minutes:

sudo shutdown -h +5

Restart immediately

sudo reboot

Shutdown immediately

sudo halt

If you are not an admin user non of the above commands are going to help. If that’s the case try the following commands.
Shutdown immediately:

osascript -'tell application "System Events" to shut down'

Restart immediately:

osascript -'tell application "System Events" to restart'

Sleep:

osascript -'tell application "System Events" to sleep'

Logout:

osascript -'tell application "System Events" to log out'