All Bash commands from "Learn Bash by building a Boilerplate" on freeCodeCamp

All Bash commands from "Learn Bash by building a Boilerplate" on freeCodeCamp

Hello!

If you are reading this article, it means that you have tried the new freeCodeCamp curriculum on Relational Database (beta version for now) and maybe at first you had some difficulties or couldn't get going. Or you just feel like learning something new.

This article covers the first course called "Learn Bash by Building a Boilerplate" to get certified in the Relational Database curriculum on freeCodeCamp.

What is the Bash shell?

Somewhat like the Windows File Explorer, the shell is a fundamental component of the operating system. The user (who has the proper permissions) can use this command interpreter to start programs, execute commands, and manage files.

In Linux, EVERYTHING is a file.

"This is 2022. Why are we using the terminal when we could be using an interface and mouse support?"

  1. Speed

  2. On server versions of Linux, you use the command line

  3. You can do things that seem "impossible" for a graphical interface

  4. Your friends will think you are a hacker

What is a Website Boilerplate?

It is a kind of template that we can use to create websites. It contains folders and files that make up an empty site in its raw state.

Foreword:

Since this is still a beta course, arm yourself with patience because you may run into some bugs right from the start. Nothing serious but I understand that a complete beginner might get discouraged if right from the start they get stuck. So I will try to guide you step by step and give you some tricks to make your life easier.

"The problem lies between the chair and the keyboard."

  • Old Saying

This course uses VSCode and an add-on called CodeAlly that allows you to follow tutorials directly in the VSCode interface.

If you are a novice, know that none of this needs to be installed.

The entire course runs on browsers and uses these technologies but you may run into two problems:

PROBLEM~#1:

"Help! When I opened the site for the first time CodeAlly is not showing the exercise."

SOLUTION: Relaunch the site.

Instead, the goal is to obtain the following result, where the exercise in the CodeAlly window is readable.


PROBLEM~#2:

"I accidentally closed the CodeAlly window!"

SOLUTION: Relaunch only the CodeAlly extension using the Command Palette.

What it is?

"The Command Palette is where all Commands are found."

  • Visual Studio Code

Hamburger Menu -> View -> Command Palette

HINT: To access the Command Palette hold down CTRL + SHIFT + P.

In the Command Palette select "CodeRoad: Start."

Let's expand our workspace

We close the Getting Started window and click on the icon with the two files to collapse the Explorer panel. Now we have a lot more space available.

Do you want even more?

Then press F11 on your keyboard to put the browser in Full-Screen mode.

Let's cut the small talk and get started!

Start the Terminal

Hamburger Menu -> Terminal -> New Terminal

You have other ways to open a new terminal:

  • CTRL + SHIFT + ù

  • Remember the Command Palette? You can also invoke it to show the terminal (doing so doesn't open a new one)

The commands that you will encounter

During this course, you will encounter many commands with some "modifiers" or flags.

Here they are in order of appearance:

ECHO to "Write to the Terminal"

The first command you learn is ALWAYS the one that allows the user to make a prompt appear. The classic "Hello World!" On the terminal just type "echo" followed by the words we want to show. It sounds like something trivial but it allows another person to understand how to interact with our program and scripts.

echo Hello World!

PWD to "Show which folder we are in"

As in any other file manager, it is necessary to know where we are. It would be inconvenient to create a folder or file without knowing what the active directory is.

pwd

LS to "Show files and folders in the active directory"

Later you will find that folders have bold names, images are pink, and that you can type "ls -l" using the -l flag to show the contents of the folder in a long list format that provides details such as permissions, file owner, and creation date.

ls -l

To see hidden files and folders use the -a flag

ls -a

If you want to see more flags type

ls --help

CD to "Change Directories"

Change the active directory, that is, move between folders in your operating system. To do this:

cd <directory name>

Later you will find that you can go back to the 'parent' folder by typing "cd .." and that you can go back twice with "cd ../.." and three times with "cd ../../.."

HINT: To complete this exercise instead of typing "cd freeCodeCamp" you can simply type "cd f" and press TAB to use shell auto-completion, followed by the ENTER key to validate the command.

You will use TAB many, many times.

Speed Tip

Do not click Continue every time you complete an exercise, but press CTRL + ENTER

The focus will remain on the terminal and you will never take your hands off the keyboard.

MORE to "Show the Contents of a File"

more <filename>

Where <filename> is the name of the file that you want to show. Press ENTER if the file text is longer than the height of your window. Doing so will take you down one line each time you press ENTER.

HINT: Press the letter "q" to quit, if the text is too long and you want to return to the command prompt.

CLEAR to "Clean the Screen"

Simply type "clear" and press ENTER.

clear

Speed Tip

Want to repeat the last command you wrote? Use the UP ARROW to walk through the history of your commands.

MKDIR to "Create a Directory"

Type "mkdir <directory name>" to create an empty folder in the active directory.

Later you will find that you can create a folder without being in the active directory by typing

mkdir <active directory>/<new directory name>

for example:

mkdir client/src

TOUCH to "Create a file"

Type "touch <filename>" to create an empty file in the active directory.

CP to "Copy a file or folder"

Type "cp <file><destination>" to copy an existing file to a specific folder.

The first time you encounter this command it will ask you to copy an image into a folder, and to do so you must type

cp background.jpg ./images/

Always remember that TAB is your best friend.

cp b TAB ./im TAB

Toward the end of the course, you will learn that with the -r flag you can copy a folder with all its contents, for example

cp -r website-boilerplate/ toms-website

RM to "Delete a file"

Type "rm <filename>" to remove an existing file.

CAUTION there is no recycling bin. The file is simply gone. Volatilized. Irrecoverable.

In any case with the --help flag, we can see all the flags available for this command. One very dangerous thing you can do is to use the -r flag, which stands for recursively, to delete a folder and all its contents. For example,

rm -r fonts

I hope I was clear when I said earlier that there is no trash can.

MV to "Move or Rename a File"

Type "mv <filename> <new filename>" to rename a file.

Later you will find that you can move files with:

"mv <file to move> <destination folder>" for example

mv index.html ./client/src/

Or better:

mv in TAB ./c TAB TAB

FIND to "Find files, folders or see file tree"

Type "find" followed by the ENTER key to show the file tree.

The advantage over "ls -l" (the Long List format) is that this way you see both the contents of the active directory and the contents of all the folders that the active directory contains.

Later you will find that with "find <target directory>" you can see the contents of a specific directory. You will also find that if you need help you can use the --help flag. This command will show you various flags for example with the -name flag you can perform a name search to look for a file in a folder and its subfolders.

RMDIR for "Delete an empty directory"

As above. Nothing incredible.

Use >> to "Redirect Standard Output"

At some point in the course you will be told to print text to a file instead of to the terminal and type:

echo I made this boilerplate >> README.md

This allows the Standard Output to be redirected from the terminal (the default option) to a specific file. Text is added to the file, that is, the line is added to the end of the file content.

Speed Tip

CTRL + RIGHT/LEFT ARROW

Move the cursor sideways over a word instead of letter by letter.

EXIT to "Close the terminal."

Type "exit" and the terminal will close.

Conclusion

I hope I have been helpful and that this article has sparked your interest in trying this course. We have learned the basic commands but there are many others such as "ps" and "top" to see active processes, "bg" and "fg" to put a process in the background and retrieve it, etc..

This is my first article on medium for Step #4: Publish 3 tutorials on your Hashnode blog for the 2022 Become-a-Dev New Year's Resolution Challenge