Advertisement

Command Line Basics: Master Terminal and Command Prompt

The command line looks intimidating, but it's actually pretty useful. Once you learn the basics, you can do things faster than clicking through menus. I use the command line daily, and I'm going to teach you the essentials.

This course covers command line basics for Windows (Command Prompt/PowerShell) and Mac/Linux (Terminal). By the end, you'll be comfortable navigating and using the command line.

Opening the Command Line

Windows:

  • Command Prompt: Press Windows key, type "cmd", press Enter
  • PowerShell: Press Windows key, type "PowerShell", press Enter

Mac:

  • Applications → Utilities → Terminal
  • Or press Cmd+Space, type "Terminal", press Enter

Linux:

  • Usually Ctrl+Alt+T
  • Or find Terminal in applications

Basic Navigation

See where you are:

  • Windows: cd (shows current directory)
  • Mac/Linux: pwd (print working directory)

List files:

  • Windows: dir
  • Mac/Linux: ls

Change directory:

  • All: cd folder-name
  • Go up one level: cd ..
  • Go to home: cd ~ (Mac/Linux) or cd %USERPROFILE% (Windows)

Clear screen:

  • Windows: cls
  • Mac/Linux: clear or Ctrl+L

Working with Files

Create a file:

  • Windows: echo. > filename.txt
  • Mac/Linux: touch filename.txt

Read a file:

  • Windows: type filename.txt
  • Mac/Linux: cat filename.txt

Copy a file:

  • Windows: copy file.txt newfile.txt
  • Mac/Linux: cp file.txt newfile.txt

Move/rename a file:

  • Windows: move file.txt newname.txt
  • Mac/Linux: mv file.txt newname.txt

Delete a file:

  • Windows: del filename.txt
  • Mac/Linux: rm filename.txt

Working with Folders

Create a folder:

  • Windows: mkdir folder-name
  • Mac/Linux: mkdir folder-name

Delete a folder:

  • Windows: rmdir folder-name (empty) or rmdir /s folder-name (with contents)
  • Mac/Linux: rmdir folder-name (empty) or rm -r folder-name (with contents)

Useful Tips

Tab completion: Start typing a file or folder name, press Tab to auto-complete. Saves typing and prevents typos.

Command history:

  • Windows: Press Up arrow to see previous commands
  • Mac/Linux: Press Up arrow to see previous commands

Cancel a command: Press Ctrl+C to stop a running command.

Get help:

  • Windows: command /? (like cd /?)
  • Mac/Linux: man command (like man ls)
Advertisement

Common Tasks

Find a file:

  • Windows: dir /s filename.txt (searches subdirectories)
  • Mac/Linux: find . -name "filename.txt"

See file contents page by page:

  • Windows: type filename.txt | more
  • Mac/Linux: less filename.txt (press q to quit)

Count lines in a file:

  • Windows: find /c /v "" filename.txt
  • Mac/Linux: wc -l filename.txt

PowerShell vs Command Prompt (Windows)

Command Prompt (CMD): Older, simpler, good for basic tasks.

PowerShell: More powerful, modern, better for advanced tasks. I recommend PowerShell if you're on Windows.

Most basic commands work the same in both. PowerShell has more advanced features.

Terminal vs Command Line

Terminal (Mac/Linux): The program you use to access the command line. Usually runs bash or zsh shell.

Command Prompt/PowerShell (Windows): Windows' command line interfaces.

They're all command line interfaces - ways to interact with your computer by typing commands instead of clicking.

Practice Exercises

Try these to get comfortable:

  1. Navigate to your Documents folder
  2. List all files
  3. Create a new folder called "test"
  4. Create a file in that folder
  5. Navigate into the folder
  6. List files to see your new file
  7. Go back up one level
  8. Delete the test folder

Practice these until they feel natural.

Common Mistakes

  • Wrong case: On Mac/Linux, file names are case-sensitive. "File.txt" is different from "file.txt"
  • Spaces in names: Use quotes: cd "My Folder" or escape: cd My\ Folder
  • Forgetting where you are: Use pwd or cd to check your location
  • Deleting wrong files: Be careful with delete commands - there's no undo

Pro Tip: Learn keyboard shortcuts. Tab for completion, Up arrow for history, Ctrl+C to cancel. These make the command line much faster. Also, don't be afraid to experiment - you can't break your computer with most commands, and you can always close the terminal and open it again.

Common Questions

Do I need to know command line to program?

Not strictly, but it helps a lot. Most development tools use the command line. You can get by with GUIs, but knowing command line makes you more efficient and opens up more tools.

Can I break my computer with command line?

Most commands are safe. But be careful with delete commands and commands that modify system files. Don't run commands you don't understand, especially ones that require administrator/sudo access.

Should I learn PowerShell or Command Prompt?

If you're on Windows, learn PowerShell. It's more powerful and modern. Command Prompt is fine for basics, but PowerShell is better for advanced tasks. Most basic commands work the same in both.

Start Using the Command Line

Open Terminal or Command Prompt and start practicing. Navigate folders, list files, create and delete things. The more you use it, the more comfortable you'll get. Start with the basics, then learn more commands as you need them. The command line is a powerful tool once you get the hang of it.

Advertisement