Learning the command line is fun and quite challenging at the same time. You have to memorize a lot of commands to be able to use it effectively.  But here are some of the most basic and most widely used commands that you should learn if you want to use a UNIX like operating system like linux or mac os.

1. ls

The ls command is used to list all of the files and folders on a certain directory.

Syntax:

ls <path>

Examples:

  • ls - Will print all the files in the current directory.
  • ls ~ - Will print all the files and folders in home directory.
  • ls ~/home/<your-user-folder>

2. cd

The cd command or the change directory command. This command will let you navigate from folder to folder within your system.

Syntax:

cd <destination path>

Examples:

  • cd or cd ~ - Will bring you to the home directory.
  • cd ../ - Will bring one step outside your present working directory. Say you are in ~/john, then this command will bring you to ~/. You can use trailing ../ to go outside of a directory multiple times. E.g. cd ../../.

3. mkdir

The make directory or mkdir is just "Create a new folder" command. It's that simple.

Syntax:

mkdir <folder name>

Examples:

  • mkdir not-porn - Will create a folder called not-porn.
  • mkdir ~/Documents/school-stuff/home-work/not-porn - You can also create a folder in a certain path. In this example, mkdir will create a not-porn folder in ~/Documents/school-stuff/home-work.

4. touch

The touch command is a quick way of creating an empty file.

Syntax:

touch <filename>

Examples:

  • touch my-body.html - This will create a my-body.html file in your present working directory.
  • touch ~/Documents/codes/my-body.html Same with mkdir, you can also specify the path or location of your file.

5. rm

If you can create of course could also remove files and files from your terminal. The rm command will help you do that.

Syntax:

rm <path|directory name|file name>

Examples:

  • rm memes-link-collection.txt - Will delete the file  
    memes-link-collection.txt.
  • rm ~/Documents/codes/my-body.html - Removes the file my-body.html from ~/Documents/codes folder.
  • rm -r folder-name - Deleting a folder is a little different from deleting a file. If you want to delete a folder you should pass the flag/argument -r which means  recursive. This is required to delete the folder and everything inside it.

Note:

Some folders or files are protected by strict permissions, because maybe those files and folders are system owned. To understand how UNIX permission works, you can check this article.

6. cp

The copy command.

Syntax:

cp <origin> <destination>

Examples:

  • cp carl-homework.txt john-homework.txt - You just copied Carl's homework as  john-homework.txt.
  • cp ~/Documents/cats/cat-1.jpg ~/Documents/cats-backup -  Here we create a copy of cats-1.jpg to   ~/Documents/cats-backup.
  • cp -r ~/Documents/cats ~/Documents/new-folder - Like the removing of folder above, you must also use the -r to copy a folder and everything inside it to a new location. This sample will copy the  cats folder from  ~/Documents to  ~/Documents/new-folder

7. mv

The move files/folder command. This will... move a file to a new destination.

Syntax:

mv <origin> <destination>

Examples:

  • mv ~/Documents/cats/dog.png ~/Documents/dogs - This will move the dog.png from the  ~/Documents/cats folder to where it belongs. The ~/Documents/dogs folder.
  • mv ~/Documents/llama ~/Documents/dogs - This will move the llama folder inside the dogs folder. (Where it belongs :D)

Note:

mv command can also be used to rename a folder.

Example:

  • mv ~/Documents/porn ~/Documents/homework - Here you just renamed porn to  homework. Nice.

8. clear

The `clear` will just clear the terminal.

Syntax:

clear

Example:

  • clear

See? It's cleared now.

Congrats! You can now use the basic terminal commands.