Learn the Command Line!
svg files cannot be displayed: https://replanalytics.repl.co/track/1a7dc1bf-462c-47c6-8cf3-11f52de679be/badge.svg
How to use
Hi, today I will be teaching you how to navigate the file system using a software called
Bash stands for Bourne Again SHell.
Bash is the most popular
Terminal is an application that comes installed on Windows, Mac, and Linux, which you can use to navigate between, create, and view files.
Note: If you see something called
CLI, just know that is shorthand for "Command Line"
Opening Bash on
Bash is the default
Terminal Program in
Bash comes installed on all versions of
MacOS Catalina and after, there is a very similar application called
Zsh. It's basically the same thing. To open Bash, first navigate to
Finder. Then, go to the
Applications folder. In there, look for
Terminal. Double click the icon, and voila! You have opened
If you had a little trouble understanding all this, here's the step-by-step version
- Navigate to
- Go to the
- Search for
- Double click the icon that shows up.
Opening Bash on
Linux and Ubuntu
Bash is the default
Terminal program in
Linux and Ubuntu.
Linux or Ubuntu, go to the list of programs and open the program that says
Terminal Emulator. Open it, and you have opened
Bash is much more complicated on
Windows does not use the
Bash software for
Terminal/Powershell/Command Prompt. While the
Bash and the software
Windows uses for its
CLI are different, some commands that are available in
Bash are not in
CLI. So just take note that
Bash is much better. Since
Bash is not directly available on
Windows, we will be downloading something called
Git Bash. This is virtually the same thing as
Okay, so now let's actually download
Git Bash for
First, navigate to this site: Git Bash.
Then click the
Download link. If you can't see it, here is the link: Download Git Bash. You may need
Administrator control over the computer. Go through all the steps the Wizard takes you through. At some point, it may ask you for your text editor preference. I recommend selecting
Visual Studio Code. Finally, press
Finish. The application might start up automatically, or, if it doesn't, go to the
Windows search bar. Search for
Git Bash. Press
Enter. You have successfully opened
Do not ever 'Pin'
Git Bashto your taskbar in
Windows. Some glitches may occur while doing this.
That was quite a lot! If you had trouble understanding the steps, here is the task-by-task version
- Open the
Git for Windowslink: Git Bash
- Click the download link: Download Git Bash
- You might need
Administratorcontrol over the computer to download
Git Bash. Do what the download wizard says. When it asks you for the text editor of your choice, I recommend you select
Visual Studio Code.
Now let's actually start using
First, we're going to learn some very basic words.
Directory means a folder.
Files are things that contain information like words or code.
Before we start learning the commands, I just need to tell you a few very useful tricks:
- Using the
tab key. This can be very useful when typing out long directories or files. If you want to navigate to a directory called "Something Random", you can use this:
cd "Something + 'tab'".When you hit the tab key, it will automatically fill up the directory name. It's okay if you don't understand what
cdmeans. You will learn it before the end of this tutorial.
- Another very useful trick is
clear. This just cleans up the
Next I'll teach you some commands.
cdstands for Change Directory
cd changes from the current directory to the specified directory. For example, say my current place is
/c/users/username/. The next directories I can go to are
Documents, and some more. I'll teach you how to see that these directories are accessible later. I want to go to the
Desktop directory. So, I type in
cd Desktop. And voila! You are now in the
Desktop directory! However, IF the next directory is two or more words, you must use quotes around the directory you want to go to. For example, let's go back to my
C:\Users\username directory. Say there is another directory called
My Documents along with the
Documents. Then, to change from the
username directory to the
My Documents directory, you would do
cd 'My Documents'. You can use single quotes or double quotes. Next, going off of the
cd command is the
cd .. command. The
cd .. command goes up one current directory. Remember when I was at
/c/users/username/desktop/? I went back to
/c/users/username and navigated to
/c/users/username/'My Documents'. To do that, I could do
cd ../'My Documents'.
What does this do?
cd ..goes up one directory. (From
/'My Documents'is a continuation of the
cdcommand. It goes to the
This is ls as in the lowercase L, not the number one
ls basically lists all the directories and files accessible in the current directory. Remember, earlier, how I knew that the directories available in the
username directory were
My Documents, and some other stuff? Well, I figured that out using
ls. This can be really helpful when you don't have all the directories and files that are in a directory memorized. There are some other things you can add on to
ls such as
ls -a, and
ls -t. But for the sake of simplicity, I'm not going to go into detail about these commands.
pwdmeans Print Working Directory
pwd is a really simple command. All it does is show the current working directory. For example, if I don't know what directory I am on right now, I can simply use
pwd to find that out.
mkdirmeans MaKe a new DIRectory
Now is when you really start harnessing the power of the
mkdir is an awesome command that makes a new directory!
For example, let's say that I am in the
root directory right now. The
root directory is the base directory I see when I start up
Bash. For me, it is
MacOSX it is a little different, but don't worry. Say I want to make a new directory called
tutorials where I store all my tutorials in
HTML format. I do the following command:
mkdir "Tutorials". Now, to see if I succeeded in creating that new directory, I can do:
cd "Tutorials". Yay, you just created a new directory!
rmdirmeans ReMove DIRectory
rmdir removes the specified directory. Remember the directory
Tutorials we created a while ago? Well, we just realized we don't want this to be in the
root directory. We want it to be in our
Desktop. So, let's harness the power of
rmdir and do this!
- If you are still in the
Tutorialsdirectory, go up one directory
- Remove the
Tutorialsdirectory. Check the hint below if you don't fully understand how to do this.
- Go to the
- In step 1, do:
- Hint: For step two, do the following command:
- In step 2, do:
- Make a new directory called
rm -rcan also be used instead of
touchcreates a new file
touch creates a new file. To see this in action, first navigate to your
Tutorials directory in
Terminal. It should be in
Desktop. Next, do the following command:
touch "index.html". Now you have a file! If you do
ls, you should be able to see that it lists
index.html. I will teach you how to put content in the file in a bit.
rm removes files.
So we removed directories, but we didn't remove files! We just decided that we don't want the
HTML file to be named
index. So, we are going to delete the file and make a new file with a different name! Make sure you are in the "Tutorials" directory. You can make sure of this using the
pwd command. Do
ls to see if the "index.html" file is still there. Now, do the following:
rm "index.html". Make sure you get the name of the file exactly right, or else it won't work. Now do
ls. You shouldn't see anything. And you just learned how to delete a file in
Terminal! Now make a new
HTML file called
ls to make sure the file got created. You should only see
echobasically puts words in files.
First navigate to the
Tutorials directory. Do
ls to make sure "LearningCLI.html"
echo is one of the most handy commands in
CLI! To use
echo, do the following:
echo "I'm learning the CLI!"" >> "LearningCLI.html"
Now use the command
cat(which we'll learn about later) to do this:
Used the simplest way,
catcan show the contents inside a file
This is an on-your-own exercise. Go to Terminal, and navigate to a directory containing some
.txt file. Do:
cat filename. You should see the contents inside the file!
grepsearches for the specified file among all the available directories.
grepmeans “global regular expression print.” It searches files for lines that match a pattern and then returns the results. It is also case sensitive.
We do NOT need quotes when searching for a file or directory.
This is very confusing, so I will not go into detail about it. Feel free to Google it.
|Command||What It Does|
|Navigates to the specified directory|
|Goes up one directory|
|Lists all directories and files accessible in the current directory.|
|Shows the current working directory|
|Makes a new directory|
|Removes the specified directory|
|Removes the specified file|
|Creates a new file in the current directory|
|Puts words in specified file using redirect symbol: >>|
|Shows the contents inside a file|
|Searches for the specified lines inside a specified file. Format: |