As an aspiring developer, just looking at the command line (or the shell) can be intimidating. Once you start using it regularly and getting more comfortable with it, you’ll see how powerful it really is. Looking cool using it is just a plus.
If you're wanting to become a serious web developer, you need to learn how to use the command line. If you already know the basics then this blog isn’t for you but pass it on to a friend who could learn a thing or two!
What is the Command Line?
The command line is called different names for different platforms. For example, on Mac, it’s called the terminal, Powershell for Windows, and bash for Unix. The overall idea and functionality stays the same across different platforms, but the commands might be slightly different.
Now, it’s time to explain what the command line actually does… You’re probably used to using your mouse or trackpad to perform a task like opening a file or program, right? The command line is what was used to tell your computer what to do when there were just keyboards. Think of it as navigating through files just like you would using Finder or Windows Explorer.
Why is it Important to Learn How to Use It?
You might be thinking: “Why do I have to learn this if I can just use Finder or Windows Explorer?”
Learning how to use the command line will save you hours and give you more control. Making changes that would be tedious (or impossible) only using the user interface can be done with the command line in a fraction of the time. You can spend hours doing a repetitive task or five minutes writing a command line that gets it done in a second.
The shell also helps you learn and teach. It’s easier to give someone a tutorial using command lines instead of having to take screenshots or a screen recording of what’s going on and what steps they need to take.
Useful Commands
pwd
Type pwd
into terminal to see where you are right now. The letters stand for “print working directory”. Mine outputs /Users/home/SDG, but yours will be different depending on where you are in your computer.
When do you use pwd
? Use pwd
when you want to see where you are in the terminal.
cd
Congrats, you know where you are! Now, it’s time to move around.
Typing cd
will take you back to your home folder.
Type cd . .
to go to the directory above the one you’re currently in.
And if you type, cd
- you’ll go back to the directory you were in before the last time you used cd
.
Type cd folder_name
to move into a new folder.
When do you use cd
? When you want to move into a new folder or project within your computer.
ls
ls
stands for "list files" and will list all of the files in the current directory that you’re working in. This command lets you see what files you can use.
When do you use ls
? When you want to see what files are in your current working directory.
mkdir
mkdir
or “make directory” allows us to make a new folder from the terminal.
When do you use mkdir? When you want to make a new folder. We can and should make new folders to manage and organize projects.
git
git
is used for coordinating work among programmers, but it can also be used to track changes in files.
Git is different than GitHub. GitHub is a web-based service that lets you manage repositories while Git is a tool to manage and save changes to your code. In other words, Git is a tool and GitHub is the service that runs Git.
When do you use git
? Use it when you want to save changes. The most common uses for git
is “making a commit” or “pushing to GitHub”. You can do much more than that using Git, but as a budding developer, that’s all you need to focus on for now.
Here’s how to save your changes:
git add .
git commit -m "A message about what you did"
To save your changes to GitHub, you need to run:
git push origin master
Open VS Code
To open VS Code, you’ll use code folder_name
. If you’re not familiar with VS Code, it’s what we use at Suncoast Developers Guild's Academy to write and edit code. You can use this command line to open the current folder in VS Code: Code .
Note that there is a space between the word and the . (which represents the current directory).
When do you use this command? When you want to open a project to edit or write code.
Yarn
Yarn is a task runner and package manager for node. This command line can do much more, but for a new developer, we’ll use it to run and deploy apps.
How do you use yarn? Once you’re in the directory that you want to work from, use yarn to start your HTML/CSS/JavaScript apps by typing yarn start
into your terminal.
Conclusion
We know terminal and the command line can be daunting when you’re first getting started in web development, but it’s really just another way of interacting with your computer. Using command lines saves you time, headaches, and lets you have more power and control.