@@ -6,6 +6,8 @@ This is a huge chapter. I could divide it up in many subchapters but I like to h
The shell, or the terminal is a really useful tool. Bash is the standard shell on most Linux distros.
One really useful trick when working with bash is to search for old commands that you have used. You can access this search function by doing `ctr-r` in the terminal.
### Navigating
`pwd` - Print working directory
@@ -32,7 +34,6 @@ Use `/searchterm` to search. It is the same command as in vim. `n` to scroll to
`more` - Output file but just little bit at a time. `less` is better.
### Working with files
`touch` - Create a new file.
@@ -57,7 +58,6 @@ Watch the command destroy an entire machine: [https://www.youtube.com/watch?v=D4
`rmdir` - Remove empty directory
### A little bit of everything
`history` - Show commands history
@@ -108,21 +108,22 @@ which bash
# Usually outputs: /bin/bash
```
## 2. Editing text
First let's just clear out something about **standard streams**, or **I/O**-streams. Standard streams are the streams that are used to interact between the human computer-user and the machine. There are three standard streams: standard input (stdin), standard output (stdout), and standard error (stderr).The stdin stream can be seen as an abstractions of the real keyboard input. So when you issue a command/program that requires input the program does not read straight from the keyboard input, instead it reads from the file STDIN.
First let's just clear out something about **standard streams**, or **I/O**-streams. Standard streams are the streams that are used to interact between the human computer-user and the machine. There are three standard streams: standard input \(stdin\), standard output \(stdout\), and standard error \(stderr\).The stdin stream can be seen as an abstractions of the real keyboard input. So when you issue a command/program that requires input the program does not read straight from the keyboard input, instead it reads from the file STDIN.
### Stdin
Stdin is the data that gets inputed into the program. An example of a program that requires stdin data is `cp`. In order for the program to do anything it needs input data. For example `cp file1 copy_of_file1`. Here `file1` and `copy_of_file1` is the stdin.
So the default Stdin comes from the STDIN-file that is a text-file representation of the keyboard input. But often times we do not want to input stuff from the keyboard, sometimes we want to input something into a program that comes from another file. That is when we can use redirection symbol: `>`.
So an example could be `cat < my_text_file.txt`. The data from my_text_file.txt will now be used as input instead of the keyboard input.
So an example could be `cat < my_text_file.txt`. The data from my\_text\_file.txt will now be used as input instead of the keyboard input.
The file descriptor for **stdin** is: **0**
### Stdout
Stdout is the data that get ouputed from the program.
For example, when you use the command `cat file1` that data/text that gets outputed is the stdout The same with the program `ls`. Not all programs have stdout. For example when you use `mv` or `cp` successfully you get no stdout back from the program.
@@ -146,6 +147,7 @@ This will take the stdout from `ls -la` and forward/redirect it into the `less`
The file descriptor for **stdout** is: **1**
### Stderr
Stderr is the stream used for outputting error messages. So if a program fails for whatever reason. For example, if we try to copy a file that does not exist, this will be the stdrr output:
So awk is an advanced tool for editing text-files. It is its own programming language to it can become quite complex. Awk iterates over the whole file line by line.
@@ -294,7 +287,6 @@ We can use the -F flag to add a custom delimiter.
awk -F ':' '{print $1}' test.txt
```
So if you are manipulating some text you might want to start the output with some info about the columns or something like that. To do that we can use the BEGIN-keyword.
```
@@ -304,7 +296,6 @@ awk 'BEGIN{printf "IP-address \tPort\n"} /nop/ {print $3} END {printf "End of th
Here we are printing IP-address PORT to the first line of the file.
## 3. User management
To add a user we do:
@@ -367,15 +358,15 @@ The next three letters are for read, `w` for write and `x` for execute. The firs
To display information regarding the systems processes you can use the `ps` command.
```
ps -aux
```
`-a` stands for all
`-u` stands for all processes by all users
`-x` stands for all processes that don't run a `tty`
If you run this command you will probably see a pretty big output. In the column for **command** you will see what command has been run. Every process has a Process Identification Number (**PID**). Something you will also see in the output.
If you run this command you will probably see a pretty big output. In the column for **command** you will see what command has been run. Every process has a Process Identification Number \(**PID**\). Something you will also see in the output.
All of theses processes can actually be found in `/proc`. You just go to `/proc/[pid]`. In `/proc` you can find information about the system, and you can actually change the system if you change those files! But more on that later. What I wanted to explain is that if we look at the output from `ps` we see that some commands are in brackets. Like this:
If you are using a distro that is Long Term Supported (LTS). You will not get the latest Kernel version, but you will get the latest Long Term Supported version.
If you are using a distro that is Long Term Supported \(LTS\). You will not get the latest Kernel version, but you will get the latest Long Term Supported version.