modify basic filestructure

It's unclear what's 'basic', so `basic/` notes have been mostly moved.
The remainder became `shell/`.
This commit is contained in:
2026-04-20 02:42:41 +02:00
parent c95176c7a9
commit bca5337ac3
23 changed files with 2 additions and 445 deletions

88
shell/conditionals.md Normal file
View File

@@ -0,0 +1,88 @@
---
title: "conditionals"
tags: [ "basics" ]
---
# If statements
Test statement equality as so:
```
read t1
read t2
if test $t1 != $t2; then
echo 'variables do not match'
else
echo 'variables match'
fi
exit 0
```
# Case Structure
These deal with multiple states rather than forking conditions.
Example:
```
#!/bin/bash
# Simple case demonstration
echo "What's your favourite creature?"
read CRE
case $CRE in
human | humanoids ) echo "Why is $CRE always standard?"
;;
troll | monsters ) echo "Not exactly known for their character ..."
;;
owlbears | monsters ) echo "Really you're a wizard fan"
;;
esac
```
# While and Until
This prints from 1 until 9.
```sh
COUNTER=1
while [ $COUNTER -lt 2 ]; do
> ((COUNTER++))
> echo $COUNTER
> done
```
There's also 'until', which stops when something is true, rather than keeping going when something is true.
# For
```sh
for i in $( ls ); do
> du -sh $i
> done
```
# Sequences
The sequences tool counts up from X in jumps of Y to number Z.
Count from 1 to 10.
```sh
seq 10
```
Count from 4 to 11.
```sh
seq 4 11
```
Count from 1 to 100 in steps of 5.
```sh
seq 1 5 100
```

22
shell/eval.md Normal file
View File

@@ -0,0 +1,22 @@
---
title: "eval"
tags: [ "basics" ]
---
Compose a statement for execution.
```sh
x='echo $y'
echo $x
y=dragon
eval "$x"
```
The results remain in the current shell, unlike sub-shells.
```sh
b=basilisk
sh -c 'echo $b'
eval "g=goblin"
echo $g
```

11
shell/games.md Normal file
View File

@@ -0,0 +1,11 @@
---
title: "bash games"
tags: [ "fun" ]
---
Games are a great way to learn bash.
- `mapscii.me` is an interactive terminal map.
1. Install telnet.
1. `telnet mapscii.me`
- [Over the Wire](https://overthewire.org/wargames) teaches bash with small challenging you can do over `ssh`.

26
shell/joyous_ascii.md Normal file
View File

@@ -0,0 +1,26 @@
---
title: "Joyous ASCII"
tags: [ "fun" ]
---
- `asciiquarium`
- `cbonsai -lim "$(fortune)"`
- `printf 'w\na\n' | ssh -tt nethack@alt.org`
```sh
cow=$(cowsay -l | sort -R | head -1)
fortune -s | figlet | cowsay -nf $cow | lolcat
```
Watch the [Collatz Conjecture](https://en.wikipedia.org/wiki/Collatz_conjecture) collapse:
```sh
x="$(du -sc ~/.cache | tr -d '[:alpha:]' | tail -1)"
until [ "$x" -eq "1" ]; do
test "$(( x % 2 ))" -eq 0 && x=$(( x / 2 )) || \
x=$(( x * 3 + 1 ))
clear -x
figlet "$x" | lolcat
sleep 1
done
```

28
shell/locate_program.md Normal file
View File

@@ -0,0 +1,28 @@
---
title: "locating"
tags: [ "basics" ]
---
# Type
`type` shows what kind of thing you're running, be it an alias, function, or binary program.
```sh
type cd
type ls
type -P ls
type -a cat
```
# Whereis the Program
Where is `grep` and all its configuration files?
```sh
whereis grep
```
Which one of these is the binary file which you actually use?
```sh
which grep
```

46
shell/ls.md Normal file
View File

@@ -0,0 +1,46 @@
---
title: "ls"
tags: [ "basics" ]
---
Firstly, your `ls` is probably aliased to something.
Check it with:
```sh
alias ls
```
If the prompt shows some alias, then start by removing it:
```sh
unalias ls
```
Now we can begin.
Check the most recently modified file:
```sh
ls -t
```
Reverse this with `tac` to see the file which has been unmodified the longest:
```sh
ls -t | tac
```
Group files by extension:
```sh
ls -X
```
Sort largest files first:
```sh
ls -X
```

View File

@@ -0,0 +1,191 @@
---
title: "Quality of Life"
tags: [ "basics", "setup" ]
dependencies: [ "vi", "basics" ]
---
This & That
===========
Refer to 'that last thing', and 'the first thing':
```sh
fortune -l > file1
cat !$ | tr -d u
diff !^ !$
```
**NB:** this can go wrong:
```sh
ls -l file1 file2
cat !^
```
Done
----
`<C-d>`
- If you have a command, Control + d will execute the command.
- If you have nothing, `exit`.
Clear Search Highlights
=======================
`<Esc>+u`
Input Run-Commands (`~/.inputrc`)
=================================
Alias Expansion
---------------
```sh
echo '"\C- ": shell-expand-line' >> ~/.inputrc
exec bash
```
Now you can expand all aliases with 'Control + Space'.
Try just `ls`, then 'Control + Space'.
Glob Expansion (`*`)
--------------------
```sh
echo '"\C-x": glob-expand-word' >> ~/.inputrc
exec bash
ls *<C-x>
```
- Are you sure you want to delete that?
* `rm -r *<C-x>`
- Clean up the Downloads folder:
* `rm Downloads/*pdf<C-x>`
Arbitrary Commands
------------------
Use `\n` as a 'newline' character to automatically press `<Return>`.
```sh
echo 'Control-y: "| lolcat\n"' >> ~/.inputrc
exec bash
ls<C-y>
```
```sh
Control-l: "\C-u clear -x && ls\n"
exec bash
cd /etc/<C-l>
```
Readline as Vi
--------------
```sh
echo 'set editing-mode vi' >> ~/.inputrc
echo 'set keymap vi-insert' >> ~/.inputrc
exec bash
```
The prompt now works according to `vi`-motions.
This goes much further than the bash-option, `set -o vi` ('set option: `vi`').
It changes the cursor in the terminal, not just bash.
Try:
- `ls <C-n>`
- `ls <C-p>`
- Type some words.
- `<Esc>0dw$p`
- <Esc> to normal-mode, and go back with 'b', and forward with 'e'.
- `4b` to step back four times.
- `cE`
- `<Esc>kcw`
- ls -a<Esc>xxxx
Readline can work with python one you set `PYTHON_BASIC_REPL` to `true`.
```sh
echo 'export PYTHON_BASIC_REPL=true' >> ~/.bashrc
exec bash
```
```python
im<C-n>os<Return>
os.li<C-n><Return>
<Esc>kfn
<C-d>
```
Fix Globs!
----------
If you tried the previous commands then they will not work any more, because the `vi`-commands overwrite the other commands.
Remove them.
```sh
sed '/ vi/d' ~/.inputrc
sed -i '/ vi/d' ~/.inputrc
sed '1 i set editing-mode vi' .inputrc
sed -i '1 i set editing-mode vi' ~/.inputrc
sed -i '2 i set keymap vi-insert' ~/.inputrc
```
Vi-sibility
-----------
The `readline` prompt becomes confusing if you don't remember if you're in insert or normal mode.
But you can show the current mode in the prompt:
```sh
echo 'set show-mode-in-prompt on' >> ~/.inputrc
exec bash
```
Set new symbols for normal and insert mode:
```sh
echo 'set vi-ins-mode-string " "' >> ~/.inputrc
echo 'set vi-cmd-mode-string " "' >> ~/.inputrc
```
Fuzzy Sort
==========
Check your repos for `sk-im`, and install.
The program is called `sk`.
```sh
FUZZY=sk
```
If you don't have it, `fzy` or `fzf` should work the same way.
```sh
FUZZY=fzy
```
Find some 'read-config' files to check out:
```sh
find . -maxdepth 2 -name "*rc"
find . -maxdepth 2 -name "*rc" | $FUZZY
```
And read some:
```sh
PAGER='less -R'
$PAGER "$(find . -maxdepth 2 -name "*rc" | $FUZZY)"
```
Make the change long-term:
```sh
alias rrc='$PAGER "$(find . -maxdepth 2 -name "*rc" | sk)"'
alias | grep rrc= >> ~/.bash_aliases
```

36
shell/tree.md Normal file
View File

@@ -0,0 +1,36 @@
---
title: "tree"
tags: [ "basics", "tree", "markdown" ]
---
The `tree` utility outputs a full listing of everything in your current directory, and those below.
- Just directories: `tree -d`
- Output colour to `less`: `tree -C --info | less -re`
- Ignore files in the `.gitignore` file: `tree --gitignore`
You can place information about the files in a directory to use with the `tree --info` option, like this:
```
config
Config files.
This is a git submodule.
README.md
Summary of the git.
*.jpg
Little picture, does not display
words well.
```
Each description-line starts with a tab.
## Markdown Conversion
To represent a file structure as a nested series of markdown lists, you can try this horrifying `sed` one-liner:
```sh
tree -tf --dirsfirst --gitignore --noreport --charset ascii | \
sed -e 's/| \+/ /g' \
-e 's/[|`]-\+/ */g' \
-e 's:\(* \)\(\(.*/\)\([^/]\+\)\):\1[\4](\2):g'
```

24
shell/yes.md Normal file
View File

@@ -0,0 +1,24 @@
---
title: "yes"
tags: [ "basics" ]
---
# The Best Linux Program: `yes`
The program `yes` prints the word `yes` to your terminal until you cancel it, perhaps with 'Control + c'.
Or technically it prints `yes\n`, meaning `yes` and then a new line (like pressing the Return key).
This is extremely powerful.
If you ever want to automatically install something which persistently nags you with `do you want to do the thing? [y/N]?`, then you can just pipe `yes` into that program, and it will answer 'yes' to all questions.
```sh
yes | $INSTALL_SCRIPT_FILE.sh
```
This works best for disposable systems, like VMs or containers.
Try this on a live system, and you might find out that you should have read that message fully.
```sh
yes | yay
```