My Journey with Bash Commands: The Essential Commands Every Developer Should Know

My Journey with Bash Commands: The Essential Commands Every Developer Should Know

Hi there, coding world! 😎

Today, I’m going to share my experience with some of the most fundamental and powerful bash commands that I’ve found incredibly useful. And trust me, once you get the hang of them, it will become your best friends. I’ll also walk you through how to use these commands on Windows, by setting up WSL (Windows Subsystem for Linux).

So buckle up, we’re about to go on an adventure into the world of bash commands!

See terminal is just nothing but another interface to do things on your machine.

Prerequisites: Setting Up Your Environment

Before diving into the bash commands, you’ll need to have the right tools in place, depending on the system you’re using.

1. For Linux or macOS:

If you're on a Linux or macOS system, you're already good to go! Both of these operating systems have bash available out of the box, and you can start using the terminal right away.

2. For Windows:

If you're on Windows, you’ll need to install either WSL (Windows Subsystem for Linux) or Git Bash. Here's how to do it:

Option 1: Install WSL (Windows Subsystem for Linux)

WSL allows you to run a Linux environment directly on Windows, without the need for a virtual machine. It's like bringing the power of Linux to your Windows machine.

Steps to Install WSL:

  1. Open PowerShell as Administrator
    Click on the Start menu, type "PowerShell", right-click, and select "Run as Administrator."

  2. Enable WSL
    In PowerShell, type the following command to enable WSL:

     wsl --install
    

    This command will enable the WSL feature on your Windows machine, allowing you to install a Linux distribution.

  3. Restart Your Computer
    Once the installation is complete, restart your computer to finalize the setup.

  4. Choose a Linux Distribution
    Open the Microsoft Store, search for your preferred Linux distribution (I recommend Ubuntu for beginners), and install it.

  5. Set Up Your Linux Distro
    After installation, open your Linux distro from the Start menu. You’ll be prompted to create a user account and set a password. Then you’re all set!

Option 2: Install Git Bash

Git Bash is another fantastic option for using bash commands on Windows. It’s a lightweight application that allows you to use the bash terminal, even if you’re not using WSL.

Steps to Install Git Bash:

  1. Download and install Git for Windows from the official website:
    https://git-scm.com/

  2. During installation, make sure to select Git Bash as your default terminal.

  3. After installation, open Git Bash from the Start menu, and you’re ready to start using bash commands!

3. Curiosity and willingness to learn and experiment.

Here We Go! :)

How to Use Bash Commands on Windows (Installing WSL)

Now, let’s get into the nitty-gritty.

We’re all familiar with Windows, but if you want to use these cool bash commands on your system, you’ll need WSL (Windows Subsystem for Linux). Don’t worry, it’s easier than it sounds.

Steps to Install WSL:

  1. Open PowerShell as Administrator
    Click on the Start menu, type "PowerShell", right-click, and select "Run as Administrator."

  2. Enable WSL
    In PowerShell, type the following command to enable WSL:

     wsl --install
    

    This command will install the WSL feature, which is like giving your Windows computer a Linux brain!

  3. Restart Your Computer
    Once the installation is complete, restart your computer to let everything settle in.

  4. Choose a Linux Distribution
    After restarting, open the Microsoft Store, search for your favorite Linux distribution (Ubuntu is my personal favorite!), and install it.

  5. Set Up Your Linux Distro
    After installation, open your new Linux distro from the Start menu. You’ll be asked to create a user account and set a password. It’s like setting up a new phone, but without the annoying setup screens!

The Classic Bash Commands You Must Know:

1. pwd (Print Working Directory)

Imagine you’re in the middle of a forest, but you're not sure where you are. You’d probably pull out a map, right? Well, pwd is like your map when you’re in the terminal. It prints the current directory you're in. You’ll use it to know exactly where you are while navigating the filesystem.

How to use:

pwd

When you run the pwd command, you’ll see something like /d/sam as the output, which tells you exactly where you are in the file system.

It’ll give you a full path of your current directory. Easy peasy!

2. cd (Change Directory)

cd is your trusty GPS for navigating through your terminal world. You can use it to jump from one folder to another. For example, if you’re in the Documents folder and want to go to Projects, you just type:

How to use:

cd <directory name>

To go up one directory, you can type:

cd ..

It's like jumping through portals, but with a bit of typing!

3. ls (List)

Imagine opening a box, and you want to see what's inside. ls is like your peek inside the box, showing you all the files and folders in your current directory.

How to use:

ls

Want to see more details? Add the -l option:

ls -l

4. mkdir (Make Directory)

mkdir is like having a magical button that creates a new folder for you. You can create as many as you want, just by typing this command.

How to use:

mkdir NewFolder

You’ll find a shiny new folder in your directory, ready for all your files!

5. touch (Create a File)

Need a new file?

touch is like the create button for your terminal. It instantly creates a new file, and you can start typing away in it. No more manually creating files through a GUI (graphic interface)!

How to use:

touch newfile.txt

Voila, you have an empty file named newfile.txt in your directory.

6. cat (Concatenate)

Now that you've created a file, you might want to check what's inside it. cat (concatenate) shows the contents of your file, as simple as that!

How to use:

cat newfile.txt

If you’re feeling fancy and want to combine two files, you can use cat to merge them together.

7. vi (Text Editor)

Now, vi is where things get a little more exciting. It’s like opening up a text editor in the terminal itself. It can be a bit confusing at first, but once you master it, you’ll wonder how you ever lived without it.

How to use:

vi newfile.txt

When you're inside vi, you’re in one of two modes:

  1. Insert Mode (where you can type text)

  2. Command Mode (where you can give commands).

    To switch between the two, just hit Esc (for Command Mode) and i (for Insert Mode). Don’t forget to save your work and quit with:

  • :w (save)

  • :q (quit)

Or if you want to do both:

  • :wq (save and quit)

8. mv (Move)

The mv command can be your magic wand when you need to move or rename files and directories. It’s like dragging and dropping, but all you need is your terminal.

How to use:

mv oldfile.txt newfile.txt

This will rename oldfile.txt to newfile.txt. You can also use mv to move files between directories.

9. cp (Copy)

cp is your best friend when you want to copy files. It’s like creating a clone of your files without touching the original.

How to use:

cp originalfile.txt copyfile.txt

Boom, you now have two files.

10. nvm (Node Version Manager)

For all the JavaScript lovers out there (yes, I’m one of you!), nvm is a lifesaver. It helps you manage multiple versions of Node.js without getting your hands dirty. You can switch between versions easily.

How to use:

nvm install node
nvm use node

It’s like upgrading your JavaScript skills with every version switch!

11. node (Run Node.js)

If you have Node.js installed, the node command lets you run your JavaScript files from the terminal.

How to use:

node app.js

This will run your Node.js application. Time to see your code come to life!

12. npm (Node Package Manager)

Let’s not forget about npm! It’s the reason why the JavaScript world runs smoothly. npm allows you to install packages, update dependencies, and manage your project like a pro.

How to use:

npm install express

This will install the Express package, and you’re ready to build your next web application.

13. rm (Remove)

Last but not least, rm is your go-to command when you need to delete a file. Be careful, though, because once you use rm, there’s no going back. It’s like a secret ninja delete button.

How to use:

rm oldfile.txt

No confirmation, no mercy. Just like that, your file is gone!

Wrapping Up!

And there you go! You’ve now got a bunch of powerful bash commands under your belt. With a bit of practice, you’ll be a terminal ninja in no time. Whether you're using them to navigate your system, create files, or manage your Node.js apps, these commands will make you feel like a true coding wizard. 🧙‍♂️

Remember, the terminal might seem intimidating at first, but once you start using it, you’ll realize just how much power is at your fingertips. So go ahead, open that terminal, and start exploring the vast world of bash commands! 🌍

And if you ever forget how to use a command, just remember: Google, chatgpt (and Stack Overflow) are always there to lend a helping hand.

Happy coding! 🙌

Connect with me on Twitter, LinkedIn and GitHub for updates and more discussions