1
0
Fork 0
mirror of https://codeberg.org/Mo8it/How_To_Linux.git synced 2024-11-21 20:18:02 +00:00

Complete basics

This commit is contained in:
Mo 2022-08-22 03:25:58 +02:00
parent 6aff23c488
commit 6abbb589ac

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:
@ -381,4 +381,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 read the manual! Otherwise, you can look up things in this book or using a search engine 😉