Welcome back to the series “Becoming a Web Developer” part 6. If you are new here, you can start with this list [ part 1, part 2, part 3, part 4, part 5]. In this part, we will discuss the terminal and most used commands for web developers, and for more commands and details you can visit here.
Now, If you’re a web developer, software engineer, or just a tech enthusiast, you’ve probably used Linux commands and the terminal. But if you’re not, let’s get you to learn what are they, and why are they so important. Let’s dive in!
Table of Contents
The terminal, also known as the command line interface (CLI), is a tool that allows us to interact with our computer using text-based commands. It’s a powerful tool that gives us direct access to the operating system and allows us to perform tasks more efficiently than we could with a graphical user interface (GUI).
Linux commands are the language we use to communicate with the terminal. This originated in the Unix operating system but is now used in many other systems, including Linux and MacOS.
So why should you, as a web developer or software engineer, care about Linux commands and the terminal? Here are a few reasons:
- Efficiency: Linux commands can perform complex tasks quickly and with fewer steps than a GUI.
- Control: The terminal gives you more control over your system. You can access and modify files that are not visible or accessible in a GUI.
- Scripting: Linux commands can be combined into scripts, allowing you to automate repetitive tasks.
- Development Tools: Many tools for developers, like Git and Node.js, are primarily used through the terminal.
- Troubleshooting: Understanding Linux commands can help you diagnose and fix problems on your system.
In this article, we’ll start with the basics and what you need to learn to start with Linux as a software developer or web developer.
Before we dive into the commands and the terminal, let’s take a moment to understand what’s happening on the backend side of things. If you’re new to web development, you might be wondering,
What exactly is the backend?
In the context of web development, the ‘backend’ refers to the server side of an application. This is the part of the software that users don’t see. It’s where the magic happens: data is processed, stored, and sent back to the user. The backend is responsible for business logic, database interactions, server configuration, and much more.
Imagine you’re visiting an online store. The beautiful webpage you see, with all its images, buttons, and menus, is the ‘front end.’ It’s what you interact with. But when you click on a product to view more details or place an order, your request is sent to the ‘backend.’ The backend retrieves the product details from the database or processes your order, then sends the information back to the frontend to be displayed to you.
So, why is understanding the backend important for learning Linux commands and the terminal? Well, as a backend developer, or even a full-stack developer (someone who works on both the frontend and backend), you’ll often find yourself working in a Unix-like environment. You’ll need to navigate through your system’s directories, manipulate files, install software, and run scripts, all using the terminal. That’s why getting comfortable with Linux commands is such a crucial skill.
In the following sections, we’ll start exploring these commands, So, buckle up and get ready for an exciting journey!
Tips to Get comfortable with the Terminal
Getting comfortable with the terminal is a bit like learning to ride a bike. It might seem intimidating at first, but with practice, it becomes second nature. Here are some tips and strategies to help you become more comfortable with the terminal:
1. Practice Regularly
The best way to get comfortable with the terminal is to use it regularly. Try to incorporate it into your daily workflow. Need to create a new directory? Use
mkdir. Need to move a file? Use
mv. The more you use the terminal, the more familiar it will become.
2. Learn the Basics
Start with the basic commands like
cp. Understand what they do and practice using them. Once you’re comfortable with the basics, you can move on to more advanced commands and concepts.
3. Use the
man command is your built-in manual. Use it to learn about other commands and their options. For example,
man ls will show you the manual for the
ls command, including a description of what it does and a list of its options.
4. Don’t Be Afraid to Make Mistakes
It’s okay to make mistakes. In fact, making mistakes is a great way to learn. If you type a command and it doesn’t work, try to figure out why. Is there a typo in the command? Are you in the right directory? Did you forget an option?
5. Customize Your Terminal
Customizing your terminal can make it more pleasant to use. You can change the colors, prompt, and even add features like auto-completion and command aliases. There are also different terminal emulators you can try, each with their own set of features.
6. Learn to Use a Text Editor
Knowing how to use a text editor from the terminal is a valuable skill. Whether it’s Vim, Emacs, or Nano, choose one and learn the basics. You’ll need this skill for editing configuration files, writing scripts, and more.
7. Explore and Have Fun
Finally, don’t forget to have fun. A terminal is a powerful tool, and learning to use it effectively can open up new possibilities. Try new commands, write scripts, and automate tasks. The more you explore, the more comfortable you’ll become.
Listing and Path
Let’s kick things off with two of the most basic yet essential Linux commands:
pwd. These commands are your bread and butter when it comes to navigating the terminal. They’re the equivalent of looking around and checking your map in a new city.
ls command stands for ‘list’. As the name suggests, it lists the contents of a directory. When you type
ls into the terminal and hit enter, it will display all the files and directories in your current location.
Here’s an example:
Desktop Downloads Pictures Documents Music
ls has listed five directories: Desktop, Downloads, Pictures, Documents, and Music.
ls lists the contents of a directory. But it can do much more when used with options. Let’s look at some examples:
ls -l: This option displays the contents in a ‘long format’, which includes additional information such as the file permissions, number of links, owner, group, size, and time of last modification.
$ ls -l
drwx------+ 3 YourUsername staff 96 Mar 1 09:00 Desktop
drwx------+ 4 YourUsername staff 128 Mar 1 09:00 Documents
drwx------+ 3 YourUsername staff 96 Mar 1 09:00 Downloads
drwx------+ 3 YourUsername staff 96 Mar 1 09:00 Music
drwx------+ 3 YourUsername staff 96 Mar 1 09:00 Pictures
ls -a: This option shows all files, including hidden ones. In Unix-like systems, files that start with a dot (.) are hidden.
$ ls -a
. .. .bash_history .bash_profile Desktop Documents Downloads Music Pictures
ls -R: This option lists the contents of directories recursively, meaning it will show the contents of the directories within the current directory, and so on.
$ ls -R
Desktop Documents Downloads Music Pictures
pwd command stands for ‘print working directory’. It tells you where you currently are in your system’s directory structure. Think of it as checking your current location on a map.
Here’s an example:
In this example,
pwd has printed the path to the current directory, which is the user’s home directory.
pwd -P: This option prints the physical directory, without any symbolic links. If you’re in a directory that is a symbolic link (a file that points to another file or directory),
pwd -P will show the actual directory, not the linked one.
$ pwd -P
In this example, even if you navigated to the directory using a symbolic link,
pwd -P shows the path to the actual directory.
These two commands,
pwd, are your starting point for navigating the terminal. Practice using them until you’re comfortable. In the next sections, we’ll learn how to move around the directory structure and manipulate files. So, stay tuned!”
P.S. Remember, you can always use the
man command to read the manual and learn more about these commands and their options. For example,
man ls will show the manual for the
Navigation and Paths
Changing directories is a fundamental task you’ll do in the terminal. It’s like navigating through folders in a graphical file explorer, but instead, you’re using text commands. The command to change directories in Unix-based systems is
cd, which stands for “change directory”.
Let’s start with the basics. If you want to move into a directory, you type
cd followed by the name of the directory. For example, if you have a directory named
projects, you can move into it with:
Now, what if you want to move back to the previous directory? You can use
.. to represent the parent directory. So to move back, you can do:
You can also use
.. to move multiple levels up. For example,
cd ../.. will move two levels up.
If you want to go to your home directory, you can use the
cd command without any arguments:
You can also use
~ to represent your home directory. So
cd ~ will also take you home.
What about if you want to go to a specific directory, no matter where you currently are? You can do this by providing the absolute path to the directory. For example:
This will take you to the directory
/usr/local/bin, regardless of your current directory.
Remember, the terminal is case-sensitive. So
cd projects is different from
Also, if the directory name has spaces, you need to enclose it in quotes. For example:
cd "My Projects"
Or you can escape the space with a backslash:
cd My\ Projects
A relative path is a path that starts from your current directory. It’s ‘relative’ to where you are right now in the file system. For example, if you’re in a directory called
projects and there’s a subdirectory in it called
myapp, the relative path to
myapp is simply:
You can use this relative path with commands like
cd to move into
Relative paths can also use special directory names like
. (which represents the current directory) and
.. (which represents the parent directory).
An absolute path, on the other hand, is a path that starts from the root of the file system. It’s ‘absolute’ because it points to the same location, no matter where you currently are in the file system. An absolute path always starts with a
For example, the absolute path to a directory
myapp located directly under
projects in your home directory might look something like the following. You also can use this absolute path with
cd to go directly to
myapp, no matter your current location:
P.S. If you’re moving around directories close to your current location, relative paths are simpler. If you’re jumping to a directory far from your current location, absolute paths can be more direct.
Creating Directories (Folders)
Creating new directories (or folders) is a common task when organizing your files or setting up new projects. In the terminal, you can create directories using the
mkdir command, which stands for ‘make directory’.
The basic usage of
mkdir is straightforward. Just type
mkdir followed by the name of the directory you want to create. For example, to create a directory named
myproject, you would use:
This will create a new directory named
myproject in your current directory. You can verify that the directory was created using the
myproject was created successfully, you should see it listed in the output of
You can also create a directory in a different location by specifying a path. For example, to create a directory named
myproject in the
projects directory, you would use:
This assumes that the
projects directory already exists. If it doesn’t,
mkdir will give an error. However, you can tell
mkdir to create any necessary parent directories by using the
mkdir -p projects/myproject
This will create both
myproject if they don’t already exist.
touch command is a standard command used in UNIX/Linux operating system which is used to create, change and modify timestamps of a file.
Let’s say you want to create a new file named ‘example.txt’. You can do this using the
touch command like so:
If the file ‘example.txt’ does not already exist, the
touch command will create a new file with this name. If the file already exists,
touch will update the last-modified time of the file.
Removing Files & Folders
rmdir commands are used to remove files and directories respectively.
rm command removes specified files. For example, to remove a file named ‘example.txt’, you would use the
rm command like this:
Be careful when using
rm, as it deletes files permanently. It’s not like moving a file to the trash bin, it’s more like shredding that file!
rmdir command removes empty directories. To remove a directory, it must be empty of files and other directories. Here’s how you would remove a directory named ‘example_directory’:
If you want to remove a directory and its contents, you can use the
rm command with the
--recursive) flag. This tells
rm to remove the directory and its contents recursively. Be very careful when using this command, as it will permanently delete the directory and everything within it:
rm -r example_directory
touch is used to create or update files,
rm is used to remove files and directories, and
rmdir is used to remove empty directories.
More Tips and Best Practices
- Master the basics: Start with the basic commands like
mkdir. Once you’re comfortable with these, you can start learning more advanced commands.
- Use Tab Completion: This is a handy feature that allows you to auto-complete file and directory names. Simply start typing the name and then press Tab to auto-complete it.
- Learn to use the man pages: The
mancommand followed by any other Linux command will display the manual page for that command. This is a great way to learn what a command does and how to use it.
- Use the history command: The
historycommand will show you the last commands you’ve used. This can be very helpful if you need to repeat a command or can’t remember a command you used previously.
- Learn to use pipes and redirection: Pipes (
|) and redirection (
<) are powerful features that allow you to chain commands together or redirect input and output.
Common Mistakes and How to Avoid Them
- Deleting the wrong file: Always double-check the file name before running a
rmcommand. You might also want to use the
-i(interactive) option with
rmto confirm before deleting.
- Using wildcards carelessly: Wildcards like
*can be very useful, but they can also be dangerous if used carelessly. For example,
rm *will delete all files in the current directory!
- Not understanding command options: Before using an option (like
rm), make sure you understand what it does. The man pages are a great resource for this.
- Overusing sudo: The
sudocommand gives you superuser privileges, which means you can do things that regular users can’t, like deleting system files. Use
sudosparingly and only when necessary.
- Not backing up data: Always back up important data. While Linux commands can be powerful, they can also be destructive if used incorrectly.
We’ve taken quite a journey through the world of Linux commands and the terminal. We started with the basics, learning about commands like
pwd, and then moved on to making directories, removing files, and understanding man pages and flags. We’ve also discussed some common mistakes and best practices to keep in mind when working with the terminal.
Remember, don’t be discouraged if you don’t remember all the commands or concepts right away. Keep practicing, keep experimenting, and before you know it, you’ll be wielding the terminal like a pro.
For those of you who are eager to continue your journey with Linux commands and the terminal, here are some additional resources that you might find helpful:
- The Unix Shell: A great tutorial for beginners from Software Carpentry.
- Linux Command Line Basics: A free course from Udacity that covers the basics of the Linux command line.
- Advanced Bash-Scripting Guide: For those interested in scripting, this guide is a comprehensive resource.
- Explain Shell: A handy tool that explains what each part of a Unix command does.
- ManKier: Another great tool for understanding Unix commands. It provides explanations for commands and their options.