26 min read
Working with Files at the Command Line
Create, copy, move, rename and delete files and folders, use wildcards, and write a simple batch file.
The Essential Commands
| File and folder commands | ||
|---|---|---|
Wildcards
A wildcard stands for other characters, so one command can affect many files:
- The asterisk
*matches any number of characters:dir *.pdflists every PDF;del *.tmpdeletes every .tmp file. - The question mark
?matches exactly one character:dir invoice-0??.xlsxmatches invoice-001.xlsx to invoice-099.xlsx.
A Worked Session
Windows Command PromptCommand line
C:\Users\Nuwan\Documents> md Jobs\2026-03\incomingC:\Users\Nuwan\Documents> md Jobs\2026-03\proofsC:\Users\Nuwan\Documents> cd Jobs\2026-03C:\Users\Nuwan\Documents\Jobs\2026-03> copy D:\wedding-card.pdf incoming 1 file(s) copied.C:\Users\Nuwan\Documents\Jobs\2026-03> ren incoming\wedding-card.pdf perera-wedding-card.pdfC:\Users\Nuwan\Documents\Jobs\2026-03> treeC:.├───incoming└───proofsC:\Users\Nuwan\Documents\Jobs\2026-03> cd ..\..C:\Users\Nuwan\Documents> xcopy Jobs E:\Backup\Jobs /e /iC:\Users\Nuwan\Documents> dir /s *.pdfThe same job in a Linux terminalCommand line
nuwan@hillside-server:~$ mkdir -p jobs/2026-03/incoming jobs/2026-03/proofsnuwan@hillside-server:~$ cp /media/usb/wedding-card.pdf jobs/2026-03/incoming/nuwan@hillside-server:~$ mv jobs/2026-03/incoming/wedding-card.pdf jobs/2026-03/incoming/perera-wedding-card.pdfnuwan@hillside-server:~$ ls jobs/2026-03/incomingperera-wedding-card.pdfnuwan@hillside-server:~$ cp -r jobs /srv/backup/Automating with a Batch File
A batch file (.bat) is a text file containing commands that run one after another. On Linux the same idea is a shell script (.sh). Nuwan saves this as backup-jobs.bat and double-clicks it every evening:
backup-jobs.batCommand line
@echo offecho Backing up print jobs...xcopy "C:\Users\Nuwan\Documents\Jobs" "E:\Backup\Jobs" /e /i /yecho Backup finished on %date% at %time%pause@echo off hides the commands themselves; echo prints a message; /y overwrites without asking; %date% and %time% insert the current date and time; pause keeps the window open until a key is pressed. Windows Task Scheduler can run it automatically every night.
Two Useful Network Commands
ipconfig(Windows) orip a(Linux) shows the computer's IP address — useful when a PC cannot reach the server.ping 192.168.1.10sends small test messages to another computer. Replies mean the network path works.
Practice
Choose one.
More lessons in Operating Systems · Next: Course Exam · Previous: Command-Line Basics
