How to use Command Prompt and Terminal
Learn the main commands in Command Prompt and Terminal: move between folders, make, copy, rename and delete files, and get help.
Safety first
- Only type commands that you understand.
- Never type or paste a command that someone sends you in a message, an email, a video or on the phone and tells you to run.
- Commands that delete files (del and rm) do not use the Recycle Bin or Trash.
- A deleted file cannot be brought back.
- Practise only in the Practice folder that you make in this guide, not in folders that hold your real files.
- Nothing in this guide needs administrator rights or the sudo command.
- If a window asks for an administrator password, or says Run as administrator, stop and close it.
What you need
A Windows computer or a Mac
Steps
Know what you are opening. Command Prompt (on Windows) and Terminal (on a Mac) are windows where you type short instructions, called commands, instead of using the mouse. The computer carries out each command when you press Enter. You will practise in a new folder that you make yourself, so none of your real files are at risk.
Open it. On Windows, press the Windows key on your keyboard (it sits between the Ctrl and Alt keys at the bottom left), type
cmd, then press Enter. On a Mac, hold down the Command key, press the Space bar, typeTerminal, then press Enter. A window opens with a line of text and a blinking cursor. On Windows 11 the window may be called Terminal and show a tab named Command Prompt. That is fine: the commands in this guide work the same way.Read the prompt. The text at the start of the line is called the prompt. It tells you which folder the computer is looking at, and it waits for you to type. On Windows it ends with the
>sign, for exampleC:\Users\Sam>. On a Mac it ends with%(or$on an older Mac), for examplesam@Mac ~ %. The~sign means your home folder.Learn how to type a command. Type it exactly as shown in this guide, then press Enter. Nothing happens until you press Enter. Spaces matter, so leave a space between a command and the name after it, as in
cd Documents. On a Mac, capital letters matter too:Documentsis not the same asdocuments. On Windows they do not matter.Try a harmless first command. Type
whoamiand press Enter. The computer prints your user name on the next line, for examplemylaptop\samon Windows orsamon a Mac. Nothing has been changed. If you see a message such as 'not recognized' or 'command not found', check your spelling and try again.Find out which folder you are in. On Windows, type
cdon its own and press Enter. On a Mac, typepwdand press Enter. The computer prints the full address of the folder you are in, for exampleC:\Users\Samon Windows or/Users/samon a Mac. A new window always starts in your home folder, the folder that holds Documents, Downloads and Pictures.See what is inside the folder. On Windows, type
dir. On a Mac, typels(short for list). The computer lists the files and folders here, the same things you would see in File Explorer or Finder. On Windows, a folder has<DIR>beside it. On a Mac,lsshows names only.Move into a folder. Type
cd, a space, and the name of a folder from the list, then press Enter. For example, typecd Documents. Nothing seems to happen except that the prompt changes to show the new folder. The letters cd stand for change directory (directory is the computer word for folder). Type the name exactly as it appears in the list.Go back up one folder. Type
cd ..(cd, a space, then two full stops) and press Enter. This takes you up one level, back to the folder you came from. To jump straight to your home folder from anywhere, typecd %userprofile%on Windows, or justcdon its own on a Mac. Make sure you are back in your home folder before the next step.If a folder name has a space in it, put the name in double quotation marks, for example
cd "My Photos". Without them, the computer reads My and Photos as two separate words. Windows forgives this forcd, but a Mac and most other commands do not. The quotation marks are always safe to use, so use them whenever a name has a space.Make a practice folder. In your home folder, type
mkdir Practiceand press Enter. The letters mkdir stand for make directory. Typedir(Windows) orls(Mac) to check that Practice is now in the list.Go into the practice folder. Type
cd Practiceand press Enter. The prompt now ends with Practice. Everything you do from here happens inside this folder, which is empty.Create a small text file. Type
echo Hello > hello.txtand press Enter. This works the same on Windows and on a Mac. The>sign tells the computer to put the word into a file instead of showing it on the screen. Nothing is printed when it works. Typedirorlsto see hello.txt in the list.Show what is inside the file. On Windows, type
type hello.txt. On a Mac, typecat hello.txt. The computer prints the word Hello.Copy a file. On Windows, type
copy hello.txt backup.txt. On a Mac, typecp hello.txt backup.txt. The first name is the file you have, and the second name is the name for the copy. Typedirorlsand you will see two files now.Rename a file. On Windows, type
ren backup.txt notes.txt. On a Mac, typemv backup.txt notes.txt(mv is short for move). The first name is the old name and the second is the new name. Typedirorls: backup.txt has gone and notes.txt is there. The same command can also move a file into another folder (it is calledmoveon Windows), but you do not need that now.Delete a file. Read this first: a file deleted this way does not go to the Recycle Bin or Trash, so it cannot be brought back. On Windows, type
del notes.txt, press Enter, then typedel hello.txtand press Enter. On a Mac, typerm notes.txt, press Enter, then typerm hello.txtand press Enter. Typedirorlsto check that the folder is empty again.Remove the practice folder. First go back up with
cd ... Then typermdir Practiceand press Enter. The rmdir command only removes an empty folder, which keeps it safe: if the folder still holds files, the computer refuses and tells you. Typedirorlsto check that Practice has gone.Clear the screen. When the window fills up with text, type
clson Windows orclearon a Mac. This only tidies the screen. It does not delete anything.Get help for a command. On Windows, type
helpfor a list of commands, orhelp copyto read about one command. On a Mac, typeman cpto open the manual for a command (replace cp with any command). Press the Space bar to scroll down a page and pressqto quit and return to the prompt.Use three shortcuts to save typing. Press the Up arrow key to bring back the last command you typed, then press Enter to run it again. Type the first letters of a file or folder name and press the Tab key, and the computer finishes the name for you. Press the Ctrl key and the C key together to stop a command that is still running.
Check your internet connection. Type
ping google.comand press Enter. The ping command sends a small message to another computer and shows whether it answers. On Windows it stops by itself after four tries. On a Mac it keeps going, so press the Ctrl key and the C key together to stop it. Lines that start with Reply from (Windows) or 64 bytes from (Mac) mean you are online.Close the window. Type
exitand press Enter, or click the close button on the window. You can now open it again whenever you need it.
If it did not work
- It says 'not recognized' (Windows) or 'command not found' (Mac). Check the spelling, and check that there is a space between the command and the name after it. Then type the command again.
- It says 'cannot find the path specified' or 'No such file or directory'. The name is wrong, or the file or folder is in a different folder. Type
dirorlsto see the names in the folder you are in, and copy the spelling exactly. On a Mac, check the capital letters. - The line starts with PS. You have opened PowerShell, not Command Prompt. Most commands in this guide also work there, but
cd %userprofile%does not. Close the window, press the Windows key, typecmdand press Enter. - A command seems stuck and no new prompt appears. It is probably still running. Press the Ctrl key and the C key together to stop it.
- I deleted the wrong file. A file deleted with del or rm does not go to the Recycle Bin or Trash. Look for it in a backup, such as File History, OneDrive, Time Machine or iCloud. This is why this guide has you practise in a new folder first.
- My Mac asks if Terminal can access my Documents, Desktop or Downloads folder. This is a normal privacy message. Click OK or Allow only if you typed the command yourself.
- Windows says 'Access is denied'. That folder is protected. Do not try to force it. Go back to your home folder and use only the Practice folder.
- My prompt looks different from the pictures. Names and colours differ from computer to computer. Look for the folder name and for the sign at the end of the line, which is > on Windows and % or $ on a Mac.
Watch a video
CMD File & Folder Operations (mkdir, cd, dir, del) (Windows)
Learn Mac Terminal Basics (Mac)
Opens YouTube in a new tab. These videos are made by other people, not by Drawnsteps, and may differ from the steps above.
Spotted a mistake or something unclear? Report a problem.