Free UI/UX design course
Learn how to create exceptional designs by reading my new tutorial.
Start learningTerminal basics
Terminal, also known as the command line, is the "old" way to interact with computers. Before the graphical interfaces we know from Windows, MacOS or Linux were created, the terminal was basically the only way of communication between man and machine.
However, despite the passage of years and inventions such as the computer mouse and the huge progress that has been made in graphical interfaces, in many cases the terminal remains the fastest and most effective way of working with a computer. Even today, many systems, especially those related to servers, do not have a graphical interface at all and are operated entirely through the terminal.
That is why experienced developers cannot imagine working without a terminal. So in this lesson we will learn the basics of using the terminal.
In previous tutorials, we've already used terminal to publish our projects to the web using MDB GO. Now let's get acquainted with the command line a bit better to work even more efficiently in the future.
Launch the terminal
Windows:
Click start or press button. Then type cmd and open Command Line.
MacOS:
Click the Launchpad icon in the Dock, type Terminal in the search field, then click Terminal.
Linux:
Pressing Ctrl+Alt+T will instantly launch a Terminal window at any moment.
Change directory
Command: cd
This command will change the directory that you’re currently working in.
cd desktop/my-projects/mdb-tutorial/
Go to a directory one level up
Command: cd ..
Type the command cd
and ..
(two dots) to move from the current folder to the folder one level up.
cd ..
Displays files and folders in current directory
Command: ls
Command (Windows 10): dir
This command will list all files and folders in the folder you are currently in
ls
<!-- or -->
dir
Autocomplete
Key: tab
Just enter the first letter of the name of the file or folder you are looking for and press tab
key, and the terminal will complete the rest of the name.
If you do not enter any character and instead click tab
, the terminal will substitute the names of subsequent files and folders in turn.
Move a file
Command: mv
Command (Windows 10): move
Type mv
or move
, then the name of the file you want to move and then type the path you want to move that file.
The command below will move the image.jpg
file from its current location to the new-folder/photos/
location:
mv image.jpg new-folder/photos/
<!-- or -->
move image.jpg new-folder/photos/
Rename a file
Command: mv
Command (Windows 10): move
To rename a file we use the same command as for moving files. However, instead of specifying a new location, we specify a new file name.
The command below will rename image.jpg
to new-image.jpg
:
mv image.jpg new-image.jpg
<!-- or -->
move image.jpg new-image.jpg
Create a directory
Command: mkdir
This command will create an empty directory named new-folder
:
mkdir new-folder
Create a file
Command: touch
Command (Windows 10): copy nul
Type touch
or copy nul
, then the name of the file with an extension to create a new file.
The command below will create document.txt
file:
touch document.txt
<!-- or -->
copy nul document.txt
Show current path
Command: pwd
Command (Windows 10): cd
This command will show you the path of the current location that is open in the terminal.
pwd
<!-- or -->
cd
Clear terminal
Command: clear
Command (Windows 10): cls
This command will clear the terminal of all previous commands.
clear
<!-- or -->
cls
Exit the terminal (only on Windows)
Command: exit
This command will close the terminal.
exit
How to open Visual Studio Code from the terminal
Finally, I'll show you one very useful trick.
If you use Visual Studio Code editor you will love it. And if you don't, what are you waiting for? Visual Studio Code is the best editor :)
Windows
In terminal just go to the path where you have your project you want to open and then type command code .
(word "code", space and one dot).
MacOS
Step 1:
Open Visual Studio Code
Step 2:
Press Command + Shift + P
. You should see the command palette:
Step 3:
Next, type shell
and hit enter. When you type shell, your editor should look like this:
And that's it! Now you can open any folder in Visual Studio Code directly form the terminal, simply by typing code .
(word "code" and one dot).
About author
Michal Szymanski
Co Founder at MDBootstrap / Listed in Forbes „30 under 30" / Open-source enthusiast / Dancer, nerd & book lover.
Author of hundreds of articles on programming, business, marketing and productivity. In the past, an educator working with troubled youth in orphanages and correctional facilities.