01
What is a Command Line Interface (CLI)?
Key idea: A CLI lets you interact with the computer by typing text commands instead of clicking icons. Both DOS and Linux have their own command shells.
A Command Line Interface (CLI) is a text-based interface where users type commands to perform tasks. Unlike a GUI (Graphical User Interface), the CLI requires no mouse — only keyboard input.
DOS/Windows CMD
Accessed via
cmd.exe or Command Prompt on Windows. Commands are case-insensitive.Linux / Bash Shell
Accessed via Terminal (Ctrl+Alt+T on Ubuntu). Commands are case-sensitive.
Shell / Prompt
DOS prompt:
C:\> — Linux prompt: username@host:~$Why learn CLI?
Faster than GUI for many tasks, essential for servers, automation, scripting & programming.
Tip: In DOS/CMD, commands are NOT case-sensitive. In Linux,
ls, LS, and Ls are all different — only ls works.
02
DOS Commands – File & Directory Management
DOS (Disk Operating System) uses a command prompt (
DOS / Windows CMD
C:\>) and was the main OS for IBM PCs from 1981–1995. Its commands are still used today in Windows CMD.
These are the most commonly used DOS commands for managing files and directories (folders).
| Command | Full Form / Purpose | Syntax | Example |
|---|---|---|---|
| DIR | List files & directories in current folder | DIR [drive:][path] | DIR C:\Users |
| MD / MKDIR | Make Directory — create a new folder | MD [folder_name] | MD Projects |
| RD / RMDIR | Remove Directory — delete an empty folder | RD [folder_name] | RD OldFolder |
| CD | Change Directory — navigate to a folder | CD [path] | CD C:\Windows |
| CD .. | Move one level up (to parent directory) | CD .. | CD .. |
| CD \ | Go directly to the root directory | CD \ | CD \ |
| COPY | Copy one or more files to another location | COPY source destination | COPY file.txt D:\ |
| MOVE | Move file(s) from one location to another | MOVE source destination | MOVE notes.txt D:\Backup |
| DEL / ERASE | Delete (erase) one or more files | DEL [filename] | DEL old.txt |
| REN / RENAME | Rename a file or directory | REN oldname newname | REN doc.txt notes.txt |
| TYPE | Display the contents of a text file | TYPE [filename] | TYPE readme.txt |
| XCOPY | Extended copy — copies files, directories & subdirectories | XCOPY source destination /S | XCOPY C:\Data D:\Backup /S |
| ATTRIB | Show or change file attributes (H=hidden, R=read-only, S=system) | ATTRIB [+/-attr] file | ATTRIB +H secret.txt |
| TREE | Display the directory structure as a tree | TREE [path] | TREE C:\ |
In DOS, paths use backslash (\). Example:
C:\Users\John\Documents. Each drive (C:, D:) is accessed separately — just type the drive letter followed by a colon.
03
DOS Commands – System & Disk Utility
| Command | Purpose | Syntax | Example |
|---|---|---|---|
| CLS | Clear the screen (like clear in Linux) | CLS | CLS |
| DATE | Display or set the system date | DATE | DATE |
| TIME | Display or set the system time | TIME | TIME |
| VER | Display the current DOS/Windows version | VER | VER |
| HELP | Get help about any command | HELP [command] | HELP DIR |
| ECHO | Display a message or turn command echoing on/off | ECHO [message] | ECHO Hello World |
| PATH | Display or set the search path for executables | PATH [path1;path2] | PATH C:\Windows;C:\Python |
| SET | Display or set environment variables | SET [variable=value] | SET MYVAR=Hello |
| FORMAT | Format a disk (erases all data) | FORMAT [drive:] | FORMAT D: |
| CHKDSK | Check the disk for errors and display status | CHKDSK [drive:] | CHKDSK C: |
| DISKPART | Manage disks, partitions and volumes | DISKPART | DISKPART |
| IPCONFIG | Display network adapter configuration (IP, subnet, gateway) | IPCONFIG [/all] | IPCONFIG /all |
| PING | Test network connectivity to a host | PING [hostname/IP] | PING google.com |
| SHUTDOWN | Shutdown, restart, or log off Windows | SHUTDOWN /s /t 0 | SHUTDOWN /r /t 30 |
| TASKLIST | Display all running processes | TASKLIST | TASKLIST |
| TASKKILL | Kill (stop) a running process by name or PID | TASKKILL /IM name /F | TASKKILL /IM notepad.exe /F |
| FIND | Search for a text string inside a file | FIND "text" [file] | FIND "error" log.txt |
| SORT | Sort the contents of a file or input | SORT [file] | SORT names.txt |
04
Linux Commands – File & Directory Management
Linux Shell: Opened with Terminal (Ctrl+Alt+T). The prompt looks like
Linux / Bash
user@machine:~$. The ~ represents your home directory. Commands are case-sensitive.
| Command | Full Form / Purpose | Syntax | Example |
|---|---|---|---|
| ls | List files and directories | ls [options] [path] | ls -la /home |
| ls -l | Long format listing (permissions, size, date) | ls -l [path] | ls -l /var/log |
| ls -a | List all files including hidden files (starting with .) | ls -a | ls -a ~ |
| cd | Change Directory — navigate to another folder | cd [path] | cd /var/www |
| cd ~ | Go to home directory | cd ~ | cd ~ |
| cd .. | Move one level up (to parent directory) | cd .. | cd .. |
| pwd | Print Working Directory — show current path | pwd | pwd |
| mkdir | Make Directory — create a new directory | mkdir [name] | mkdir projects |
| mkdir -p | Create nested directories at once | mkdir -p path/sub/dir | mkdir -p a/b/c |
| rmdir | Remove an empty directory | rmdir [name] | rmdir old_folder |
| rm | Remove (delete) a file | rm [file] | rm notes.txt |
| rm -r | Recursively remove a directory and its contents | rm -r [directory] | rm -r oldproject/ |
| rm -rf | Force remove without confirmation (use with care!) | rm -rf [directory] | rm -rf /tmp/cache |
| cp | Copy a file to another location | cp source destination | cp file.txt /backup/ |
| cp -r | Copy a directory recursively | cp -r source/ destination/ | cp -r mydir/ /backup/ |
| mv | Move or rename a file/directory | mv source destination | mv old.txt new.txt |
| touch | Create an empty file or update file timestamp | touch [filename] | touch index.html |
| cat | Concatenate — display file contents | cat [file] | cat readme.txt |
| cat > file | Create a new file and type content into it (Ctrl+D to save) | cat > [filename] | cat > notes.txt |
| more | Display file one screen at a time (press Space to continue) | more [file] | more big_file.txt |
| less | Like more but allows backward scrolling (press Q to quit) | less [file] | less /var/log/syslog |
| head | Show the first 10 lines of a file | head [-n N] [file] | head -n 20 log.txt |
| tail | Show the last 10 lines of a file | tail [-n N] [file] | tail -n 5 error.log |
| find | Search for files matching criteria | find [path] -name "pattern" | find / -name "*.txt" |
| grep | Search for a pattern/text inside files | grep "pattern" [file] | grep "error" log.txt |
| chmod | Change file permissions (read/write/execute) | chmod [mode] [file] | chmod 755 script.sh |
| chown | Change file owner and/or group | chown user:group [file] | chown root:root file.txt |
| ln -s | Create a symbolic (soft) link to a file | ln -s target linkname | ln -s /var/www/html mysite |
Linux paths use forward slash (/). The root of the filesystem is
/. Your home directory is /home/username or simply ~.
05
Linux Commands – System & Network
| Command | Purpose | Syntax | Example |
|---|---|---|---|
| clear | Clear the terminal screen | clear | clear |
| echo | Print text or variable value to terminal | echo [text] | echo "Hello World" |
| date | Display current date and time | date | date |
| whoami | Display the current logged-in username | whoami | whoami |
| uname -a | Show system information (kernel, OS, hardware) | uname [-a] | uname -a |
| ps | Show currently running processes | ps [aux] | ps aux |
| kill | Terminate a process by its PID | kill [PID] | kill 1234 |
| top | Show real-time CPU, memory & process usage | top | top |
| df -h | Show disk usage in human-readable format | df -h | df -h |
| du -sh | Show size of a directory | du -sh [path] | du -sh /var/www |
| free -h | Show RAM usage (free & used memory) | free -h | free -h |
| sudo | Run a command with superuser (root) privileges | sudo [command] | sudo apt update |
| apt install | Install a package (Debian/Ubuntu) | sudo apt install [package] | sudo apt install vim |
| apt update | Update list of available packages | sudo apt update | sudo apt update |
| apt remove | Uninstall a package | sudo apt remove [package] | sudo apt remove vim |
| ifconfig | Display network interface configuration (IP address, etc.) | ifconfig | ifconfig |
| ping | Test connectivity to a host | ping [host] | ping google.com |
| ssh | Secure Shell — remote login to another machine | ssh user@host | ssh [email protected] |
| wget | Download a file from the internet | wget [URL] | wget https://example.com/file.zip |
| tar | Archive/compress files (.tar, .tar.gz) | tar -cvzf archive.tar.gz folder/ | tar -xvzf file.tar.gz |
| history | Show list of previously typed commands | history | history | tail -20 |
| man | Display the manual/help page for a command | man [command] | man ls |
| shutdown | Shutdown or restart the system | shutdown -h now / -r now | shutdown -h now |
06
Operators – Pipe, Redirection & More
Operators are special characters that control the flow of input and output between commands and files. They work in both DOS and Linux (with minor differences).
Both DOS & Linux
|
Pipe Operator
The pipe (
|) takes the output of one command and passes it as the input to the next command. It lets you chain multiple commands together in a single line.
Syntax
command1 | command2 | command3
Linux Examples
ls -l | grep ".txt"
↳ Lists files and filters to show only .txt files
cat log.txt | grep "error" | sort
↳ Shows lines containing "error", then sorts them alphabetically
ps aux | grep firefox
↳ Finds all processes related to Firefox
DOS/CMD Examples
DIR | FIND "txt"
↳ Lists directory and filters to show only entries containing "txt"
>
Output Redirection (Overwrite)
The greater-than (
>) operator redirects the output of a command to a file instead of displaying it on screen. If the file already exists, it is overwritten.
Syntax
command > filename
Linux Examples
ls > filelist.txt
↳ Saves the list of files into filelist.txt (overwrites if exists)
echo "Hello World" > hello.txt
↳ Creates hello.txt with the text "Hello World"
cat file1.txt > file2.txt
↳ Copies contents of file1.txt into file2.txt
DOS/CMD Examples
DIR > list.txt
↳ Saves directory listing into list.txt
>>
Append Operator
The double greater-than (
>>) appends output to the end of a file without overwriting it. If the file doesn't exist, it is created.
Syntax
command >> filename
Linux Examples
echo "Line 2" >> hello.txt
↳ Adds "Line 2" to the end of hello.txt without deleting existing content
date >> activity.log
↳ Appends the current date/time to a log file each time it runs
DOS/CMD Examples
ECHO Error found >> errors.log
↳ Appends "Error found" to errors.log
<
Input Redirection
The less-than (
<) operator sends the contents of a file as input to a command, instead of requiring keyboard input.
Syntax
command < filename
Linux Examples
sort < names.txt
↳ Sorts the content of names.txt and displays result on screen
grep "apple" < fruits.txt
↳ Searches for "apple" in fruits.txt using file as input
2>
Error Redirection (stderr)
Redirects error messages (standard error / stderr) to a file, separate from normal output. Useful in Linux shell scripting to log errors silently.
Syntax
command 2> error_file
Linux Examples
ls /fakepath 2> errors.txt
↳ Saves the "No such file or directory" error into errors.txt
command > output.txt 2>&1
↳ Redirects both normal output AND errors into output.txt
&& / ;
Command Chaining Operators
&& runs the next command only if the previous one succeeds. The semicolon ; (Linux only) runs commands one after another regardless of success or failure.
Linux Examples
mkdir newdir && cd newdir
↳ Creates directory AND changes into it — only if mkdir succeeds
sudo apt update && sudo apt upgrade
↳ Updates package list, then upgrades only if update was successful
echo "Start" ; ls ; echo "Done"
↳ Runs all three commands in sequence regardless of errors
07
Wildcards – * and ? (Both DOS & Linux)
Wildcards are special characters used to match multiple files by a pattern, without typing every filename individually.
Both DOS & Linux
* (Asterisk)
Matches any number of characters (including none).
*.txt → all .txt filesfile* → file, file1, file_old, etc.* → all files
? (Question Mark)
Matches exactly one character.
file?.txt → file1.txt, fileA.txt???.log → any 3-char named .log file
| Pattern | Matches | OS |
|---|---|---|
| *.txt | All files ending in .txt (notes.txt, report.txt, etc.) | Both |
| file?.doc | file1.doc, fileA.doc — exactly one character before .doc | Both |
| *.??? | Any file with a 3-character extension | Both |
| DEL *.bak | Delete all .bak backup files (DOS) | DOS |
| rm *.log | Remove all .log files (Linux) | Linux |
| ls data_*.csv | List all CSV files starting with "data_" | Linux |
| cp *.jpg photos/ | Copy all .jpg images into the photos/ folder | Linux |
Warning: Be careful with
rm * in Linux — it deletes all files in the current directory with no Recycle Bin recovery!
08
DOS vs Linux – Quick Command Comparison
Many tasks can be performed in both DOS and Linux — but with different commands. Here is a side-by-side comparison of equivalent commands:
| # | Task | DOS/CMD | Linux/Bash |
|---|---|---|---|
| 1 | List files | DIR | ls |
| 2 | Change directory | CD foldername | cd foldername |
| 3 | Create directory | MD / MKDIR | mkdir |
| 4 | Remove directory | RD / RMDIR | rmdir / rm -r |
| 5 | Copy file | COPY src dest | cp src dest |
| 6 | Move/Rename file | MOVE / REN | mv |
| 7 | Delete file | DEL / ERASE | rm |
| 8 | Show file contents | TYPE filename | cat filename |
| 9 | Clear screen | CLS | clear |
| 10 | Current directory | CD (no args) | pwd |
| 11 | Print to screen | ECHO text | echo text |
| 12 | Find text in file | FIND "text" file | grep "text" file |
| 13 | Network config | IPCONFIG | ifconfig / ip addr |
| 14 | Show processes | TASKLIST | ps aux |
| 15 | Kill a process | TASKKILL /IM name | kill PID |
| 16 | Disk space usage | CHKDSK | df -h |
| 17 | System info | VER / SYSTEMINFO | uname -a |
| 18 | Current date | DATE | date |
| 19 | Current time | TIME | date +%T |
| 20 | Sort output | SORT | sort |
| 21 | Directory tree | TREE | tree |
| 22 | Help on command | HELP cmd / cmd /? | man cmd |
| 23 | Path separator | \ (backslash) | / (forward slash) |
| 24 | Case sensitivity | NOT case-sensitive | IS case-sensitive |
Key differences at a glance
- Case sensitivity: DOS commands work in any case (DIR = dir = Dir). Linux commands must be lowercase exactly as written.
- Path separator: DOS uses
\(backslash), Linux uses/(forward slash). - Root: DOS root is a drive letter like
C:\. Linux root is/(a single forward slash). - File creation: Linux uses
touch filename; DOS has no direct equivalent (usecopy con filename). - Superuser: Linux uses
sudobefore a command for admin rights. DOS/CMD uses "Run as Administrator". - Hidden files: In Linux, files starting with a dot (
.bashrc) are hidden. In DOS,ATTRIB +Hhides files. - Pipe (
|),>,>>: Work in both DOS and Linux — this is a shared feature.
Quick Exam Tip: The commands
cat, ls, pwd, mkdir, rm, grep, and chmod are Linux-only. The commands DIR, TYPE, IPCONFIG, and CLS are DOS/Windows-specific. The pipe | and redirection > operators work in both!
Comments 0
Leave a Comment