DEV Community

Cover image for The Complete Guide to Becoming a Web Developer: Part 6
Ahmed Radwan
Ahmed Radwan

Posted on • Originally published at nerdleveltech.com

The Complete Guide to Becoming a Web Developer: Part 6

Welcome back to the series “Becoming a Web Developer” part 6. If you are new here, you can start with this list [ part 1part 2part 3part 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!

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:

  1. Efficiency: Linux commands can perform complex tasks quickly and with fewer steps than a GUI.
  2. 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.
  3. Scripting: Linux commands can be combined into scripts, allowing you to automate repetitive tasks.
  4. Development Tools: Many tools for developers, like Git and Node.js, are primarily used through the terminal.
  5. 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.

Backend? 🧐

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 ls, pwd, cd, mkdir, touch, rm, and 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

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: ls and 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.

The ls Command

The 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:

$ ls
Desktop    Downloads  Pictures  Documents  Music

This example, ls has listed five directories: Desktop, Downloads, Pictures, Documents, and Music.

As mentioned, 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
total 0
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

./Desktop:
file1.txt  file2.txt

./Documents:
doc1.docx  doc2.docx

./Downloads:
image1.jpg  image2.jpg

./Music:
song1.mp3  song2.mp3

./Pictures:
photo1.png  photo2.png

The pwd Command

The 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:

$ pwd
/Users/YourUsername

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
/Users/YourUsername/ActualDirectory

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, ls and 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 ls command.

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:

The cd command

cd projects

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:

cd ..

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:

cd

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:

cd /usr/local/bin

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 cd Projects.

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

Relative Paths

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:

myapp
cd myapp
cd ..

You can use this relative path with commands like cd to move into myapp.

Relative paths can also use special directory names like . (which represents the current directory) and .. (which represents the parent directory).

Absolute Paths

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:

/home/username/projects/myapp
cd /home/username/projects/myapp

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:

mkdir myproject

This will create a new directory named myproject in your current directory. You can verify that the directory was created using the ls command:

ls

If myproject was created successfully, you should see it listed in the output of ls.

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:

mkdir projects/myproject

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 -p option:

mkdir -p projects/myproject

This will create both projects and myproject if they don't already exist.

The touch Command

The 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:

touch example.txt

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

The rm and rmdir commands are used to remove files and directories respectively.

The rm command removes specified files. For example, to remove a file named 'example.txt', you would use the rm command like this:

rm example.txt

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!

The 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':

rmdir example_directory

If you want to remove a directory and its contents, you can use the rm command with the -r (or --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

In summary, 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

  1. Master the basics: Start with the basic commands like ls, cd, pwd, touch, rm, and mkdir. Once you're comfortable with these, you can start learning more advanced commands.
  2. 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.
  3. Learn to use the man pages: The man command 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.
  4. Use the history command: The history command 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.
  5. 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

  1. Deleting the wrong file: Always double-check the file name before running a rm command. You might also want to use the -i (interactive) option with rm to confirm before deleting.
  2. 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!
  3. Not understanding command options: Before using an option (like -r with rm), make sure you understand what it does. The man pages are a great resource for this.
  4. Overusing sudo: The sudo command gives you superuser privileges, which means you can do things that regular users can't, like deleting system files. Use sudo sparingly and only when necessary.
  5. Not backing up data: Always back up important data. While Linux commands can be powerful, they can also be destructive if used incorrectly.

Conclusion

We've taken quite a journey through the world of Linux commands and the terminal. We started with the basics, learning about commands like ls and 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.

Additional Resources

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:

  1. The Unix Shell: A great tutorial for beginners from Software Carpentry.
  2. Linux Command Line Basics: A free course from Udacity that covers the basics of the Linux command line.
  3. Advanced Bash-Scripting Guide: For those interested in scripting, this guide is a comprehensive resource.
  4. Explain Shell: A handy tool that explains what each part of a Unix command does.
  5. ManKier: Another great tool for understanding Unix commands. It provides explanations for commands and their options.

Top comments (0)