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.

Time: About 30 minutesDifficulty: Easy

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.
A two-column table of the main commands. Where am I: cd on Windows, pwd on Mac. List files: dir, ls. Go into a folder: cd name on both. Go up one folder: cd .. on both. Make a folder: mkdir name on both. Show a file: type, cat. Copy: copy, cp. Rename: ren, mv. Delete: del, rm. Clear the screen: cls, clear.

What you need

Steps

  1. 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.

    Two ways to do the same job. With the mouse, you double-click the Documents folder in a folder window. With a command, you type cd Documents in Command Prompt or Terminal. Both open the Documents folder.
  2. 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, type Terminal, 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.

    Two panels. Windows: press the Windows key, type cmd, then press Enter on the Command Prompt result. Mac: press Command and Space, type Terminal, then press Enter.
  3. 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 example C:\Users\Sam>. On a Mac it ends with % (or $ on an older Mac), for example sam@Mac ~ %. The ~ sign means your home folder.

    Two terminal windows. Windows shows C:\Users\Sam> with the folder name marked 1 and the sign at the end marked 2, where you type. Mac shows sam@Mac ~ % with the user and computer name marked 1, the folder marked 2 and the percent sign marked 3, where you type.
  4. 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: Documents is not the same as documents. On Windows they do not matter.

    Three stages. 1: type the command with a space after the command word, for example cd Documents. 2: press the Enter key, because nothing happens until you do. 3: the computer carries it out and the prompt changes. A note says that on a Mac capital letters matter: cd Documents works but cd documents is not found.
  5. Try a harmless first command. Type whoami and press Enter. The computer prints your user name on the next line, for example mylaptop\sam on Windows or sam on 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.

  6. Find out which folder you are in. On Windows, type cd on its own and press Enter. On a Mac, type pwd and press Enter. The computer prints the full address of the folder you are in, for example C:\Users\Sam on Windows or /Users/sam on a Mac. A new window always starts in your home folder, the folder that holds Documents, Downloads and Pictures.

    On Windows, typing cd prints C:\Users\Sam. The path is shown as boxes: C: then Users then Sam, each inside the one before, with Sam the folder you are in. On a Mac, typing pwd prints /Users/sam, shown as boxes: slash, Users, sam.
  7. See what is inside the folder. On Windows, type dir. On a Mac, type ls (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, ls shows names only.

    A folder window showing two folders, Letters and Photos, and two files, Budget.xlsx and Notes.txt. An arrow points down to two terminal windows showing the same four items as text. On Windows the command is dir and folders are marked DIR. On a Mac the command is ls and only names are shown.
  8. Move into a folder. Type cd, a space, and the name of a folder from the list, then press Enter. For example, type cd 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.

    Two folder trees. On the left the Sam home folder is highlighted as the folder you are in. An arrow labelled cd Documents points to the right tree, where the Documents folder is highlighted. A return arrow labelled cd two dots goes back up. Below, the prompt before and after: on Windows C:\Users\Sam then C:\Users\Sam\Documents, and on a Mac sam@Mac ~ then sam@Mac Documents.
  9. 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, type cd %userprofile% on Windows, or just cd on its own on a Mac. Make sure you are back in your home folder before the next step.

    Three folders stacked: Sam (home) at the top, Documents below it and Practice at the bottom, marked as the folder you are in. Each arrow labelled cd two dots goes up one folder. A separate box shows how to jump straight home: cd %userprofile% on Windows, or just cd on its own on a Mac.
  10. 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 for cd, 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.

    Two panels. Without quotation marks, cd My Photos is read as three separate words, so the computer treats My and Photos as two names. With quotation marks, cd "My Photos" is read as two words, and My Photos stays together as one folder name.
  11. Make a practice folder. In your home folder, type mkdir Practice and press Enter. The letters mkdir stand for make directory. Type dir (Windows) or ls (Mac) to check that Practice is now in the list.

    Before: the Sam home folder holds Documents, Downloads and Pictures. After typing mkdir Practice, a new folder called Practice appears beside them. The command is the same on Windows and Mac.
  12. Go into the practice folder. Type cd Practice and press Enter. The prompt now ends with Practice. Everything you do from here happens inside this folder, which is empty.

  13. Create a small text file. Type echo Hello > hello.txt and 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. Type dir or ls to see hello.txt in the list.

    The command echo Hello > hello.txt with four parts numbered. 1: echo is the command that shows text. 2: Hello is the words to put in the file. 3: the greater-than sign sends it into a file instead of the screen. 4: hello.txt is the name of the new file. The result is a new file called hello.txt that holds the word Hello.
  14. Show what is inside the file. On Windows, type type hello.txt. On a Mac, type cat hello.txt. The computer prints the word Hello.

    A file called hello.txt that holds one word, Hello. An arrow shows it being displayed in the window. On Windows the command is type hello.txt and the window prints Hello. On a Mac the command is cat hello.txt and the window prints Hello.
  15. Copy a file. On Windows, type copy hello.txt backup.txt. On a Mac, type cp hello.txt backup.txt. The first name is the file you have, and the second name is the name for the copy. Type dir or ls and you will see two files now.

    Before: one file called hello.txt. After: hello.txt is still there and a new copy called backup.txt sits beside it. On Windows the command is copy hello.txt backup.txt, with the parts labelled: the command, the file to copy and the name for the copy. On a Mac the command is cp hello.txt backup.txt.
  16. Rename a file. On Windows, type ren backup.txt notes.txt. On a Mac, type mv backup.txt notes.txt (mv is short for move). The first name is the old name and the second is the new name. Type dir or ls: backup.txt has gone and notes.txt is there. The same command can also move a file into another folder (it is called move on Windows), but you do not need that now.

    Before: a file called backup.txt. After: the same file is now called notes.txt and backup.txt is gone. On Windows the command is ren backup.txt notes.txt, with the parts labelled command, old name and new name. On a Mac the command is mv backup.txt notes.txt.
  17. 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 type del hello.txt and press Enter. On a Mac, type rm notes.txt, press Enter, then type rm hello.txt and press Enter. Type dir or ls to check that the folder is empty again.

    Before: two files, hello.txt and notes.txt, with notes.txt marked to delete. After: only hello.txt is left and notes.txt is gone. A red warning shows a crossed-out bin: the file does not go to the Recycle Bin or Trash. On Windows the command is del notes.txt. On a Mac it is rm notes.txt.
  18. Remove the practice folder. First go back up with cd ... Then type rmdir Practice and 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. Type dir or ls to check that Practice has gone.

    Two cases. An empty folder called Practice: typing rmdir Practice removes it with no message. A folder that still has files: rmdir Practice is refused, with the message The directory is not empty on Windows or Directory not empty on a Mac, so nothing is lost.
  19. Clear the screen. When the window fills up with text, type cls on Windows or clear on a Mac. This only tidies the screen. It does not delete anything.

  20. Get help for a command. On Windows, type help for a list of commands, or help copy to read about one command. On a Mac, type man cp to open the manual for a command (replace cp with any command). Press the Space bar to scroll down a page and press q to quit and return to the prompt.

    On Windows, typing help copy prints a short description of the copy command. On a Mac, typing man cp opens a manual page with a colon at the bottom waiting for a key. Press Space for the next page and q to quit and return to the prompt.
  21. 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.

    Three cards. Up arrow brings back the last command you typed. Tab finishes a name for you after you type the first few letters, for example cd Doc becomes cd Documents. Ctrl and C together stop a command that is still running.
  22. Check your internet connection. Type ping google.com and 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.

    Two panels. Working: Windows shows a line starting Reply from and a Mac shows a line starting 64 bytes from. Not working: Windows shows Request timed out or Ping request could not find host, and a Mac shows Request timeout or cannot resolve.
  23. Close the window. Type exit and 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 dir or ls to 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, type cmd and 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.