Congratulations on learning and running your first few commands! You now have a sense of what command interactions are like between you and your computer.
So far, you've learned how to ask for your current location (
pwd), list its contents (
ls), and change locations in your system (
Now, it's time for a pause break. Let's learn some shortcuts will let you be more nimble on the command line.
Accessing your command history
Once your development tasks become more complex, you're likely to run series of commands over and over. To run the same command more than once, you don't have to scroll up in your command history, confusedly searching for commands you've run before.
Instead, you can use your up and down arrow keys to scroll through your history! ⬆️⬇️
When the command line prompt is waiting for your input, just type your up arrow key instead.
By doing this, you should instantly have the previous command you've run shown on the command line. You can hit Enter to run it, or you can modify its contents. Continue to hit the up arrow key multiple times to see more and more of your previous commands.
Press the down arrow key to navigate back as needed.
Move around in the prompt
Entering text in Terminal isn't the same as writing in Google Docs. You can't click around to various points in the text, and it's frustrating to write a long command only to realize you have a typo in the middle of it. 😞
Various shortcuts allow you to jump from place to place as your inputting your text.
To move your cursor back to the beginning of the line (since you can't just click on it), press ctrl +a (this means you should press and hold the ctrl key while pressing the a key slightly thereafter). You can then adapt the beginning of your command if needed.
To move your cursor back to the end of the line, press ctrl+ e. Now you can add more content to the end of your command if necessary.
You can even hold down your option key and click to a certain point in the line, which will move your cursor to that particular spot. Type or fix what you need at that location, then jump back to the end of your command with ctrl + e if necessary.
If you hate everything you've written and no longer want to run a certain command, instead of hitting backspace to erase everything, just type ctrl + u. The command you were currently typing will be erased. Phew!
While you don't NEED these shortcuts, knowing them will make you much more nimble in Terminal.
Stop a hanging command
Although you'd have to work very hard to actually harm your computer using Terminal, sometimes you can run commands that are more tricky for your computer than you expect. Maybe you make a typo that means the command isn't running as it should. Maybe you've changed your mind and don't want a command to finish running.
Your handy "Stop!" key combination is ctrl + c.
By hitting ctrl + c, you can stop most commands as they're running.
This can be a little tricky if you're doing more advanced operations because you won't want certain operations to run only halfway. However, ctrl + c is safe in most scenarios (especially for the commands in this course).
Now you've got some handy keyboard shortcuts that will make you more nimble in Terminal and can get you out of trouble if necessary!
In the next chapter, we'll start creating content via the command line, and you can use these new keyboard shortcuts whenever you like!