24 min read
Command-Line Basics
Open the Windows Command Prompt and a Linux terminal, read the prompt, and move around folders with dir, cd, ls and pwd.
Why Learn the Command Line?
Before Windows, PCs ran MS-DOS, where everything was typed as commands. The Windows Command Prompt (cmd) still understands most DOS commands, and every Linux server is managed from a terminal. IT technicians use the command line to fix computers that will not start normally, to manage servers, and to automate repetitive jobs.
Opening a Command Line
- Windows: press the Windows key, type cmd and press Enter. (You can also use Terminal or PowerShell; the basic commands in this lesson work in cmd.)
- Linux (Ubuntu): press Ctrl + Alt + T, or open Terminal from the applications menu.
- macOS: open Terminal from Applications → Utilities. It uses the same commands as Linux.
Reading the Prompt
Windows Command PromptCommand line
C:\Users\Nuwan>The prompt shows where you are: drive C:, folder Users\Nuwan. The > means "type a command here". This location is the current directory (current folder).
Linux terminalCommand line
nuwan@hillside-server:~$On Linux the prompt shows the user, the computer name, and the folder — ~ means your home folder (/home/nuwan). A $ at the end means an ordinary user; a # means the administrator (root).
Looking Around: dir and ls
Listing a folder in WindowsCommand line
C:\Users\Nuwan\Documents> dir Directory of C:\Users\Nuwan\Documents 12/03/2026 09:15 <DIR> .12/03/2026 09:15 <DIR> ..10/03/2026 14:02 <DIR> Jobs11/03/2026 16:40 24,576 price-list.xlsx11/03/2026 16:45 1,204 notes.txt 2 File(s) 25,780 bytes 3 Dir(s) 120,431,112,192 bytes freedir lists the files and folders in the current directory. <DIR> marks a folder. The single dot . means "this folder"; the double dot .. means "the folder above" (the parent).
Listing a folder in LinuxCommand line
nuwan@hillside-server:~/documents$ ls -ldrwxr-xr-x 2 nuwan staff 4096 Mar 10 14:02 jobs-rw-r--r-- 1 nuwan staff 24576 Mar 11 16:40 price-list.xlsx-rw-r--r-- 1 nuwan staff 1204 Mar 11 16:45 notes.txtls lists files; ls -l shows details, including the permissions you met in the Number Systems course (d = directory, rwx = read, write, execute).
Moving Around: cd
| Changing directory | ||
|---|---|---|
Absolute and Relative Paths
- An absolute path gives the full location from the top:
cd C:\Users\Nuwan\Documents\Jobsorcd /home/nuwan/documents/jobs. It works from anywhere. - A relative path starts from where you are now: if you are in Documents,
cd Jobsis enough.cd ..\Downloadsgoes up one level, then into Downloads.
Practice
More lessons in Operating Systems · Next: Working with Files at the Command Line · Previous: Booting a Computer
