1
0
Fork 0
mirror of https://codeberg.org/Mo8it/How_To_Linux.git synced 2024-10-18 11:52:39 +00:00

Done some basics

This commit is contained in:
Mo 2022-08-19 23:40:47 +02:00
parent df8a7fa0d6
commit b4c7e93577
3 changed files with 144 additions and 25 deletions

View file

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

View file

@ -1,24 +0,0 @@
# The terminal
The terminal, the console, the command line. All terms refer to the same thing. Get access to a Linux system and open a terminal. Wait, 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!
Again, don't panic! What you see is just a prompt (usually on a dark background).
Now, how to interact with the terminal? You are probably not seeing a lot of buttons on your terminal. This is because you interact with it (mainly) through your keyboard. But what to type?
It is like a chat with your computer. But your computer is not into memes. It is a soldier waiting for your commands!
Lets enter a command, probably your first command. Type `echo "Hello!"` and press enter:
```console
$ echo "Hello!"
Hello!
```
Congratulation! You did just say hi to your computer and it did even reply! What a charm!
Well, to be more precise, you gave a command to your computer to say "Hello!" and it did that.
I know, I did just brake the romance between you and your computer. I appoligize.

View file

@ -0,0 +1,143 @@
# Terminal basics
The terminal, the console, the command line. All terms refer to the same thing. Get access to a Linux system and open a terminal. Wait, 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!
Again, don't panic! What you see is just a prompt (usually on a dark background).
Now, how to interact with the terminal? You are probably not seeing a lot of buttons on your terminal. This is because you interact with it (mainly) through your keyboard. But what to type?
It is like a chat with your computer. But your computer is not into memes. It is a soldier waiting for your commands!
Lets enter a command, probably your first command. Type `echo "Hello!"` and press enter. This is the output:
```console
$ echo "Hello!"
Hello!
```
Congratulation! You did just say hi to your computer and it did even reply! What a charm!
Well, to be more precise, you gave a command to your computer to say "Hello!" and it did that.
I know, I did just brake the romance between you and your computer. I appoligize.
`echo` is a command that prints out what you give as an argument. It might not seem to be a useful command. Why would I want the computer to echo my words? The importance of `echo` will be clear mainly when writing scripts. More about this in later sections!
Lets try more commands. type `ls` and press enter. What do you see? The output is going to be the files and directories in your current path. `ls` stands for _list_.
What if you want to take a look at the content of a different directory at different path?
To examine this, lets first create a new directory. Enter the command `mkdir empty_directory`. Well, you don't see anything? Did the command do something at all? To verify this, run `ls` again. Now you should be able to see your new directory `empty_directory` listed too! `mkdir` stands for _make directory_. `empty_directory` is just a name for our new directory. You could have used `mkdir Images` for example to create a directory called `Images`.
Is `empty_directory` really empty? Lets verify that.
Enter the command `cd empty_directory`. Again, you don't see an output. But maybe you did notice that a part of your prompt changed from `~` to `empty_directory`. 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 abbrevations does help you to memorize them.
Now enter the command `ls`. You should not be seeing anything because the directory is indeed empty.
An empty house is a sad house. Lets give the directory some friends to live within it. Enter the command `touch friend1.txt`. Now enter `ls` again:
```console
$ ls
friend1.txt
```
You should see the first friend of the empty directory. `touch` creates a file if it does not exist. It does also have another use case which is not relevant at this moment.
But wait a minute, our directory `empty_directory` is not empty anymore! Lets fix that by renaming it.
Enter the command `cd ..` to go one directory back. The two points `..` refer to the parent directory in Linux.
Now that you are back in `~`, enter `mv empty_directory happy_directory`. Now enter `ls` again. You can see that `empty_directory` does not exist anymore. It was renamed to `happy_directory` (_since it has at least one friend now_). `mv` stand for _move_. Moving is not the same as renaming, right? Well, `move` does move file or directories to a new destination while making it possible to give the file or directory a new name on the destination. So we did _move_ the directory `empty_directory` to the same location, but we did give it a new name.
I know, it is tricky. Lets take a look at an example that does actually _move_. Enter the command `touch friend2.txt friend3.txt`. This will create two new files at the same time. This way, you don't have to type `touch friend2.txt` **and** `touch friend3.txt`.
Now lets move one of our new text files. Enter `mv friend2.txt happy_directory`. Enter `ls` to see that `friend2.txt` did disappear. Lets verify that it now lives in `happy_directory`. You could use `mv happy_directory` and then `ls` analogously to the strategy above. But it is faster to use `ls` directly. Enter `ls happy_directory`:
```console
$ ls happy_directory
friend1.txt friend2.txt
```
We did verify that `friend2.txt` was moved. Lets move `friend3.txt`, too. Enter `mv friend3.txt happy_directory/loud_friend.txt`. Take a look at the content of your directory now:
```console
$ ls happy_directory
friend1.txt friend2.txt loud_friend.txt
```
We did not only move `friend3.txt`. We did also give it a new name in the destination. Hopefully, you have now a better understanding of renaming with `mv`.
What if our directory is not really _happy_ anymore since a loud friend did move in. Lets remove that loud friend!
Enter `mv happy_directory` and then `rm loud_friend.txt`. You will not see any output, but lets see what has changed in the directory:
```console
$ ls happy_directory
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`.
Does `rm` also work with directories? Lets test it:
```console
$ ls
friend1.txt friend2.txt
$ mkdir zombies
$ ls
friend1.txt friend2.txt zombies
$ rm zombies
rm: cannot remove 'zombies': Is a directory
```
So it does not work. To delete an empty directory, use `mrdir`:
```console
$ rmdir zombies
$ ls
friend1.txt friend2.txt
```
`rmdir` stands for _remove directory_. But it does only work on empty directories! Lets verify this on none empty directories:
```console
$ ls
friend1.txt friend2.txt
$ mkdir zombies
$ touch zombies/zombie1.txt
$ ls zombies
zombie1.txt
$ rmdir zombies
rmdir: failed to remove 'zombies': Directory not empty
```
What to do now? Turns out, `rm` is more powerful than we thought and can delete directories too, even if they are not empty! But you have to give it a _flag_.
What is a flag? It is an option that you specify after the command name that enables some functionality.
In our case, to remove a directory that is not empty, we need the `-r` flag of `rm`:
```console
$ tree
.
├── friend1.txt
├── friend2.txt
└── zombies
└── zombie1.txt
1 directory, 3 files
$ rm -r zombies
$ ls
friend1.txt friend2.txt
```
The directory `zombies` is removed!
You probably wonder what `tree` is. As you can see in the output above, it shows you the tree of your current directory. It goes recursively through all directories starting with the current path and shows their content.
It might be overwhelming for you to memorize all the commands. Again, if a command is an abbrevation, 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 ;)