Compare commits

...

6 Commits

6 changed files with 271 additions and 33 deletions

View File

@ -1,6 +0,0 @@
---
title: "Linux Knowledge Base"
---
{{< ticks >}}
{{< /ticks >}}

View File

@ -22,20 +22,41 @@ Also `which` shows where a binary file (the program) is,
which cmus
```
# Quick Search for Files
# Search Instantly with `plocate`
You'll need to set up `locate` for this by installing `mlocate`.
`mlocate` needs a list of all files on the machine, so run:
You can search every file on the computer instantly by installing `plocate`.
Once installed, run `sudo updatedb` to create the database of (nearly) every file on the computer.
Check how big the database is:
```bash
du -h /var/lib/plocate/plocate.db
```
Once you have the database, you can find nearly any file instantly.
- Search for gifs: `locate .gif`
- Search for gifs in the `/usr/` directory: `locate /usr/ .gif`
- Search for jpg images with 'dog' or 'Dog' in the name: `locate -i dog jpg`
- Search for videos: `plocate --regex '.mp4$|.mkv$|.wmv$|.webm$|.mov$|.avi$'`
For best results, run `updatedb` regularly, perhaps in [crontab](../system/cron.md).
## Search More Places
`plocate` will not search `/tmp/`, because nobody cares about those files, and won't search inside `/mnt/`, because that's where USB sticks get mounted, so the files keep changing as USB sticks come and go.
Change where `plocate` searches by editing the configuration file at `/etc/updatedb.conf`.
By default, the `/mnt` directory is 'pruned' from the database.
So if you want to search `/mnt` for videos, remove the word `/mnt` from the configuration file.
```bash
cat /etc/updatedb.conf
sudo sed 's#/mnt/##' /etc/updatedb.conf
sudo updatedb
plocate --regex '.mp4$|.mkv$|.wmv$|.webm$|.mov$|.avi$'
```
Then to find a file called 'my-cats.jpg', run:
```bash
locate cats
```
For best results, run `updatedb` regularly, perhaps in crontab.

View File

@ -0,0 +1,180 @@
---
title: "Quality of Life"
tags: [ "basics", "setup" ]
dependencies: [ "vi", "basics" ]
---
This & That
===========
Refer to 'that last thing', and 'the first thing':
```bash
fortune -l > file1
cat !$ | tr -d u
diff !^ !$
```
**NB:** this can go wrong:
```bash
ls -l file1 file2
cat !^
```
Done
----
`<C-d>`
- If you have a command, Control + d will execute the command.
- If you have nothing, `exit`.
Input Run-Commands (`~/.inputrc`)
=================================
Alias Expansion
---------------
```bash
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 (`*`)
--------------------
```bash
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>`.
```bash
echo 'Control-y: "| lolcat\n"' >> ~/.inputrc
exec bash
ls<C-y>
```
```bash
Control-l: "\C-u clear -x && ls\n"
exec bash
cd /etc/<C-l>
```
Readline as Vi
--------------
```bash
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
Works with `python` too:
```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.
```bash
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:
```bash
echo 'set show-mode-in-prompt on' >> ~/.inputrc
exec bash
```
Set new symbols for normal and insert mode:
```bash
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`.
```bash
FUZZY=sk
```
If you don't have it, `fzy` or `fzf` should work the same way.
```bash
FUZZY=fzy
```
Find some 'read-config' files to check out:
```bash
find . -maxdepth 2 -name "*rc"
find . -maxdepth 2 -name "*rc" | $FUZZY
```
And read some:
```bash
PAGER='less -R'
$PAGER "$(find . -maxdepth 2 -name "*rc" | $FUZZY)"
```
Make the change long-term:
```bash
alias rrc='$PAGER "$(find . -maxdepth 2 -name "*rc" | sk)"'
alias | grep rrc= >> ~/.bash_aliases
```

View File

@ -0,0 +1,28 @@
---
title: "ssh to phone"
tags: [ "networking", "ssh", "android" ]
---
1. Install fdroid on phone.
2. Install termux.
3. Open fdroid, and run:
```bash
pkg upgrade
pkg install busybox termux-services openssh openssh-sftp-server
source $PREFIX/etc/profile.d/start-services.sh
```
`openssh-sftp-server` will mount the phone's file-system, and show you some directories in `~/storage/`.
4. Copy your PC's ssh public key to the phone's downloads or somewhere, so you can see it in `~/storage/downloads`.
5. On the phone:
* `yes | ssh-keygen`
* `cat $pubkey.pub >> ~/.ssh/authorized_hosts`.
* Check its ip address with `ifconfig | grep broadcast`
* Check the phone's username with with `whoami`
* `sshd -D`
6. On the PC:
* `ssh -p 8022 -l $phone_username $phone_ip`

View File

@ -0,0 +1,15 @@
---
title: "Download Website"
tags: [ "networking", "scraping" ]
---
```bash
domain=splint.rs
mkdir $domain
cd $domain
wget --recursive --convert-links --backup-converted \
--page-requisites --level=inf --adjust-extension \
-U "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" \
-p --mirror --html-extension --convert-links \
$domain
```

View File

@ -6,35 +6,35 @@ tags: [ "Documentation", "Vision" ]
Convert jpg to png.
```bash
convert image.jpg image.png
magick image.jpg image.png
```
```bash
convert image.jpg -quality 50 image.jpg
magick image.jpg -quality 50 image.jpg
```
'Quality' must be from 1 to 100.
```bash
convert -resize 50% image.jpg image2.jpg
magick -resize 50% image.jpg image2.jpg
```
Resizing only changes jpegs. Change a png with:
```bash
convert input.png png8:out.png
magick input.png png8:out.png
```
# Invert Colours
```bash
convert input.jpg output.jpg -negate
magick input.jpg output.jpg -negate
```
# Make Images Smaller
```bash
convert image.jpg -resize 25% output.jpg
magick image.jpg -resize 25% output.jpg
```
@ -43,13 +43,13 @@ convert image.jpg -resize 25% output.jpg
This is generally used for transparent images.
```bash
convert -trim image.png output.png
magick -trim image.png output.png
```
Make the white of an image transparent.
```bash
convert -transparent white -fuzz 10% input.png output.png
magick -transparent white -fuzz 10% input.png output.png
```
The 'fuzz' option tells the computer that 'close to white' is fine. You might want to use 20% or higher fuzz.
@ -58,7 +58,7 @@ The 'fuzz' option tells the computer that 'close to white' is fine. You might w
## Dropshadow
```bash
`convert <input file> \( +clone -background black -shadow 50x8+0+5 \) +swap -background none -layers merge +repage <output file>`
`magick <input file> \( +clone -background black -shadow 50x8+0+5 \) +swap -background none -layers merge +repage <output file>`
```
@ -70,13 +70,13 @@ mogrify -format png *.jpg
# Printing Words
# Mass convert
# Mass magick
This script converts all jpg files in a directory to svg.
This script magicks all jpg files in a directory to svg.
```
for i in *jpg
do convert "$i" $(ls "$i" | sed s#jpg\$#svg#)
do magick "$i" $(ls "$i" | sed s#jpg\$#svg#)
done
```
@ -86,7 +86,7 @@ The above script has crappy results.
It's better to use potrace.
```
$convert -flatten input.jpg output.ppm
$magick -flatten input.jpg output.ppm
$potrace -s output.ppm -o svgout.svg
```
@ -97,19 +97,19 @@ $potrace -s output.ppm -o svgout.svg
See your installed fonts:
```bash
convert -list font
magick -list font
```
Make an image showing day of the week:
```bash
convert -fill blue -font Sauce-Code-Pro-Semibold-Nerd-Font-Complete-Mono -gravity center -pointsize 79 label:$(date +%A) day.png
magick -fill blue -font Sauce-Code-Pro-Semibold-Nerd-Font-Complete-Mono -gravity center -pointsize 79 label:$(date +%A) day.png
```
Make a meme:
```bash
convert inputmemeimage.png -font impact -fill white -pointsize 84 -stroke black -strokewidth 3 -gravity north -annotate +0+20 'TOP MEME TEXT' -gravity south -annotate +0+20 'BOTTOM MEME TEXT' outputmemeimage.png
magick inputmemeimage.png -font impact -fill white -pointsize 84 -stroke black -strokewidth 3 -gravity north -annotate +0+20 'TOP MEME TEXT' -gravity south -annotate +0+20 'BOTTOM MEME TEXT' outputmemeimage.png
```