Skip to content

Introduction to Linux

According to data available today on the spread of operating systems, Linux is used globally by about 47% of the market. Knowing Linux is important for young developers (and others) for several reasons, as Linux plays a crucial role in the market today (most of the web server runs on Linux). Like we said, Linux powers the vast majority of web servers worldwide and is the backbone of most cloud services and data centers like AWS, GCP, Azure and the others. Therefore Linux community is one of the largest and most active in the tech world. As a developer you can benefit from the wealth of knowledge, tutorials, forums, and documentation available to learn and solve problems.

Some interesting facts about Linux from the same article :

  • Linux has over 27.8 million lines of code.
  • SpaceX has used Linux-supported systems to complete 65 missions so far.
  • About 90% of Hollywood special effects rely on Linux.
  • 85% of smartphones are Linux-powered. (To be precise, 85% of smartphones are Android-based, which originates from the Linux kernel.)
  • Linux stands behind the top 500 fastest supercomputers in the world.
  • As of 2017, about 90% of cloud infrastructure operates on Linux.
  • 96.3% of the top one million web servers are running Linux.

Do not undervalue the power of the community

Linux and open source is this huge, complex beast, but you don't need to know everything to get by. For most devs, mastering a handful of tricks from this list can get you pretty far. Think of it like this: a builder might have a zillion tools but ends up using their nail gun all the time. The tools and commands I'm talking about here are like your nail gun for Linux—they're a solid foundation that'll help you handle most of the stuff you'll run into on a daily basis.

Overview of Linux history

Linux began in 1991 as a personal project by Finnish student Linus Torvalds to create a new free operating system kernel. Because at this time if you had wanted a computer (with the graphical interface, video, audio gestion aka an Operation System) you had to pay a lisence like a Microsoft Windows OS (XP, 7, Vista...) or Apple, IBM... At this time open source was not synonym of quality or innovation like in our days, but moreit was more associated to some weird guy in this garage doing weird magic on computers that nobody would understund 😂

I think for our part it is not very important to know all of the history details, releases and key dates of the Linux project. If you want to know more about history of Linux or Open source softwares you can find a lot informations on youtube and internet and general.

By the way, the history of open-source projects is fascinating if you want more details take a look at this video here. Linux is certainly one of the most important open-source projects live today, here below from wikipedia the history of the Linux distribution by date. More details on Wikipedia

Yes there is a lot of distrib and they are ploted on a wonderfull tree on wikipedia here for your culture 🤓

File system organisation

The first thing to know in your Linux adventure here is how the file are organised, as it forms the backbone of how files and directories are structured and managed in Linux-based environments. Here are some few reasons why this knowledge is valuable:

  1. Knowing the structure of the Linux file system enables developers to navigate and manage files efficiently. This is essential for tasks like locating configuration files, scripts, logs, and application files, which may be spread across different directories.
  2. When deploying applications or services on Linux, understanding where to place files can impact both functionality and security. For example, knowing the difference between /etc for configuration files, /var for variable files like logs, and /opt for optional or third-party software, helps in structuring applications logically.
  3. The Linux file system includes detailed permission settings for files and directories. Understanding the hierarchy and permissions is crucial for securing applications and sensitive data to prevent unauthorized access and ensure that applications have the necessary permissions to run correctly.
  4. Many back-end systems, web servers, databases, and development tools run on Linux. Understanding the file system organization helps developers integrate these systems more effectively, configure services correctly, and troubleshoot issues by knowing where logs and configuration files are stored.
  5. Certain directories are intended for specific purposes, such as /tmp for temporary files or /mnt and /media for mounted devices and media. Placing files in the correct location can help optimize system performance and ensure that temporary files are handled appropriately.
  6. The Filesystem Hierarchy Standard (FHS) defines the directory structure and directory contents in Linux operating systems. Following these conventions makes software easier to package, distribute, and manage across different Linux distributions, enhancing compatibility and ease of use.
  7. For developers involved in scripting and automation, understanding the file system is essential. Scripts often need to create, search, modify, or delete files and directories. Knowing the standard locations for certain types of files can make scripts more robust and portable.
  8. Debugging issues often involve analyzing log files, which are typically located in /var/log. Understanding the file system helps developers quickly locate these files, understand log rotation schemes, and set up monitoring and alerting based on log file locations.
  9. Tools for configuration management and infrastructure as code, such as Ansible, Chef, or Puppet, require a good understanding of the file system to manage configurations effectively across different environments.

Basics things to know

When I first coded on Linux it was pretty basic—like stuff from engineering school, I could find my way around files, write and run some scripts, but that was about it... 😅 But when I started freelancing I've picked up a ton more (still a long way to go though of course lol). It turns out today I have my own physical servers for my deep learnings hobbies and I started it from scratch that is why I started to write some notes of my work and put it here.

Explore some Linux commands

I know the learning curve associated with switching to Linux (non graphical interface), especially distributions feels like a sahara desert hike and not a nice walk around the beach but you will see you will not regret it and feel like a ninja paladin in a few moment 🥷🏼

Getting Around the File System

Like we have said before, you gotta be comfy moving around Linux's file system. Say you pop open Terminator or another terminal multiplexer, you're gonna need to know where you're at (use pwd for that) and how to hop around (with cd). There's this neat trick with the tilde (~) for jumping to your home directory or using .. to go up a level. And don't forget about tab auto-complete to save yourself some typing (shift command). Creating files? touch is your friend. Need to copy or move stuff? cp and mv have got you covered. Made a boo-boo? rm will get rid of it. Just be super careful with rm -rf because it can be fast and bad, deleting files you do not want to delete and you can regret it faster 😂

cat, grep and pipe | ninja tricks

The cat command spits out file contents right to your screen, and it's super handy for a quick look-see. But the real magic happens when you pipe (|) its output into grep to search for something specific. This combo is like the Swiss Army knife for slicing and dicing output or digging through log files for that needle-in-a-haystack error message.

Imagine you're a system administrator/engineer who needs to check the server logs for any unauthorized SSH login attempts. The log file is located at /var/log/auth.log.

Using grep

To find specific entries related to SSH logins, you can use the grep command to filter out the relevant lines.

grep "sshd:" /var/log/auth.log
Piping trick with grep and cat

If you want to combine commands to both display the contents of the log file and filter it, you can use cat and grep with a pipe like this :

cat /var/log/auth.log | grep "Failed password"

This command simply displays all lines from the auth.log file that contain "Failed password", helping you quickly identify failed SSH login attempts.

Imagine now you have multiple text files (file1.txt, file2.txt, file3.txt) containing lists of users. You need to find all instances of a user named "John Doe" across these files. First, use cat to concatenate the contents of all files and then grep to search through them.

cat file1.txt file2.txt file3.txt | grep "John Doe"
This command searches for "John Doe" across all three files, displaying any lines where the name appears.

Last example you're analyzing a large CSV file (data.csv) that contains transaction data. You want to see how many transactions were completed successfully (indicated by the status SUCCESS).

You can use grep to filter successful transactions and wc (word count) command to count the lines like this :

cat data.csv | grep "SUCCESS" | wc -l
use grep to serach text patterns

If you're debugging an application and need to find all occurrences of the error message Database connection failed in your application's logs to understand when the errors occurred you will use this command :

grep "Database connection failed" /var/log/app/application.log

You want to find how many times a specific user, say "john_doe", has logged into the system this month by analyzing the /var/log/auth.log file.

cat /var/log/auth.log | grep "john_doe" | wc -l

Finding Stuff with find

Ever feel like you're on a treasure hunt in your own codebase? find is your map. It helps you sniff out files buried in a maze of directories without turning your hair gray.

Now you're working on a large web development project and need to locate all JavaScript files that have been modified in the last 7 days because you suspect one of these files contains a bug introduced in the last week.

find . -type f -name "*.js" -mtime -7

Where . indicates the current directory, -type f restricts the search only to files, -name "*.js" searches for files ending with .js and -mtime -7 finds only files modified in the last 7 days 🤓

Over time, your project directory has accumulated several empty files due to aborted scripts and temporary placeholders. You want to clean up your directory by removing these empty files to maintain a tidy workspace.

find /path/to/project -type f -empty -delete

We can also do search file according to their permissions like if you need to ensure that all directories in your web server's root have a permission setting of 755 / (drwxr-xr-x), which allows the owner to read, write, and execute, while others can only read and execute.

find /var/www/html -type d -exec chmod 755 {} \;

Who's in Charge here bro ? (File Permissions and Ownership)

Linux is all about who can do what with which file. ls -l will show you the lay of the land permission-wise. Sometimes, you'll bump into a "keep out" sign (a.k.a. our good old "Permission denied" error), which means you need to sweet-talk sudo or change who owns the file with chown and chmod.

You've deployed a new script, deploy.sh, on your server but forgot to make it executable by anyone. You need to change its permissions to ensure it can be executed.

chmod +x deploy.sh

Now let's talk about changing file ownership 🤓

After a team member leaves the company, you need to transfer ownership of their project files to a new team member without changing the group ownership.

chown new_user: /path/to/project/*
Tip

Your best friend command is the man (manual) command, before Google, StackOverflow or available internet connection it was all we had for documentation and write scripts 🤗

What's next

So what's next, now that we love Linux we have open our terminal and feel like coding ninja 🥷🏼 what do we have to learn more ?

  1. Command Line Proficiency

    Why? The command line is your bridge to efficiently interact with Linux. Mastering it allows you to navigate, manipulate files, and execute commands with speed and precision.

  2. Shell Scripting

    Why? Automating tasks through shell scripting saves time and reduces human error. Understanding shell scripting enhances your capability to create custom solutions and automate repetitive tasks.

  3. File System Hierarchy

    Why? Knowing the structure of the Linux file system (like what /etc, /var, /home, and others stand for) helps you understand where applications and their configurations reside, leading to better system management and troubleshooting.

  4. Networking and Security

    Why? Understanding networking commands (like ifconfig, ssh, netstat) and security concepts (such as firewalls, SSH keys) is crucial for developing secure applications and managing secure systems.

  5. Package Management

    Why? Whether you use apt, yum, dnf, packer, docker or another package manager, mastering package management helps you install, update, and maintain software packages, ensuring your systems are up to date and secure.

  6. Version Control Systems 🐱

    Why? Familiarity with version control, particularly Git, is essential for modern development workflows. It allows for collaboration, version tracking, and managing code changes over time.

  7. Text Processing Tools

    Why? Tools like grep, awk, sed, and others are powerful for manipulating and processing data. They are indispensable for searching through files, extracting data, and automating text manipulation tasks.

  8. System Monitoring and Performance Tuning

    Why? Knowing how to monitor system resources (using tools like top, htop, vmstat) and tune performance is vital for ensuring your applications run efficiently and reliably.

  9. Containers and Virtualization

    Why? Understanding technologies like Docker and Kubernetes is increasingly important. They allow for the isolation of environments, making applications more portable, scalable, and secure.

That's it for this article, hope you learn some new things 🥳