Command blocks are useful elements in Minecraft because they have world-bending abilities. You first need to obtain a command block, and then you must program and activate it to be useful to you in the game.
Command blocks, because of their world-bending abilities, cannot be found in Survival mode. In fact, they don’t even appear on the Block menu in Creative mode. To obtain a command block, you must follow these steps:
Create a world that enables cheats.
If you start your world in Creative mode, cheats are enabled by default. You can tell whether cheats are enabled by finding your world on the Select World page — the third row of text should contain the word Cheats.
Clear out a space in the inventory.
Preferably, at least one of the nine bottom inventory slots should be clear.
Open the chat menu.
You do this by pressing the T key by default.
Type/give <your username> command_block.
If you opened the Chat menu with the Open Command key (which is / by default) rather than the T key, the slash at the beginning is entered automatically.
Press Enter.
The command block should appear in the inventory. If the bottom row of the inventory was already full, open the full inventory (press E by default) to find the command block.
Congratulations — you now have your first command block!
You can place the command block like you can place any normal block. By right-clicking on the block (or using a nondefault Use Item button), you open the Set Console Command for Block interface. You can enter a command in the Console Command box. You can access this interface only in Creative mode — if you’re playing on a server, you must have operator status as well.
Minecraft has many commands that you can enter in the chat interface, which can do various things, from teleporting the player to manipulating blocks. By entering one of these commands into a command block rather than the chat interface, you can execute the command automatically and remotely by powering the block.
A command block is a solid, nontransparent block, so when it’s powered a certain way, it activates everything around it. This can be useful for powering multiple command blocks easily, but it can also mess up the work of inexperienced designers.
The simplest way to use a command block is to place a button, lever, or pressure plate on or near the block — this allows you to activate the command block whenever you want. Some players like to take many command blocks and hook them up to redstone circuits.