Skip to content

Instantly share code, notes, and snippets.

@woile
Created April 13, 2021 18:57
Show Gist options
  • Select an option

  • Save woile/116cdb316a5e0b36da6edf38ecd3bebe to your computer and use it in GitHub Desktop.

Select an option

Save woile/116cdb316a5e0b36da6edf38ecd3bebe to your computer and use it in GitHub Desktop.
Introduction to the terminal

The command line

Short OS introduction

2 types:

  • Windows: we don't care much about this
  • Unix: Mac, Linux, BSD (same family, kind of unix, some are not fully compliant)

Unix systems

All of them should have a command line or terminal.

What is the use of command line?

It's a way to interact with the OS, using text. You write commands. Most people are used to interact with the operating systems using a GUI. This means, they use windows, the mouse, clicking in different folders and navigating.

Why is it useful for developers?

  • Only way to interact with some programming language tools
  • Allows automation of tasks

How to open a command line

MAC: Go to launchpad and search Terminal Linux with Gnome: Press the super key and search Terminal

Folder structure

/ root of the operating system /bin/ binaries /etc/ configuration files /tmp/ temporary files

⬆️ are used by the Operating System

Each user usually has its own folder, when you log in, you get your information. You should develop and code in your user folder.

Linux: /home/<username>/ Mac: /Users/<username>/

Shortcut for both linux and mac: ~

A location identifying a folder or a file, in the folder structure, is called path.

E.g: /home/lara/Downloads/

File vs folder

A folder contains files or folders.

A file contains some content.

Mounting

Usually you can mount a partition anywhere you want. By partition, we mean a hard drive. By mounting, we mean, making it available in the folder structure in order to save files.

For example:

  • I have a new 250 GB SSD (internal or external)
  • Plug it in
  • By running a command, we can make it available, under the following path:
/mount/Lara-250ssd/

Command line and folder structure

The terminal is always "standing" in a folder. If you use the terminal, you are going to navigate through different folders. You can use TAB to auto-complete for you in the terminal. We separate between folders and directories using a slash /

Cheatsheet

Command Description
pwd your current location, the full path
ls lists files and folders in your current path
mkdir my_folder_name create a folder/directory. Tip: avoid using spaces for filenames
cd my_folder_name change directory
cd ~ or cd take you to the home directory
cd ~/my_folder_name Go to my_folder_name
cd .. Change directory to the parent directory
cd . A single dot means the current directory
touch index.html Create an empty file
cp index.html lara.html Copy existing file with a new name
mv ./lara.html ./about.html Moves and/or renames a given file or folder to a new location
rm about.html Remove a file
rm -rf ~/my_folder_name Remove a directory
cat index.html Show the content of a file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment