change formatting

input examples are now given as

```bash
input $ARG1
```

While outputs use md's '> ' sign as a quote.
This commit is contained in:
2023-06-17 21:28:20 +02:00
parent 1ba3010b81
commit ba8026e0c3
102 changed files with 2388 additions and 3211 deletions

View File

@@ -9,91 +9,136 @@ Don't worry about understanding any of it, just type it in and the habit forms p
You start in a dark room. You want to know where you are by **p**rinting out your **w**orking '**d**irectory' (i.e. 'location'):
> pwd
```bash
pwd
```
Have a look at what is here:
> ls
```bash
ls
```
If you get no response, the list of items is "", meaning "nothing here".
Have a look at **a**ll the files:
> ls -a
```bash
ls -a
```
`. ..`
```bash
. ..
```
So `.` means 'here' and `..` means 'you see stairs leading downwards' (e.g. 'the directory behind you').
Change directory (`cd`) down one level:
> cd ..
```bash
cd ..
```
Look where you are again with `pwd`, then go back up. Use `ls`, and if you see `bob`, then:
> cd bob
```bash
cd bob
```
Move around the directories. The place at the bottom is the 'root', and is known as `/`. Go to the root:
> cd /
```bash
cd /
```
Do `ls` again and change into `etc`. Look at how much space those folders are taking up:
Do `ls` again and `cd` into `etc`. Look at how much space those folders are taking up:
> du iptables
```bash
du iptables
```
That's the number of kilobytes the file is taking up.
Do the same again, but in a human-readable format:
That's the number of kilobytes the file is taking up. Do the same again, but in a human-readable format:
```bash
du -h iptables
```
> du -h iptables
The `du` program has `-h` for 'human', '-s' for 'short', and a bunch of other commands.
Have a look at the manual and try another command:
The `du` program has `-h` for 'human', '-s' for 'short', and a bunch of other commands. Have a look at the manual and try another command:
> man du
```bash
man du
```
Once you're done, press 'q' to quit the manual page and try the extra `du` flag you've found.
Now you can try to gain super-powers and take over the system:
> sudo -i
```bash
sudo -i
```
At this point, you are 'root'. All your commands will be executed, even if they're unsafe, or even if you ask to delete the entire machine. Best to exit out of the root account:
At this point, you are 'root'.
All your commands will be executed, even if they're unsafe, or even if you ask to delete the entire machine.
Best to exit out of the root account:
> exit
```bash
exit
```
Go find a file that isn't a directory. You can tell which is which with:
> ls -l
```bash
ls -l
```
A directory starts with a 'd', like this:
`drwxr-xr-x 79 root root 4096 Jan 3 05:15 /etc/`
```bash
drwxr-xr-x 79 root root 4096 Jan 3 05:15 /etc/
```
A standard file starts with '-', like this:
```bash
`-rw-r--r-- 1 root root 8 Dec 11 17:26 hostname`
```
Look inside the file /etc/hostname to find out your computer's name:
> cat /etc/hostname
```bash
cat /etc/hostname
```
Print out the words "hello world":
> echo "hello world"
```bash
echo "hello world"
```
Move back to your home directory:
> cd
```bash
cd
```
Take the words 'hello world', and put them in 'my_file':
> echo 'hello world' > my_file
```bash
echo 'hello world' > my_file
```
Measure the disk usage of that file, then put the results at the bottom of the file:
> du my_file >> my_file
```bash
du $FILE >> $FILE
```
And check the results:
> cat my_file
```bash
cat $FILE
```
# Autocompletion
@@ -103,50 +148,70 @@ Press tab after typing a few keys and bash will guess what you're trying to typ
Look at your file's owner:
> ls -l my_file
```bash
ls -l $FILE
```
If it says `-rw-r--r-- 1 root root 8 Dec 11 17:26 hostname` then the file is owned by 'root'.
Take your file and change the owner to root:
> sudo chown root my_file
```bash
sudo chown root $FILE
```
Change the same file so it's owned by the group 'audio':
> sudo chown :audio my_file
```bash
sudo chown :audio $FILE
```
Check you did that correctly:
> ls -l my_file
```bash
ls -l my_file
```
`-rw-r--r-- 1 root audio 0 Jan 3 19:20 my_file`
> -rw-r--r-- 1 root audio 0 Jan 3 19:20 my_file
Read the start of that line. Root can 'read' and 'write' to or delete the file. Try to remove (delete) it:
> rm my_file
```bash
rm $FILE
```
You'll see you're not allowed, because you don't own it.
Look at which groups you're in:
> groups
```bash
groups
```
Change the file so that members of the audio group can write to the file:
> sudo chmod g+w my_file
```bash
sudo chmod g+w $FILE
```
Check you got it right with `ls -l`:
> -rw-rw-r-- 1 root audio 0 Jan 3 19:20 my_file
```bash
-rw-rw-r-- 1 root audio 0 Jan 3 19:20 my_file
```
Try to delete the file again:
> rm my_file
```bash
rm my_file
```
If you can't, you're not in the audio group. Add yourself. You'll need to *modify* your *user account*, by **a**ppending 'audio' to your list of groups.
Use `-a` to **a**ppend, and `-G`, to say you're modifying groups:
> sudo usermod -a -G audio [ your username here ]
```bash
sudo usermod -a -G audio [ your username here ]
```
Now you should be able to remove (delete) the file. Remember, that using 'rm file' will not send it to a recycling bin. The file is gone.
@@ -154,59 +219,83 @@ Now you should be able to remove (delete) the file. Remember, that using 'rm fi
Make a directory called 'new test':
> mkdir 'new test'
```bash
mkdir 'new test'
```
Make two directories, called 'A', and 'Z':
> mkdir A Z
```bash
mkdir A Z
```
Make a single directory called 'A Z'
> mkdir 'A Z'
```bash
mkdir 'A Z'
```
# Text Searches
Measure the disk usage of everything ('\*' means 'everything'), and put it in a file called 'disk usage.txt':
> du -sch * > A/'disk usage'.txt
```bash
du -sch * > A/'disk usage'.txt
```
Look at your file:
> cat A/'disk usage.txt'
```bash
cat A/'disk usage.txt'
```
If you think you have too much information, use `grep` to just get the one line of text you want:
> grep total A/disk\ usage.txt
```bash
grep total A/disk\ usage.txt
```
The `grep` program also has a manual ('man page'). You should find out what that `-c` flag does, but the manual is too long to read.
Start the manual:
> man du
```bash
man du
```
Then search for `-c` by pressing `/`. Your final keys should be `man du`, then `/-c`
Find out if the `ls` program also has a 'human readable' format by using `grep` to search for the word 'human':
> man ls | grep human
```bash
man ls | grep human
```
Now use that flag that you've found in combinatin with the `-l` flag to look at a file.
Remove the directory 'Z':
> rmdir Z
```bash
rmdir Z
```
Remove the directory 'Z':
> rmdir Z
```bash
rmdir Z
```
And then remove all the rest:
> rmdir *
```bash
rmdir *
```
The 'A' directory will not budge because it's not empty. Remove it recursively, so the computer will remove the things inside the directory as well as the directory itself:
> rm -r A
```bash
rm -r A
```
# Installation
@@ -214,34 +303,48 @@ You get a package manager which installs programs, fonts, et c.
If you're on something like Debian, you'll have `apt`, or if you're on something like Red Hat, you'll have `yum`.
If unsure, ask where a program is:
> whereis yum
```bash
whereis yum
```
> whereis apt
```bash
whereis apt
```
If you get a hit, you can use whatever program that is to install things.
Set a reminder of your package manager:
> echo my package manager is yum | lolcat
```bash
echo my package manager is yum | lolcat
```
If that failed it's because you don't have `lolcat` installed.
Install lolcat:
> sudo apt install lolcat
```bash
sudo apt install lolcat
```
Try the same command again.
Search for things you want, like `libreoffice`, or `gimp`:
> apt search libreoffice
```bash
apt search libreoffice
```
... then install one of them with:
> apt install [ thing ]
```bash
apt install $PROGRAM
```
Remove `lolcat`, because it's useless:
> sudo apt remove lolcat
```bash
sudo apt remove lolcat
```
... and that's pretty much it. You can move, create, destroy, install things, and look things up.