Knowing how to use a terminal is a good skill to have as a developer. You can use to run various tools or running git commands.

It can be intimidating at first, especially if you are a beginner. But once you understand the principles behind it, it is not so complicated.

The terminal commands listed below are the founding stones for your further work. They are easy to understand and remember.

  1. pwd
  2. ls
  3. cd
  4. mkdir
  5. rmdir
  6. rm
  7. !!
  8. clear
  9. sudo
  10. Tips

1. pwd

pwd - stands for print working directory. Running this command will output the path to the directory your currently in.

TP-MAC:~ tippingpointdev$ pwd
/Users/tippingpointdev

2. ls

ls - stands for list. This command will output a list of all directories and files inside the current directory.

TP-MAC:~ tippingpointdev$ ls
Applications			Movies
Desktop				Music
Documents			Pictures
Downloads			Public
Library             
              

3. cd

cd - stands for change directory. This command is used to change directory and move around your system.

TP-MAC:~ tippingpointdev$ cd Documents/Sites
TP-MAC:Sites tippingpointdev$ pwd
/Users/tippingpointdev/Documents/Sites

Some additional change directory commands are quite useful.

  • To go to the parent directory use: cd ..
  • To go to the root directory from any location use: cd /
  • To go to the home directory from any location use: cd ~

4. mkdir

mkdir - stands for make directory. This command is used to create a directory.

TP-MAC:~ tippingpointdev$ mkdir helloWorld
TP-MAC:~ tippingpointdev$ ls
Applications			Movies
Desktop				Music
Documents			Pictures
Downloads			Public
Library				helloWorld

5. rmdir

rmdir - stands for remove directory. This command is used to remove a directory.

TP-MAC:~ tippingpointdev$ rmdir helloWorld
TP-MAC:~ tippingpointdev$ ls
Applications			Movies
Desktop				Music
Documents			Pictures
Downloads			Public
Library

6. rm

rm - stands for remove. This command is used to remove the specified directory or file.

TP-MAC:~ tippingpointdev$ rm index.php

7. !!

!! - execute the last command typed.

TP-MAC:~ tippingpointdev$ ls
Applications			Movies
Desktop				Music
Documents			Pictures
Downloads			Public
Library
TP-MAC:~ tippingpointdev$ !!
Applications			Movies
Desktop				Music
Documents			Pictures
Downloads			Public
Library

8. clear

clear - will clear the terminal screen of all the text.

TP-MAC:~ tippingpointdev$ clear

9. sudo

sudo - stands for super user do. This command will execute any command with the security privileges of the super user. The example below will execute the last typed command with the security privileges of the super user.

TP-MAC:~ tippingpointdev$ sudo !!

Tips

Below are some useful key combinations that will help you be more productive and handle terminal with ease.

  • fn + shift(⇧) +  - Jump to the start of the line
  • fn + shift(⇧) +  - Jump to the end of the line
  • alt(⌥) +  - Jump to the previous word
  • alt(⌥) +  - Jump to the next word
  • ctrl(⌃) + u - Remove all text in the current line
  • Double-clicking on the Tab button acts as an autocomplete and will offer you suggestions. This is useful when typing in a path.

Additional resources

There are a lot more than these basic terminal commands. You can learn a lot more and become very productive and efficient if you know more commands. Below just a few useful resources for you to extend your knowledge:

Tags: