So... Linux?
Tags: beginners, linux, webdev, computerscience
Published: 2020-04-13 05:53:03

## Introduction

Did you know Linux is the most popular operating system in the world? It is! For servers and supercomputers. The millions of server computers hosting the websites we visit are more than likely running a version of Linux. In this post, we'll learn what Linux is and where it comes from, vocabulary, and commands you need to start navigating this exciting platform.

## What is Linux?

Linux is an operating system, just like Windows or Apple's mac OS. Operating systems are collection of software that manage the different devices and applications in your computer. These bits of software take care of processes like shutting down your computer, booting it up, and giving your programs an interface to interact with devices like your keyboard and mouse.

Learning to use a Linux system is a great opportunity to get familiar with the **command line**, the most explicit way to communicate with your machine. Additionally, as you experiment with different projects, you will start to learn about repositories, package management, file permissions, user management, and much more. Package management and repositories are concepts you might already be familiar with if you have any experience using npm and GitHub.

## Why is Linux so Popular?

Linux distinguishes itself in the world of enterprise computing, big data, and science (think supercomputers!). Why?

- **Linux is free**. Free in multiple ways, you don't need to pay to use Linux and you're free to view, edit, and distribute the source code. When you buy a computer with Windows or macOS, the cost of creating and maintaining these operating systems is included in the price.
- **Linux is flexible**. Linux is used in a lot of different types of computers. Think smart toasters and refrigerators, other IoT devices, internet routers, Android smartphones, the list goes on and on. You can probably install Linux on your laptop or desktop today and be up and running with little set up! More on this at the end. This flexibility is possible because a Linux operating system is designed to be the sum of many different tools that do one job and do it well. You could piece together a version of Linux that works for _your_ device and is optimized for _your_ needs.

## The Unix Philosophy

Linux is a 'Unix-like' operating system, meaning much of it is derived from the Unix operating system and generally follows Unix's design principles. An ideal Unix program is simple, modular, and extensible. Unix programs do a few tasks really well and are designed to work well with other programs without depending on too many others. The system is made strong by the collaboration of the programs that compose it, not because the programs themselves are super powerful.

My favorite thing about Linux is that **everything is a file** _somewhere_ in the system. Those commands and programs you run in the terminal? Files. The icons in your desktop that let you quickly open your favorite apps? Files. What about the repositories your system checks for application updates? Written in a file! All of which you can mess around with. The transparency! The power! Its beautiful. Imagine one day set up your own Linux installation with everything you want, and nothing that you don't, while having full autonomy over your system... Pretty cool, right?

These principles really speak to Linux's flexibility. No wonder it's used in for so many applications!

## Everything is a File, Here is Where They Live

I want to show you a typical system tree, or file system hierarchy in a Linux installation. Read more about tree-like data structures in my other [post](https://dev.to/emtes/learning-data-structures-trees-2p5g)! If you're following along in your own Linux system, note that you may have additional or fewer directories. If you want to learn more these directories (folders) in detail, run `man hier` in your Linux terminal and read away! Personally, I keep my search engine of choice nearby to look up the many words I don't know the meaning of.

`/` this is the root directory (folder), the root of the tree (yes, the data structure :smile:)

`/bin` contains binaries, executable programs the system needs to boot

`/boot` contains the kernel and files needed while the machine boots

`/dev` contains _device nodes_, instructions/interfaces to use with physical devices connected to machine

`/etc` contains system-wide configuration files (pronounced _etsy_). Big software packages like `gtk`, `python`, and `X11` store configuration files here as well.

`/home` contains directories for system users (each user's Downloads, Pictures, etc.)

`/lib` contains libraries shared by core programs necessary to boot the machine

`/lost+found` contains data misplaced during a system crash or as a result of drive errors

`/media` contains mount points for media devices like USBs, CDs, and DVDs.

`/mnt` is a mount point for a temporary file system (like the one you might use to build your installation)

`/opt` contains additional packages for programs. In my machine, Google Chrome and the Minecraft Launcher keep files here.

`/proc` contains files related to the kernel and running processes

`/tmp` contains temporary files that may be created while executing a program

`/usr` contains a secondary, read-only system tree for sharing with some programs or to be mounted on other Linux systems. Many of the directories above exist here containing additional files.

`/var` contains files that vary in size at different times like logs and backups

If you use Linux frequently, at one point or another you'll find that you need to edit or write files in some odd directory. I hope knowing what these names generally refer to can help you out!

## Command Line Basics

Earlier I said 'the most explicit way you can communicate with your Linux machine is the command line' and I meant it. Let's learn some basic command line or terminal commands that will allow you to start familiarizing yourself with your system. If you currently develop with a graphical user interface you may find that doing things from the terminal is faster and safer (ish).

There is a program between you and the terminal called the shell. A shell is a program that interprets text commands and sends them to your operating system to execute. The most common shell program is called **Bash**, which comes included in most Linux installations. For macOS users, Apple recently switched the shell program to _zsh_. macOS is actually a Unix-like operating system as well. You too can change your shell!

### The Structure of a Terminal Command

I won't share too many commands in this post, its long enough already and learning patterns is more important. Generally, terminal commands follow a very similar and predictable structure:

`program_name [--optional flags] [optional arguments]`

_Flags_ can come after arguments and are often shortened to just one letter and one dash, e.g. `-f`. Flags are options that change the way a program behaves. `-h` or `--help` are common flags that will tell a program you want to see which flags are available to you.

Arguments are often files but can be strings and numbers too.

You can call a program from any directory in your system and you can use a file from any directory in your system as an argument. You can do this because to name a file you can use a relative or absolute path. **Relative paths** are relative to your current directory, which you can refer to with `.`. **Absolute paths** start at the root of the system `/` and name every directory to get to the desired file.

### Navigation

- `pwd` prints the directory you're currently in (print working directory)

- `cd` changes the directory to your specified argument. If you provide no arguments it will by default take you to your user's directory, which you can refer to in paths with `~`. `.` and `..` represent your current and parent directories respectively and are also valid arguments.

- `ls` lists the files in the directory you specify as an argument, which by default is `.`. The `-a` flag comes in handy for seeing hidden files. You can hide files by starting their name with a `.`, e.g. `.gitignore` to reduce clutter.

```Bash
ls -a ~/Documents
```

### File Manipulation

- `mv` moves a file or directory to your specified directory.

```Bash
mv fun-letter.text ~/Documents/letters/
```

You can also use `mv` to rename files and directories:

```Bash
mv fun-letter.txt hilarious-letter.txt
```

Like moving it to itself with a new name!

- `cp` makes a copy of a file in a specified directory. Use the `-r` flag to copy directories, and you can rename files and directories with `cp` similarly to how we did it with `mv`.

- `mkdir` makes new directories where the names are your arguments. You can also make directories inside directories that don't exist yet with the `-p` flag.

```Bash
mkdir -p code/web-stuff/html notes
```

- `touch` makes new files where the names are your arguments.

You will soon find yourself wanting to do more complicated things, so read more on these commands and keep a cheat-sheet :wink:.

## Linux for Everyday Use

I won't say 2020 is going to be the year for Linux in the desktop, but I will share that there are many Linux distributions ready to go out of the box and with simple installation methods. If you are attracted to the power of the shell, are concerned about privacy using other operating systems, or you just like hacking around, Linux might be for you. As a developer this is also a great platform because its made with other developers in mind. Distributions, versions of Linux like Ubuntu, Linux Mint, and Fedora can get you up and running quickly. These 'distros' are accompanied by huge communities full of people willing to help. Just remember to back up any important files!

Thanks for reading! I appreciate any comments and feedback :)

Cover photo by [Pixabay](https://www.pexels.com/@pixabay?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels) from [Pexels](https://www.pexels.com/photo/animal-beaks-bird-cold-209096/?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels)