clarify various entries
This commit is contained in:
parent
95d9ddf031
commit
4f1ca14d02
14
basics/at.md
14
basics/at.md
@ -1,3 +1,13 @@
|
||||
Install with:
|
||||
|
||||
> sudo apt install at
|
||||
|
||||
> sudo pacman -S at
|
||||
|
||||
Enable the daemon service with:
|
||||
|
||||
> sudo systemctl enable --now atd
|
||||
|
||||
Then jobs can be specified with absolute time, such as:
|
||||
|
||||
> at 16:20
|
||||
@ -8,6 +18,10 @@ Then jobs can be specified with absolute time, such as:
|
||||
|
||||
> at teatime
|
||||
|
||||
Type in your command, e.g.:
|
||||
|
||||
> touch /tmp/myFile.txt
|
||||
|
||||
The jobs can also be specified relative to the current time:
|
||||
|
||||
> at now +15 minutes
|
||||
|
195
basics/bash.md
195
basics/bash.md
@ -1,195 +0,0 @@
|
||||
# STIN, STOUT, STERR
|
||||
|
||||
Input is 0, output is 1, error is 2.
|
||||
|
||||
Pipe standard output to log.txt while also outputting it.
|
||||
|
||||
> cat file.txt |& tee -a log.txt
|
||||
|
||||
Copy file and *if* that's successful, delete it where it stands.
|
||||
|
||||
> scp archive.tar.gz pi@192.168.0.31:/home/pi && rm archive.tar.gz
|
||||
|
||||
A double pipe will try one, and do the other if that fails.
|
||||
|
||||
> cp -r ~/Archive ~/Backup || tar czf Archive.tar.gz *
|
||||
|
||||
# REGEX
|
||||
|
||||
Regular expression characters include:
|
||||
|
||||
\\ ^ $ . | ? * + () [] {}
|
||||
|
||||
As a result, grep cannot read these characters as literal characters unless they are escaped. E.g.
|
||||
|
||||
> grep wtf\\? log.txt
|
||||
|
||||
... will search the string 'wtf?' in the file log.txt. Another version is egrep (now used with 'grep -e') which uses more characters as special characters, or fgrep, which treats all characters as literal strings.
|
||||
|
||||
# Environmental Variables
|
||||
|
||||
PWD, USER, PATH
|
||||
|
||||
To display all environmental (but not local) variables, use
|
||||
|
||||
> env
|
||||
|
||||
Set a variable with
|
||||
|
||||
> colour=red
|
||||
|
||||
Display your variable with
|
||||
|
||||
> echo $colour
|
||||
|
||||
Export this to the entire system using:
|
||||
|
||||
> export colour=blue
|
||||
|
||||
# Search for Programs
|
||||
|
||||
Search for commands relevant to `cat`.
|
||||
|
||||
> apropos cat
|
||||
|
||||
Show files used in the `cat` program.
|
||||
|
||||
> whereis cat
|
||||
|
||||
Show *which* file is the actual code which runs when you type `cat`:
|
||||
|
||||
> which cat
|
||||
|
||||
# Working with Text
|
||||
|
||||
Convert every tab to ten spaces.
|
||||
|
||||
> expand -t 10 file.txt
|
||||
|
||||
Or the reverse, with 3 spaces converting to a tab.
|
||||
|
||||
> unexpand -t 3 file.txt
|
||||
|
||||
Format a file by cutting text after 60 characters.
|
||||
|
||||
> fmt -w 60 file.txt
|
||||
|
||||
Indent all but the first line of a paragraph.
|
||||
|
||||
> fmt -t file.txt
|
||||
|
||||
Look at the new lines of a file only:
|
||||
|
||||
> tail -f /var/log/syslog
|
||||
|
||||
The sort function arranges lines alphabetically. Use -r to reverse and -n to sort by number.
|
||||
|
||||
# Sed
|
||||
|
||||
Change all examples of hey to hoi in greetings and show that output (does not change file).
|
||||
|
||||
> sed 's/hey/hoi/g greetings.txt'
|
||||
|
||||
Change each example of 'cat' to 'dog' in the file 'animals.md'.
|
||||
|
||||
> sed 's/cat/dog/g' animals.md
|
||||
|
||||
# Measurement
|
||||
|
||||
Measure how long a script takes for super-autism powers.
|
||||
|
||||
> time [bash script]
|
||||
|
||||
# Aliases
|
||||
|
||||
Make one word equal a longer command with `alias`.
|
||||
|
||||
E.g.:
|
||||
|
||||
> alias wot='sudo systemd-analyze blame && free -h '
|
||||
|
||||
Now when you type 'go', it will perform that entire operation.
|
||||
|
||||
# Functions
|
||||
|
||||
Make a function which checks if something is a file, and if so, shows it on screen with `cat`:
|
||||
|
||||
> function show(){
|
||||
> file "$1" | grep text &\>/dev/null && cat "$1"
|
||||
> }
|
||||
|
||||
That `$1` refers to the first argument typed after the command.
|
||||
If you want to run this on a file called `list`, then use:
|
||||
|
||||
> show list
|
||||
|
||||
...and the list will output, only if it is text.
|
||||
|
||||
In total, this functions the same as typing:
|
||||
|
||||
> file list | grep text &\>/dev/null && list
|
||||
|
||||
Remove a function with:
|
||||
|
||||
> unset my_function
|
||||
|
||||
# Paths
|
||||
|
||||
Every shell has various paths from where it can execute binary files. Find out your current one with:
|
||||
|
||||
> echo $PATH
|
||||
|
||||
To add a directory to a path, e.g. /usr/share/bin, you can declare it in addition to the old path with:
|
||||
|
||||
> PATH=$PATH:/usr/share/bin
|
||||
|
||||
And then check it by echoing the path again.
|
||||
|
||||
Before this, probably best to check the path exists with:
|
||||
|
||||
> if [ -e /usr/share/bin ]; then
|
||||
|
||||
> echo yes
|
||||
|
||||
> fi
|
||||
|
||||
# Pipes, Pedantry and Brackets
|
||||
|
||||
Things that [[ ]] statements can do which [ ] statements cannot:
|
||||
|
||||
- Intuitive and easy 'and' statements.
|
||||
- [[ -z $var && -d ~/LK ]]
|
||||
- Intuitive and easy 'or' statements.
|
||||
- [[ -d LK || -f ghost-backup.zip ]]
|
||||
- Simple expression comparisons
|
||||
- [[ $v1 > $v2 ]]
|
||||
- Simple expression comparisons with clumsy strings
|
||||
- [[ item-1 > item-2 ]]
|
||||
- Vague comparisons
|
||||
- [[ $answer =~ ^y(es)?$ ]]
|
||||
|
||||
# exec
|
||||
|
||||
exec will start a process running as just that process. In a bash script, the line:
|
||||
|
||||
> unison rat
|
||||
|
||||
... will startup `unison` as a sub-process of bash. But:
|
||||
|
||||
> exec unison rat
|
||||
|
||||
... starts unison as its own process.
|
||||
|
||||
# Brace expansion
|
||||
|
||||
> mv picture{,-1}.jpg
|
||||
|
||||
This expands to
|
||||
|
||||
> mv picture.jpg picture-1.jpg
|
||||
|
||||
# `for` Statements
|
||||
|
||||
for f in *tiff;do
|
||||
convert "$f" "${f/.tiff/.png}"
|
||||
done
|
@ -16,9 +16,9 @@ Have a look at **a**ll the files:
|
||||
|
||||
`. ..`
|
||||
|
||||
So `.` means 'here' and `..` means 'you see stairs leading downwards'.
|
||||
So `.` means 'here' and `..` means 'you see stairs leading downwards' (e.g. 'the directory behind you').
|
||||
|
||||
Find out where you are by **p**rinting out your **c**urrent '**d**irectory' (i.e. 'location'):
|
||||
Find out where you are by **p**rinting out your **w**orking '**d**irectory' (i.e. 'location'):
|
||||
|
||||
> pwd
|
||||
|
||||
@ -157,6 +157,10 @@ Make two directories, called 'A', and 'Z':
|
||||
|
||||
> mkdir A Z
|
||||
|
||||
Make a single directory called 'A Z'
|
||||
|
||||
> mkdir 'A Z'
|
||||
|
||||
# Text Searches
|
||||
|
||||
Measure the disk usage of everything ('\*' means 'everything'), and put it in a file called 'disk usage.txt':
|
||||
|
@ -1,86 +0,0 @@
|
||||
# Basic Startup
|
||||
|
||||
BIOS > MBR > GRUB > Kernel > Init > Run Level
|
||||
|
||||
- The BIOS identifies system hardware.
|
||||
|
||||
- The Master Boot Record contains partition and filesystem data.
|
||||
|
||||
- The Grand Unified Bootloader executes the kernel.
|
||||
|
||||
- The Init Executes designates run level (via SysVinit, Upstart, or Systemd).
|
||||
|
||||
- Run Level starts the user's session.
|
||||
|
||||
The Master Boot Record is a 512 byte file called boot.img which starts the first sectore of core.img into memory (GRUB Stage 1.5), which then executes /boot/grub.
|
||||
|
||||
# Access system
|
||||
|
||||
Ctrl+c at boot then add in
|
||||
|
||||
> rw init=bash
|
||||
|
||||
# Run Levels
|
||||
|
||||
0: Half
|
||||
1: Single user mode
|
||||
2: Multi-user, without NFS
|
||||
3: Full multi-user mode
|
||||
4: Unused
|
||||
5: X11
|
||||
6: Reboot
|
||||
|
||||
None of this is used by humans anymore - it's all systemd.
|
||||
|
||||
# Boot Records
|
||||
|
||||
'File System Tab' under /etc/fstab keeps track of the partitions and boot order.
|
||||
|
||||
The logical voluem manager (LVM) can make non-hardware partitions.
|
||||
|
||||
The nomenclature is:
|
||||
|
||||
- PV = physical volume
|
||||
|
||||
- LV = logical volume
|
||||
|
||||
- VG = volume group
|
||||
|
||||
# Volume Groups
|
||||
|
||||
> sudo vgcreate work-volume /dev/sdb2 /dev/sdb4
|
||||
|
||||
This creates the volume group 'work-volume', consisting in sdb2 and sdb4.
|
||||
|
||||
Now you ahve a volume group, you can use it as part of a new logical volume.
|
||||
|
||||
> sudo lvcreate -n noob-lv work-volume
|
||||
|
||||
Then scan for all logical volumes on the system with lvscan.
|
||||
|
||||
> sudo lvscan
|
||||
|
||||
# GRUB
|
||||
|
||||
Install a grub with either:
|
||||
|
||||
> sudo grub-install /dev/sda
|
||||
|
||||
or
|
||||
|
||||
> sudo grub2-install /dev/sda
|
||||
|
||||
This takes all settings from /etc/fstab.
|
||||
|
||||
Then when done editing settings update the script in /boot/grub/grub.cfg (in Debian) or /boot/boot/grub/menu (in other systems).
|
||||
|
||||
There are default examples in /etc/grub.d/ (but not on Ubuntu).
|
||||
|
||||
Finalize your settings with grub-mkconfig (or grub2-mkconfig), or update-grub.
|
||||
|
||||
# Cowardice
|
||||
|
||||
If you can't do that, use boot-repair:
|
||||
|
||||
> help.ubuntu.com/community/Boot-Repair
|
||||
|
@ -39,22 +39,18 @@ case $CRE in
|
||||
esac
|
||||
|
||||
# While and Until
|
||||
This prints from 10 until 2.
|
||||
This prints from 1 until 9.
|
||||
|
||||
> declare -i COUNTER
|
||||
> COUNTER=1
|
||||
|
||||
> COUNTER=10
|
||||
> while [ $COUNTER -lt 2 ]; do
|
||||
|
||||
> while [ $COUNTER -gt 2 ]; do
|
||||
> ((COUNTER++))
|
||||
|
||||
> echo The counter is $COUNTER
|
||||
|
||||
> COUNTER=COUNTER-1
|
||||
> echo $COUNTER
|
||||
|
||||
> done
|
||||
|
||||
> exit 0
|
||||
|
||||
```
|
||||
|
||||
There's also 'until', which stops when something is true, rather than keeping going when something is true.
|
||||
|
@ -1,22 +1,14 @@
|
||||
Anacron manages crontabs which might not have run because the machine was turned off. The first value shows the days between runs, the second shows how many minutes to wait after a boot to run.
|
||||
|
||||
For example:
|
||||
|
||||
> cat /etc/anacrontab
|
||||
|
||||
`7 15 cron.daily run-parts --report /etc/cron.daily`
|
||||
|
||||
This would run crontab every 7 days, and wait 15 minutes until after boot to run.
|
||||
# Cron
|
||||
|
||||
Various services from cron exist, e.g.
|
||||
|
||||
> sudo apt -y install cronie
|
||||
|
||||
start the cronie with
|
||||
Start the cronie with
|
||||
|
||||
> sudo systemctl start cronie
|
||||
> sudo systemctl enable --now cronie
|
||||
|
||||
start a cron with
|
||||
Specify a cron job with:
|
||||
|
||||
> cron -e
|
||||
|
||||
@ -34,6 +26,26 @@ For example, you can update the database, meaning searches with 'locate' command
|
||||
|
||||
> */30 * * * * /usr/bin/updatedb
|
||||
|
||||
## Syntax
|
||||
|
||||
`* * * * *`
|
||||
|
||||
These five points refer to:
|
||||
|
||||
`minute hour day month weekday`
|
||||
|
||||
So '3pm every Sunday' would be:
|
||||
|
||||
`0 15 * * 7`
|
||||
|
||||
Here 'Sunday' is indicated by "7", and '3pm' is 'the 15th hour'.
|
||||
The minute is '0' (i.e. '0 minutes past three pm').
|
||||
|
||||
Doing the same thing, but only in February, would be:
|
||||
|
||||
`0 15 * 2 7`
|
||||
|
||||
|
||||
# Testing with runparts
|
||||
|
||||
Run-parts runs all executable scripts in a directory.
|
||||
|
@ -10,3 +10,7 @@ Or remove one with
|
||||
|
||||
> sudo modprove uvcvideo
|
||||
|
||||
The PC's irritating speaker beep can be really annoying. Disable it with:
|
||||
|
||||
> sudo rmmod pcspeaker
|
||||
|
||||
|
@ -4,6 +4,10 @@ Set layout to British English.
|
||||
|
||||
> setxkbmap -layout gb
|
||||
|
||||
Or Polish with:
|
||||
|
||||
> setxkbmap -layout pl
|
||||
|
||||
| Language | short |
|
||||
|:--------|:------|
|
||||
| Polish | pl |
|
||||
|
@ -1,4 +1,24 @@
|
||||
# Basic Signals
|
||||
If you want to kill a program in a graphical environment, open a terminal and typeL
|
||||
|
||||
## Graphical Programs
|
||||
|
||||
> xkill
|
||||
|
||||
Then click on the application which you want to kill.
|
||||
|
||||
## All Programs
|
||||
|
||||
To kill a program, find it with:
|
||||
|
||||
> pgrep discord
|
||||
|
||||
This will give you the UUID, e.g. `19643`.
|
||||
|
||||
Kill the program with:
|
||||
|
||||
> kill 19643
|
||||
|
||||
## Types of Kill
|
||||
|
||||
To see an ordered list of termination signals:
|
||||
|
||||
@ -8,3 +28,26 @@ To see an ordered list of termination signals:
|
||||
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
|
||||
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
|
||||
|
||||
|
||||
You can select these levels with a '- number'.
|
||||
Higher numbers are roughly equivalent to insistence.
|
||||
|
||||
For example:
|
||||
|
||||
> kill -1 3498
|
||||
|
||||
This roughly means 'maybe stop the program, if you can, maybe reload'.
|
||||
|
||||
Or the famous:
|
||||
|
||||
> kill -9 3298
|
||||
|
||||
This means 'kill the program dead, now, no questions, dead'.
|
||||
|
||||
**Beware** - if Firefox starts another program to connect to the internet, and you `kill -9 firefox`, this will leave all of Firefox's internet connection programs ("children") still there, but dead and useless.
|
||||
|
||||
- A dead program which sits there doing nothing is known as a 'zombie'.
|
||||
- A program which is run by another program is called a 'child program'.
|
||||
- A child whose parent program is dead is called an 'orphan'.
|
||||
- A child who remains running despite being useless because the parent is dead is called an 'orphan zombie'.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user