What the command line and the shell are
A terminal is a window that shows text and accepts typing. Inside it runs a shell, a program that reads each line you type, works out which program to start, and prints the result. Common shells include bash and zsh on Unix-like systems, and PowerShell on Windows.
The shell shows a prompt, a short piece of text that means it is ready for input. You type a command and press Enter. The shell runs it and returns to the prompt.
Commands, arguments, options and paths
A typical command has three parts: the program name, options that change its behaviour, and arguments that say what to act on. In the line ls -l Documents, ls is the program, -l is an option asking for a long listing, and Documents is the argument. Options usually start with a hyphen, though conventions vary between programs.
A path names a location in the file system. An absolute path starts at the root, such as /home/sam/notes.txt. A relative path starts from the current working directory, so notes.txt means the file in the folder you are in now. The symbol .. means the parent directory.
Core commands on Unix-like systems include pwd to print the working directory, ls to list files, cd to change directory, mkdir to make a folder, cp to copy, mv to move or rename, and rm to delete. Windows shells offer similar commands, sometimes under different names.
Worked example: moving around and combining commands
Suppose the working directory is /home/sam and it holds a folder called projects. Typing cd projects changes the working directory to /home/sam/projects. Typing cd .. then returns to /home/sam.
Commands can be joined with a pipe, written |, which sends the output of one command into the next. Suppose a folder holds 12 files, and 5 of them end in .txt. The line ls | grep '\.txt$' lists only names ending in .txt, so 5 lines appear. The backslash makes the dot literal, and $ anchors the match to the end of the name. Adding | wc -l counts lines and prints 5. The pipeline is ls, then grep, then wc, and each step does one small job.
Common misconceptions
The command line is not a separate or older computer. It is another way to ask the same operating system to run programs. Many graphical tools run the same commands underneath.
Deleted files are not safely sent to a recycle bin. With rm on Unix-like systems, a file is usually removed at once with no undo, so check the command before pressing Enter. Commands are also often case-sensitive, so Notes.txt and notes.txt can be different files.
Where the command line is used
Developers use it to run compilers, manage code with version control tools such as git, and install packages. System administrators use it to manage servers, which often have no graphical interface at all. Scripts store many commands in one file so a task can be repeated exactly, which makes automation possible.
Key terms
- Shell
- A program that reads typed commands and asks the operating system to run them.
- Terminal
- A window that displays text and passes typed input to a shell.
- Argument
- A value given to a command, often the file or folder to act on.
- Option
- A flag, usually starting with a hyphen, that changes how a command behaves.
- Working directory
- The folder the shell treats as the current location for relative paths.
- Pipe
- The | symbol, which sends one command's output into another command as input.
