Command Line Basics: Talking to Your Computer
In an age of graphical interfaces and AI assistants, the command-line terminal can seem intimidating. But learning a few basic commands is a superpower for any developer. It gives you direct control over your computer and is essential for many development tasks.
Why the Terminal Matters
- Direct Control: The terminal is the most direct way to interact with your computer's file system and run scripts.
- Automation: You can chain commands together to automate repetitive tasks.
- Required for Tooling: Many development tools, like Git and Node.js, are primarily used through the command line.
Essential Commands
Here are a few of the most important commands. Don't worry about memorizing them all at once; you'll learn them with practice.
pwd(Print Working Directory): Shows you the path of the directory you are currently in.ls(List): Lists the files and folders in the current directory.cd(Change Directory): Used to move into a different directory. For example,cd my-project.mkdir(Make Directory): Creates a new directory. For example,mkdir new-folder.clear: Clears the text from your terminal screen.
(Note: On Windows, the commands are slightly different. dir is used instead of ls, and cd works similarly. PowerShell is the modern Windows command line.)
Running a Script
Once you have a Python or Node.js script, you can run it from the terminal.
- Node.js:
node my-script.js - Python:
python my-script.py
This is how you will execute the programs you build.
Ask Your AI Assistant
The terminal has thousands of commands. If you see one you don't understand, ask your AI!
"Explain this terminal command in a simple way:
grep -r "hello world" ."
Your Turn: Get Comfortable
- Open the terminal on your computer (Terminal on Mac/Linux, PowerShell on Windows).
- Use
pwdto see where you are. - Use
lsto see what's there. - Use
mkdirto create a new directory calledmy-first-project. - Use
cdto move into that directory. - Create a simple
hello.jsfile in that directory and run it usingnode hello.js.
Congratulations! You're now using the command line.