Working with the Terminal (Windows): an overview

Git Bash shows the same folders as File Explorer, as text you type, starting from your home folder (~) and the ls command.

Novice · Operating System · Software Development · Updated

After this lesson you can

  • List a folder's contents with ls in Git Bash and match them to what File Explorer shows

Key takeaways

  • File Explorer and Git Bash show the same folders. File Explorer uses windows and clicks; Git Bash uses commands you type.
  • In Git Bash, ~ is your home folder, the one File Explorer shows as C:\Users\alex.
  • ls lists the files and folders in the folder you are in. A / after a name means it is a folder.
  • explorer . opens the folder you are in, in File Explorer, so you can check what a command did.

You already work with files in File Explorer: double-click to open a folder, right-click to rename a file. The terminal does the same jobs by typing. You met it in the last topic, running Git. In this topic you will use it to move around your folders and manage your files, because Git and every build tool in the course run there.

Two views of the same folders

File Explorer is a GUI (graphical user interface): windows, icons and clicks. Git Bash is a command line: you type a command, press Enter, and read the answer as text.

Both show the same folders on the same drive. A folder you make in one appears in the other straight away.

Here is the home folder in File Explorer:

File Explorer showing the home folder, C:\Users\alex, with the folders Desktop, Documents, Downloads, Music and Pictures listed

Your home folder: ~

Open Windows Terminal. Git Bash starts in your home folder, and its prompt shows a ~ (a tilde) to say so:

alex@LAPTOP MINGW64 ~
$

~ is short for your home folder. Git Bash's long way of writing it is /c/Users/alex, and File Explorer writes it as C:\Users\alex. All three are the same folder. Your username will be different from alex.

List what is here: ls

Type ls (list) and press Enter:

ls

Git Bash lists what is in the folder you are in. Here is part of the list:

AppData/   Contacts/   Desktop/   Documents/   Downloads/   Music/   NTUSER.DAT   Pictures/
  • A name ending in / is a folder. A name without one is a file.
  • Your list will be longer than this. Windows keeps some files and folders of its own in your home folder, such as NTUSER.DAT and AppData. Leave them alone.
  • A name ending in @ is a shortcut Windows keeps for old programs, such as My Documents@. You can ignore those too.

The folders you know from File Explorer, such as Desktop, Documents and Downloads, are all in the list.

See it both ways

Git Bash can open File Explorer on the folder you are in:

explorer .

The . means "the folder I am in now". Use it whenever you want to check what a command did.

Try it. In Git Bash, run ls, then explorer .. Find three folders that are in both lists.

Check yourself

2 questions to try on the lesson page.

So what

Every command you type runs in some folder. Knowing which folder you are in, and what is in it, is the first thing to check when a command doesn't do what you expected.

Key terms

  • Command Line
  • ls
  • Home Directory