[Linux] I learned LPIC lv1 in 10 days and tried to understand the mechanism of Linux.

Preface, notes

――For some reason, I learned LPIC 101 102 in a short-term intensive manner. ――I am learning with a feeling of grasping the concept, deepening my understanding of Linux rather than passing the exam. There are many parts where the command is not memorized (Ping-t remembered the range of 101 quite a bit, but Ping-t is interesting)

――This article summarizes my own interpretation of how Linux works at the moment (2020/12/21). To be honest, what is an OS rather than Linux? There are many stories like this.

――In order to deepen my understanding, I try to describe as much as possible even in a very rudimentary explanation. (If you don't like the explanation because it's too verbose, but it's okay!)

――There may be some misinterpretations, I'm sorry, I would appreciate it if you could let me know if there is anything.

Knowledge before my learning

--I often hit Linux commands when developing with Rails in a mac OS environment, but I often don't understand the meaning, and I have been programming for about 7 months. ――I wanted to study computer science, and I was studying for the Basic Information Technology Engineer Examination about 10 days before I started LPIC study. --Basic information learning materials -Kitami-style Illustration IT School Basic Information Engineer Reiwa 2002 -~ Learn efficiently from the beginning ~ The fastest passing course for the Basic Information Technology Engineer Examination

LPIC learning materials

-Linux textbook LPIC Level 1 Speed ​​Master Problem Collection Version 5.0 compatible (commonly known as white book) -Ping-t's strongest WEB problem collection --Google search for timely terms

What is Linux?

Two meanings

In a narrow sense, it is a kernel, and in a broader sense, it is an OS.

OS is an abbreviation for operating system, which is like a computer brain in a nutshell. Without it, the computer won't work. The kernel is the core software of the OS.

** Strictly speaking, Linux refers only to this kernel. ** So why is the OS also called Linux? First, let me explain what the kernel is.

What is a kernel?

** The kernel is software that plays a very important role in the OS. ** But the computer can't do anything with just the kernel. (In the image, it feels like working alone with a person who can lead the team with 100 subordinates)

Therefore, you need excellent subordinates (software with computing functions) around you. The team (software group) that can run its subordinates as an OS to some extent is collectively called a Linux distribution or simply Linux, including the Linux kernel, ** In other words, this is Linux in a broad sense. ** **

The Japanese translation of the distribution is distributed as a unit for each OS in the sense of distribution and distribution.

Linux distribution

There are many Linux distributions. Some are distributed free of charge, while others are paid.

Typical distribution

There are still more, but I will omit them.

What and how does the Linux OS run your computer?

First of all, from the role of the OS

Role of OS

--Start your computer --Various operations --Character input / output --Installation of various software --Manipulate software, middleware, and applications --Connecting external devices --Internet communication --Ensuring communication security

Etc., ** Everything that a computer can do involves the OS. ** **

How do you play that role? First, I will explain what a computer can do.

Computers in the first place

In the end, it interprets, processes, and outputs things digitally by combining a huge number of ** 0 or 1 or switch combinations **.

What do you mean?

The letters and colors you are looking at are assigned 01, that is, numbers in binary, and the computer interprets the letters and colors by looking at them. If you look closely, a color code, for example #FFFFFF, is a code that means white (color code is in hexadecimal notation, but hexadecimal is easy to convert to binary, it's just a very long expression. .) Hexagon FFFFFF = Binary 111111111111111111111111 It seems that words and commands expressed only in binary numbers of 01 are called machine language.

Computers can't understand English or Japanese, they can only understand machine language, so you need to give instructions in machine language to get something done.

However, there is no one who keeps typing numbers like 01011100000 ... to operate the computer.

So, after all, what do you mean by making various things normally?

--Interpreters and compilers that translate programming languages ​​written in human-friendly language into machine language --CUI shell that spawns a process using the corresponding file by command and processes it --System calls, applications, packages ...

And so on, ** Various tools, packages, applications, etc. act as an intermediary between the OS and the computer **, so the computer can run.

Thanks to the Linux kernel and my funny friends doing this kind of thing, various processes have been realized.

The important thing here is the idea of ​​files.

What is a file (file system, FHS, partition)?

File

As you all know, there are various file formats such as text files and image files.

Some files are directly expressed in machine language and some can be converted to machine language representation.

And the ** interpreters, compilers, and applications mentioned above all work using the settings and algorithms (calculation procedures) described in the corresponding files. ** **

In other words, Linux runs a computer by combining files with various instructions and files with information. ** At the extreme, software and system calls are all files. ** **

But files are abstract, how do you understand and save them on a computer that can only do 01?

File system

The file system determines the format in which files are managed in a storage area such as an HDD (hard disk drive).

In other words, ** If you arrange the files from the computer, it's just a list of numbers such as 0101000… .. **, so if you don't decide how to separate the files, what is the file from where to where? I can't recognize that, so it's like ** let's decide how to separate it firmly **.

Various methods have been developed for the file system, and it seems that Linux has XFS, ext4, etc.

Thanks to this file system, computers can understand the existence of abstract files.

partition

By setting the file system, you can now save files to a storage area such as an HDD! !! It does not mean that ... ** Actually, before setting up the file system, you need to divide the storage area into large groups. ** That is a partition.

A partition is like dividing a huge house called HDD into several rooms, giving each room a role (kitchen, living room) and putting the necessary files (furniture, table) in it. is not it.

By the way, setting the file system on the partition is called ** mount **.

FHS

In Linux, important files (files, tools, etc. required to start a computer) are decided to some extent in which directory to put which file, ** This is called FHS (File System Hierarchy Standard). ** **

For example, the log is saved in/var/log, and the configuration file is saved in/etc. It is decided to make it easy to understand by naming. After studying Rails, I felt something similar to RESTfull, which is often said (although it may be different).

By deciding this, compatibility with different distributions and a directory structure that is easy for users to understand are realized.

** The kernel uses these well-managed files (software) to achieve human instructions! ** **

So how do humans give instructions to the kernel? , It will be realized in the next section.

About shell UI (user interface)

What is a shell

As the name implies, the shell is the "shell", which is the shell of the kernel. I imagined a Pokemon shellder. The face inside is the kernel.

Like this, the shell wraps around the kernel 9BF6FFDE-D9D7-4AE1-8608-DC0D68E6C68F_1_102_a.jpeg

** The shell provides omnidirectional mediation between humans and the kernel. ** The reason why we bother to mediate is that the kernel is very important, and it is difficult to handle it poorly and break it, so the kernel and humans communicate with each other using a cushion called a shell.

The shell has a CUI and GUI

CUI and GUI

I think many people know this,

--CUI is an abbreviation for character user interface. Character means character ** As the name implies, it is a character that the user and the computer interact with (user interface). ** ** For example, in the CUI shell called bash, users enter commands in the command prompt (terminal on Mac) to communicate with the kernel.

――The GUI is the one that operates graphically using the familiar mouse pointer.

Command (bash)

When a command is typed into the command prompt and executed, the shell formats the command and passes it to the kernel as a system call to spawn a "process", and then returns the processing result to the command prompt again. Humans and the kernel communicate in this way.

For example, execute the ls command (command to display the subdirectory name and file name under the directory) as shown below.

$ ls
fileA fileB

The process looks like this (the characters are ridiculously dirty ...) C3A4B9F7-B0AA-4222-99E5-0D678A93C08A_1_102_a.jpeg

There is a command executable file (shell script) in the image. A shell script is a file that describes the processing of commands, ** yes, everything is a file. (Maybe)** So ** shell and shell script are similar terms, but they have completely different meanings, so be careful. ** **

The ls command also has a shell script, and when the command is executed, it will search for the corresponding shell script by referring to the path in the environment variable $ PATH.

You can use which command to find the location of the shell script for the command specified by the argument (the one that attaches to the command).

$ which ls
/bin/ls

Environment variables Shell variables

A variable is a box that holds values ​​in a programming language, and it often comes up when you study programming.

--Environment variables can be used throughout the computer.

--Shell variables can only be used by that process. (Cannot be used in child processes)

A process is a process executed by the shell or kernel. In fact, the shell itself is also a process. Yes, ** everything is a process. (Maybe)** ** Executing a command means spawning a child process from a parent process called the shell. ** **

It's a little confusing, but ** environment variables are like computer settings. ** It may be a little different.

The environment variable $ PATH is a variable that contains the place to look for commands!

Packages, libraries

A package is a collection of various programs and files required for a certain operation. Libraries are similar, programs and files. ** Yes, everything is a file. (I just want to say) ** There are also packages for package management (installed and updated externally).

For example, the APT tool can install packages in an "official repository" that has all the packages officially supported by Linux distributions.

When you want to install hogehoge

$ apt-get install hogehoge

I use it like this.

Summary

I wrote it for a long time, but in other words, how Linux works

** The kernel receives the instructions that mediate the shell, and the kernel leverages applications, software, files named shell scripts, etc., and returns the results. ** **

Roughly this is how it works! If you somehow grasp this concept, it will be easier to understand whether you are programming or studying for the LPIC exam. I think.

I hope it helps someone even a little. Thank you for reading to the end m (_ _) m

Recommended Posts

[Linux] I learned LPIC lv1 in 10 days and tried to understand the mechanism of Linux.
I tried to illustrate the time and time in C language
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
[Linux] I tried to summarize the command of resource confirmation system
I tried fitting the exponential function and logistics function to the number of COVID-19 positive patients in Tokyo
I tried to visualize the age group and rate distribution of Atcoder
I tried to extract and illustrate the stage of the story using COTOHA
I tried to verify and analyze the acceleration of Python by Cython
[Linux] I tried to verify the secure confirmation method of FQDN (CentOS7)
I tried to display the altitude value of DTM in a graph
I implemented the VGG16 model in Keras and tried to identify CIFAR10
I tried to touch the API of ebay
I tried to correct the keystone of the image
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I tried hard to understand Spectral Normalization and singular value decomposition, which contribute to the stability of GAN.
I tried to notify the update of "Hamelin" using "Beautiful Soup" and "IFTTT"
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
[Azure] I tried to create a Linux virtual machine in Azure of Microsoft Learn
I didn't understand the Resize of TensorFlow so I tried to summarize it visually.
I tried to graph the packages installed in Python
I tried to summarize the basic form of GPLVM
I tried adding system calls and scheduler to Linux
I want to fully understand the basics of Bokeh
I tried to visualize the spacha information of VTuber
I tried to erase the negative part of Meros
I tried to classify the voices of voice actors
I tried to summarize the string operations of Python
I tried to notify the update of "Become a novelist" using "IFTTT" and "Become a novelist API"
I tried to understand how to use Pandas and multicollinearity based on the Affairs dataset.
I tried to automate the article update of Livedoor blog with Python and selenium.
I tried to extract the text in the image file using Tesseract of the OCR engine
I tried to put HULFT IoT (Agent) in the gateway Rooster of Sun Electronics
[First data science ⑥] I tried to visualize the market price of restaurants in Tokyo
I tried to compare the processing speed with dplyr of R and pandas of Python
I tried to reintroduce Linux
I tried to find the entropy of the image with python
[Horse Racing] I tried to quantify the strength of racehorses
I tried to get the location information of Odakyu Bus
I tried the accuracy of three Stirling's approximations in python
I tried to find the average of the sequence with TensorFlow
I tried to summarize the code often used in Pandas
I tried programming the chi-square test in Python and Java.
I tried to display the time and today's weather w
[Python] I tried to visualize the follow relationship of Twitter
I wrote it in Go to understand the SOLID principle
I tried to summarize the commands often used in business
I tried to implement the mail sending function in Python
[Machine learning] I tried to summarize the theory of Adaboost
I want to know the features of Python and pip
I tried to enumerate the differences between java and python
I tried to fight the Local Minimum of Goldstein-Price Function
I displayed the chat of YouTube Live and tried playing
I tried to implement blackjack of card game in Python
Commands and files to check the version of CentOS Linux
I tried to automatically post to ChatWork at the time of deployment with fabric and ChatWork Api
I tried to rewrite the WEB server of the normal Linux programming 1st edition with C ++ 14
I tried to verify the yin and yang classification of Hololive members by machine learning
I tried to create a Python script to get the value of a cell in Microsoft Excel
I also tried to imitate the function monad and State monad with a generator in Python
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"