For developers

Command line basics: the terminal commands every beginner should know

The command line looks intimidating but uses a small set of commands. Learn how to move around, manage files, read output and avoid the few commands that can hurt.

Cursorlane Editorial TeamSoftware & tools 5 min read
A person at a standing desk typing on a keyboard in front of a dark terminal window, with a cat asleep on a nearby shelf

The command line, also called the terminal or shell, is a text interface where you type commands to control your computer instead of clicking. Command line basics come down to a small set of commands for moving between folders, managing files and running programs, and those few commands open the door to most developer tools.

This guide explains what the terminal is, the essential commands for macOS and Linux (with Windows equivalents), how paths work, how to combine commands, and which commands deserve extra care.

Terminal, shell, command line: what is the difference?

The terminal is the window you type into. The shell is the program inside it that reads your commands and runs them. Common shells include Bash and Zsh on macOS and Linux, and PowerShell on Windows. 'Command line' is the general name for working this way.

Developers use the command line because many tools, including Git, package managers, compilers and servers, are built for it first. Text commands are also easy to repeat, combine, save in scripts and share in documentation, which is hard to do with a series of mouse clicks.

On Windows, PowerShell understands several Unix-style command names, and you can also run a full Linux environment through the Windows Subsystem for Linux. The examples below use the Bash and Zsh style common on macOS and Linux.

How do you move around the file system?

The shell always has a current folder, called the working directory. Commands act there unless you tell them otherwise. Three commands are enough to find your way:

  • pwd: print the working directory, so you know where you are.
  • ls: list the files and folders here. ls -la shows hidden files and details.
  • cd folder: change into a folder. cd .. goes up one level, cd ~ goes to your home folder, and cd - returns to the previous folder.
The command line trusts you completely: there is no confirmation dialog and no undo.

How do absolute and relative paths work?

A path describes where a file lives. An absolute path starts from the root of the file system, such as /home/sam/projects/site on Linux or /Users/sam/projects/site on macOS. It works from anywhere. A relative path starts from your current folder, such as projects/site or ../notes.txt.

Two shortcuts appear everywhere: a single dot means 'this folder' and two dots mean 'the folder above'. The tilde (~) means your home folder. If a file or folder name contains spaces, put the whole path in quotes, or the shell will treat each word as a separate argument.

Press the Tab key while typing a path and the shell completes it for you. This saves typing and catches typos, because if Tab completes nothing, the path probably does not exist.

Which commands manage files and folders?

These commands cover most everyday file work. Each accepts options, written after a dash, that change how it behaves; run man followed by the command name, or the command with --help, to see them.

  • mkdir name: create a folder. mkdir -p a/b/c creates nested folders.
  • touch file: create an empty file, or update its timestamp.
  • cp source destination: copy a file. Add -r to copy a folder.
  • mv source destination: move or rename a file or folder.
  • rm file: delete a file permanently, with no recycle bin.
  • cat file: print a file's contents. less file lets you scroll through long ones.
  • head and tail: show the first or last lines of a file. tail -f follows a log as it grows.
  • grep text file: find lines containing some text.

How do you combine commands?

The real strength of the command line is joining small commands together. The pipe symbol (|) sends the output of one command into the next. For example, history | grep git shows only the past commands that mention git, and ls | wc -l counts the items in a folder.

Redirection sends output to a file. A single > writes output to a file, replacing its contents, while >> adds to the end. Two ampersands (&&) run a second command only if the first succeeded, which is handy for steps that depend on each other, such as building and then running a program.

Press the up arrow to bring back previous commands, and Ctrl+R to search your history. Ctrl+C stops a running command, which is the first thing to try when something seems stuck.

Which commands need extra care?

The command line trusts you completely. There is no confirmation dialog and no undo, so a few commands deserve respect.

  • rm -r deletes folders and everything in them. Check the path with ls first, and never run it on a path you have not read carefully.
  • sudo runs a command with administrator rights. Use it only when you understand why it is needed.
  • Commands copied from the internet, especially ones that download a script and pipe it straight into the shell, run with your permissions. Read them first and prefer official sources.
  • Wildcards such as * match many files at once. Test a pattern with ls before using it with rm or mv.
  • chmod and chown change permissions and ownership; mistakes can lock you out of your own files.

Frequently asked questions

Is the terminal the same on Mac, Linux and Windows?

+

macOS and Linux share most commands because both follow Unix conventions. Windows uses PowerShell and Command Prompt, which have different commands, though PowerShell accepts some familiar names. The Windows Subsystem for Linux gives Windows a full Linux shell.

How do I open the terminal?

+

On macOS, open the Terminal app from Utilities. On most Linux desktops, search for Terminal or press Ctrl+Alt+T. On Windows, open PowerShell or Windows Terminal from the Start menu.

How do I stop a command that is running?

+

Press Ctrl+C. It sends an interrupt signal that stops most programs. If a program like less or man is showing text, press q to quit.

Can I undo rm?

+

Not from the terminal. rm deletes files without using the recycle bin. Recovery may be possible with backups or specialist tools, which is why careful paths and regular backups matter.

What does sudo mean?

+

sudo stands for 'superuser do'. It runs a single command with administrator privileges after asking for your password. Use it sparingly, because mistakes made with sudo can affect the whole system.

Why should developers learn the command line?

+

Most development tools, servers and automation work through it, and documentation usually gives terminal commands. Basic fluency makes installing, building, deploying and debugging much faster.

Open a terminal and spend ten minutes moving around with pwd, ls and cd, then make and delete a practice folder. After a week of small daily use, the command line stops feeling foreign.

How we research: Guides are written from established sources and checked for accuracy. They are general information, not professional advice.

Written by

Cursorlane Editorial Team

Software & tools

Our writers are developers and heavy software users who test what they write about and update guides when the tools change.

More Stories

View all →