Table of contents
Introduction
In the previous article, you learned how to install Git Bash onto your local machine.
Now that you've downloaded Git Bash, you can start navigating (and later changing) the file system.
In this article, I'll teach you some basic commands to help you navigate the file system.
NOTE #1: Throughout the article, I'll be referencing this binary tree image from this Wikipedia article. I suggest that you keep this open in a separate tab to reference while reading.
NOTE #2: You might want to be at a computer or laptop (to get the full experience).
cd
Let's start with cd
. Use this command to go "up" or "down" to a particular directory (aka folder).
Let's say that you're in the directory Encyclopaedia
, which, in this case, is the root directory.
GIT BASH JARGON: "root directory" refers to the top-level directory in a file system. All other directories - such as Science, Culture, Art, and Craft (in this case) - branch off of the root directory. They're called subdirectories.
You want to go from Encyclopaedia
"down" into the Science
directory. To do that (for this and any other directories), use:
cd <directory-name>
in this case, replacing <directory-name>
with Science
.
NOTE: You must be on the same path as your desired directory.
For example, if you tried to go from where you are now (Science
) into the Culture
directory, it would result in this error: bash: cd: Culture: No such file or directory
.
This happens because there isn't a file (or directory) named Culture
on the path you're on.
GIT BASH JARGON: A path defines the location of a file or directory in relation to the file system. In the example above, the path from the root directory to the
Science
directory is (/Encyclopaedia/Science/
). The path from the root directory to theCulture
directory is (/Encyclopaedia/Culture/
).
You might notice that Science
and Culture
are on different paths. So, to get to the Culture
directory, you'd have to go "up" the directory tree.
PERFECT TIME TO LEARN HOW TO! ๐
To go "up" once the directory tree, use the following:
cd ..
Let's say you used it, and are now in the Encyclopaedia
directory. Voila!
NOTE #1: To go up more than once, add a forward slash (/
) and two more periods for each level you'd like to go up.
NOTE #2: When going "up" the directory tree, you do not have to be on the same path as your desired directory. It works anywhere, anytime, no matter what.
You're almost done! There are a couple more tips to learn.
Now, I'll teach you how to move "down" your directory tree, more than once.
Remember the note about being on the same path as where you'd like to go!
After that last command (cd ..
), you're in the directory Encyclopaedia
. You'd like to go down to the Craft
directory.
To do that, try this:
cd <directory-name>/<directory-name>/<directory-name>...
again replacing <directory-name>
with the actual path.
In this case, you'd replace it with cd Culture/Craft/
.
Lastly, know that you can use cd
by itself. Doing so takes you to your root directory, as I explained earlier.
pwd
Now that you know how to use cd
, let's move on to pwd
. Use this to print your current working directory (aka where you are in your folder tree) to the terminal.
GIT BASH JARGON: A terminal is a text-based interface, used for typing commands and interacting with your local machine. Git Bash is an example of a terminal.
pwd
is helpful if you aren't sure what path you are on, or to verify where you are in the tree.
ls
The last basic command to know how to use is ls
. This command lists the contents of your current directory.
Say you used cd
to go back to your root directory (Encyclopaedia
). If you entered ls
there, it would show up like this:
Science/ Culture/
Using the same logic, if you first typed cd Culture
, then typed ls
, it would show up like this:
Art/ Craft/
What if you changed into the Science
directory instead?
In that case (and all other cases with empty directories), nothing would show up. It's empty.
NOTE: All logic that applies to cd
applies to ls
. There's only one difference: ls
only lists the directories, whereas cd
actually moves you around the directory tree.
In this article, you learned some basic commands to help you navigate the file system, including: - cd (used to change directories) - pwd (used to print the working directory) - ls (used to list the contents of the current directory)
Great job on completing the second part of the series!
Conclusion
This is the 2nd part of a 10 part series to teach Windows users about Git Bash. This series includes:
how to install Git Bash
how to change your file system
how to set up Git and GitHub
how to connect Git and GitHub
how to keep up good practices in Git
how to backtrack in Git
how to branch in Git
...and more!!
Stay tuned for more - a new part will come out every Tuesday! ๐