1
0
Fork 0
mirror of https://codeberg.org/Mo8it/How_To_Linux.git synced 2024-12-04 19:10:32 +00:00

Compare commits

...

3 commits

Author SHA1 Message Date
30f3459847 Add help 2022-08-22 03:33:59 +02:00
3ffe5d5df2 Add packages.md 2022-08-22 03:26:13 +02:00
6abbb589ac Complete basics 2022-08-22 03:25:58 +02:00
3 changed files with 140 additions and 5 deletions

View file

@ -5,6 +5,7 @@
- [Day 1](day_1/README.md)
- [Why learn Linux?](day_1/why_linux.md)
- [Terminal basics](day_1/terminal_basics.md)
- [Packages](day_1/packages.md)
- [Day 2](day_2/README.md)
- [Day 3](day_3/README.md)
- [Day 4](day_4/README.md)

74
src/day_1/packages.md Normal file
View file

@ -0,0 +1,74 @@
# Packages
So far, we did only use commands that are common in every Linux system.
Now, we want to start exploring additional commands that might not be preinstalled on your system.
Therefore, we need to learn how to install so called packages to get access to additional programs.
### Package managers
In Linux, you don't install programs by using a search engine to find a website, then visit the website and download an installer then run the installer and click "Next" 100 times without even reading what you are agreeing to.
This method is too insecure. You have to trust the website that you did visit. You have to hope that no malware is delivered while you are downloading the installer from the website. You can get the malware either from the website itself or through a man in the middle attack. Then the installer might do whatever it wants. You just click "Next" and suddenly your system shows you ads or your browser search machine is overwritten. Surprise! 🎉
In Linux, you (mainly) install software through the package manager that ships with your distribution. The software is then downloaded from a repository which is a collection of packages that is managed by the distribution. The distribution managers make sure that no malware is added to the repository. The package manager does also take care of verifying the downloaded package before installation. This is done using some cryptographic methods and prevents man in the middle attacks or installation of packages that were corrupted during the download process.
The package manager does also take care of installing any other packages that you did not specify but are required by the package that you want to install. These packages are called dependencies.
Since the book uses a Fedora system for demonstrations, the package manager that the book will use Fedora's package manager `dnf`.
If you are using another Linux distribution, you might need to replace the commands of `dnf` with `apt` for Debian based distributions for example.
It is important to understand the functionality of package managers. Then you can transfer this knowledge to other package managers if required. This applies to some other aspects in Linux too, since _the Linux operating system_ does not exist. There are distributions that bundle a set of software and differ in small ways.
To install a package, you need adminstrative priviliges. Therefore, we need some `sudo` powers. `sudo` will be explained in the next section.
Lets install our first package! To do so, enter `sudo dnf install cmatrix`. You will be asked for the password of your user. Type the password and then press `Enter`. For security reasons, you will not be able to see you password while entering it. So don't wonder why nothing happens while typing the password. Just type it and then press `Enter`.
The package manager might then need some time to sync some data, but then it will show you a summary of what it will do and ask you for confirmation. Type `y` for _yes_ and then press `Enter` for the installation to start.
After the installation is done, you can enter `cmatrix` now. Congratulations, you are now a hacker! 💻🤓
To exit the matrix, press `q`.
If you don't like the matrix and you want to remove it? You can uninstall packages using `sudo dnf uninstall PACKAGENAME`. In this case: `sudo dnf uninstall cmatrix`. You have to confirm again with `y`.
While installing or uninstalling packages, it is important to take a look at the summary before confirming the action with `y`. There is a reason why a confirmation is required. Sometimes, some packages depend on packages with older versions than the versions that exist on your machine. If you want to install those packages anyway, other packages that depend on the newer versions can break!
Just don't blindly press `y`. If the package manager gives you a warning before doing something, enter this warning in a search engine and read about what it means before continuing.
### Sudo
[![](https://imgs.xkcd.com/comics/sandwich.png)](https://xkcd.com/149/)
Lets try to install another package, this time without `sudo` at the beginning of the command.
```console
$ dnf install cowsay
Error: This command has to be run with superuser privileges (under the root user on most systems).
```
You can see that you get an error resulted by a lack of priviliges for running this command.
Any action that might modify the system needs adminstrative priviliges. Installing a package (system-wide) is one of these actions.
Sometimes, an action might not modify the system, but a user might be restricted through the permissions system to not be able to access a file for example. In this case, you would also need to use `sudo`.
Linux has a superuser, one user that exists on every Linux system and is able to do anything! This user is the `root` user. For security reasons (and also to not do something distructive by a mistake), this user is often locked. `sudo` allows you as a non root user to run your command as a `root` user.
You are not alway allowed to use `sudo`. If you don't own the machine you are using and just share it with others, then there is a high chance that only adminstrators of the machine have `sudo` access.
If you don't have access to `sudo` and try to use it, then you get an output like this:
[![](https://imgs.xkcd.com/comics/incident.png)](https://xkcd.com/838/)
> Warning ⚠ : Use `sudo` with great caution! Do not run a command from the internet that you don't understand! Especially if it needs to be run with `sudo`! RED FLAG! 🔴
>
> Look up a command before you run it.
>
> Even commands that you know like `rm` can destroy your system if you use them with `sudo` without knowing what they are doing.
>
> You might find a "meme" in the internet that tells you to run something like `sudo rm -rf /`. This command will delete EVERYTHING on your machine. It is like delete the `C` and all other drives at the same time on Windows.
>
> Linux assumes that you know what you are doing when you use `sudo`. With great power comes great responsibility!

View file

@ -2,7 +2,7 @@
The terminal, the console, the command line. All terms refer to the same thing. Get access to a Linux system and open a terminal.
Warning ⚠️: **Don't panic!**
Warning ⚠️ : **Don't panic!**
Many find the terminal frightening. This is the cryptic thing you see hackers in films using! You might ask yourself, what am I doing here? I don't want to break my system or launch a terminator! 😯
@ -39,7 +39,7 @@ To examine this, lets first create a new directory. Enter the command `mkdir emp
Is `empty_house` really empty? Lets verify that.
Enter the command `cd empty_house`. Again, you don't see an output. But maybe you did notice that a part of your prompt changed from `~` to `empty_house`. This indicates that you are in your new directory. `cd` stands for _change directory_. Knowing the meaning of the commands you use which are often abbreviations does help you to memorize them.
Enter the command `cd empty_house`. Again, you don't see an output. But maybe you did notice that a part of your prompt changed from `~` to `empty_house`. This indicates that you are in your new directory. `cd` stands for _change directory_.
Now enter the command `ls`. You should not be seeing anything because the directory is indeed empty.
@ -91,7 +91,7 @@ friend1.txt friend2.txt
The loud friend is removed! `rm` stand for _remove_.
> **Warning** ⚠️: `rm` deletes a file directly! The file is not moved to a trash! It is gone! You can not restore it anymore! Think more than one time before using `rm`.
> **Warning** ⚠️ : `rm` deletes a file directly! The file is not moved to a trash! It is gone! You can not restore it anymore! Think more than one time before using `rm`.
Does `rm` also work with directories? Lets test it:
@ -186,7 +186,7 @@ Y Yes
N No ^C Cancel
```
A buffer is a file that is being edited in the memory. If you click `N`, then your editions are lost! In our case, we want to save the rules. Therefore, we press `Y`.
A buffer is a file that is being edited in the memory. If you press `N`, then your editions are lost! In our case, we want to save the rules. Therefore, we press `Y`.
Now it shows us:
@ -304,6 +304,12 @@ You can learn more about how to navigate manuals (and other so called pagers) by
Fun fact: You can read the manual of the manual with `man man` 😃
### Help!
If you want to read a smaller version of the manual, you can run `COMMAND --help`. Almost every command supports the `--help` flag and its small version `-h`. You will then get a quick reference.
Try `wc --help`!
### Paths
Lets build one more house!
@ -381,4 +387,58 @@ What we have just learned about paths does not only apply to `cp`, but also to `
One thing has to be mentioned about `cp`: To copy directories instead of just files, use the option/flag `-r` to copy recursively like with `mv`.
It might be overwhelming for you to memorize all the commands. Again, if a command is an abbreviation, then knowing what it stands for is very helpful. Otherwise, just look up the command you are looking for in this book or in a search engine ;)
### Terminal shortcuts
For typing a long path, you can use the **autocompletion**. Go back to the home directory using `cd`. Lets say that we want to read the rules of the directory `happy_house`. Type `cat hap` without hitting enter yet. Now press `Tab` and see how the path is autocompleted to `cat happy_house/`. Now type `ru` and hit `Tab` again. Then you have `cat happy_house/rules.txt`. Much faster, right?
If you have another directory in your home that is called something like `happy_directory`, then the autocompletion completes only to `cat happy_`. Pressing `Tab` again shows you the possible options. Type one or more characters to make an autocompletion possible and then hit `Tab` again to have the directory name autocompleted.
Often, commands are not long, but you can use autocompletion to complete commands too. If you type `ech` and then press `Tab`, you get the autocompletion `echo` with the space at the end to enter options or arguments. In this case, we did only save entering one character and a space, so `echo` is not the best opportunity for autocompletion. But this is only a demonstration. Some commands might be longer.
You might think that you don't need autocompletion at all. But you should use it. Not only for autocompletion, but for verification!
When you type `cat hapy_house/ru` and then press `Tab`, you don't get any autocompletion although you would expect it. But did you notice the missing `p` in `happy`?
This is what is ment by verification. If you don't get an autocompletion although you think that you should, then check what you have typed so far. It is much easier to correct things this way that having to correct them after trying to run the command.
But what if you did run a command with a mistake and you have to correct it? Or what if you want to run the same command with small modifications? Do you have type the whole command again?
Fortunately, no! You can use the up and down arrows to navigate through your commands history. Try it out!
If you started typing a command and you did notice that you did miss something in the middle of the command, you might try to use the mouse and click. No clicks will help you! Instead, use the left and right arrow keys.
If you want to go to the beginning of the command, press `Ctrl + a`. You can go then back to the end with `Ctrl + e`.
If you want to close a session quickly, press `Ctrl + d`. For now, this will close your terminal. Later, when we use SSH to access other Linux machines, `Ctrl + d` will close the connection and bring you back to the prompt of your machine.
Lets write a very small program in Python. Enter `nano nonstop.py` and type in the following small snippet:
```python
from time import sleep
while True:
print("You can not stop me, can you?")
sleep(1)
```
Now exit the file while saving the buffer. If you don't know about Python, don't worry. You don't need any programming skills for now. All that you have to know is that this program runs forever and prints "You can not stop me, can you?" every second.
You should not write endless loops. This is only a demonstration for a program that is running and you would like to stop.
Enter `python3 nonstop.py` to run the code.
Annoying, right? To stop a running program, press `Ctrl + c`. You _have to_ remember this shortcut!
You can also use `Ctrl + c` if are typing a command and you want to start over. Instead of pressing `Backspace` for a long time, just press `Ctrl + c`!
But wait, `Ctrl + c` is (normally) used for copying, right?
No, not in the terminal. If you want to copy text in the terminal, then select it with the mouse and the press `Ctrl + Shift + C`.
To paste text into the terminal, press `Ctrl + Shift + v`.
Why is it so inconvenient? It has historical reasons. You have to take it as it is 🙁
---
It might be overwhelming to memorize all commands, shortcuts and options. If a command is an abbreviation, then knowing what it stands for is very helpful. If you want to use an option but you are not sure which flag it was, then use `--help` or read the manual with `man`! Otherwise, you can look up things in this book or using a search engine 😉