diff options
| -rw-r--r-- | audio.md | 4 | ||||
| -rw-r--r-- | awk.md | 52 | ||||
| -rw-r--r-- | bash.md | 6 | ||||
| -rw-r--r-- | curl.md | 11 | ||||
| -rw-r--r-- | ffmpeg.md | 16 | ||||
| -rw-r--r-- | file-operations.md | 18 | ||||
| -rw-r--r-- | filesystems.md | 7 | ||||
| -rw-r--r-- | git.md | 2 | ||||
| -rw-r--r-- | locale.md | 4 | ||||
| -rw-r--r-- | network.md | 7 | ||||
| -rw-r--r-- | pdf.md | 19 | ||||
| -rw-r--r-- | postgres.md | 11 | ||||
| -rw-r--r-- | ranger.md | 1 | ||||
| -rw-r--r-- | rsync.md | 23 | ||||
| -rw-r--r-- | xdg-open.md | 7 |
15 files changed, 185 insertions, 3 deletions
@@ -6,3 +6,7 @@ * `-w` for WAV output * `-B` for batch mode (output to one file per track) + +## Inspecting audio files with `soxi` + +* `-d`/`-D`: duration in hours:minutes:seconds/seconds. @@ -13,4 +13,54 @@ Program is ;-separated pattern-action statements. `$0` is whole line, `$1`, `$2`, ... are fields separated by `FS` (by default, whitespace). -Set `FS` with `-F <sepstring>` +Set `FS` with `-F <sepstring>`. This can be a regular expression. + +Actually, the first part is any *condition*, and a /grep/ pattern is just one +possible one. Another useful example: `awk '$2 > 100 { print $3 }'`: print the +third column, if the line's second column is greater than 100. + +## Flags + +* `-F`: set the field separator, `FS` +* `-v`: set any variable + +## Conditions + +* Numerical comparisons: `==`, `!=`, `>`, `>=`, `<`, `<=` +* Regex matches: `~`, `!~` +* Logical operators: `&&`, `||`, `!` + +Special conditions: + +* `BEGIN`: triggered before processing any lines +* `END`: triggered after processing all lines + +If multiple conditions match, each action will be executed for it. In +particular, if multiple actions print, each will print. `next` can come in +useful, skipping all other conditions. + +## Built in Variables + +* `NR`: number of lines processed so far +* `NF`: number of fields (columns) in current line +* `FS`: input field separator, used to split each line into fields. +* `OFS`: output field separator, i.e. what gets printed between comma-separated + items in a `print` statement. Default: ' ' (space). Typical pattern: set it to + something else in a BEGIN block or with the `-v` flag. + +Useful when processing multiple files: + +* `FNR`: like `NR`, resets to 0 on new file +* `FILENAME`: name of currently processed file (`-` when STDIN) + +## Actions + +* `next`: skips processing of following conditions +* `exit`: finish processing (`END` will be executed) +* `printf`: formatted printing + +## Arrays + +* They're really more like hashmaps. +* Index with `[]`. +* Iterate over keys: `for(x in arr) print x, arr[x]` @@ -26,6 +26,12 @@ Loop over integers for i in `seq 10`; do echo $i; done +Loop over lines of file: + + while IFS= read -r line; do + echo "tester: $line" + done < "$1" + ## Conditionals * `-z`: is empty string @@ -0,0 +1,11 @@ +# Curl + +## Basic options + +* `--silent`: suppresses additional output: progress meter, warning/error messages + * Add `--show-error` to return error messages. + * Or `--no-progress-meter` to only remove progress meter, keep messages + +## Request parameters + +* `-X`/`--request <method>`: set the method, e.g. GET, PUT, DELETE, etc. @@ -69,7 +69,21 @@ For the transpose parameter you can pass: ## Concatanate audio - ffmpet -i in1.mp3 -i in2.mp3 -i in3.mp3 -filter_complex '[0:0][1:0][2:0]concat=n=3:v=0:a=1' output.mp3 + ffmpeg -i in1.mp3 -i in2.mp3 -i in3.mp3 -filter_complex '[0:0][1:0][2:0]concat=n=3:v=0:a=1' output.mp3 + +## Concatanate videos + +Works well especially for large number. + +Create file `list.txt` + + file 'video1.mp4' + file 'video2.mp4' + ... + +Then + + ffmpeg -f concat -i list.txt -c copy combined.mp4 ## Fitlering diff --git a/file-operations.md b/file-operations.md new file mode 100644 index 0000000..f9383c2 --- /dev/null +++ b/file-operations.md @@ -0,0 +1,18 @@ +# General file operations and utilities + +## `ls` + +* `-S`: sort by file size (largest first) +* `-r`: reverse sorting order + +## `shred` + +Overwrites a file repeatedly with random data, to prevent data recovery. + +* `-z`: zeroes out at the end +* `-n <N>`: does `N` iterations (deafults to only 3) +* `-u`: deallocates and removes file + +So a common usage: + + shred -zun100 <file> diff --git a/filesystems.md b/filesystems.md new file mode 100644 index 0000000..4f66932 --- /dev/null +++ b/filesystems.md @@ -0,0 +1,7 @@ +# Filesystems + +## MacOS compatibility + +vfat appears to work on all systems - MacOS, Linux, Windows. + +NTFS is read only on MacOS. @@ -15,7 +15,7 @@ git bisect new git checkout <some commit a while ago> git bisect old - git bisect run <command that returns 1 on old, 0 on new> + git bisect run <command that returns 0 on old, 1 on new> ## Patches @@ -17,3 +17,7 @@ both the `en_US` and `pl_PL` utf8 locales, then create a `.config/locale.conf`: # /etc/vconsole.conf KEYMAP=pl2 FONT=lat2-16 + +For high DPI displays (needs `terminus-font` package): + + FONT=ter-v32n @@ -11,6 +11,13 @@ # any protocol lsof -i :8000 +## Inspect network + + # get hosts on LAN + nmap -sn 192.168.0.0/24 + # inspect ports on particular machine + nmap 192.168.0.10 + ## DNS DNS lookup: @@ -4,6 +4,11 @@ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf in1.pdf in2.pdf +GhostScript uses some algorithm to autodetect page orientation, and may +undersireably flip some pages. To disable this, add: + + "-dAutoRotatePages=/None" + ## Compress gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile=output.pdf input.pdf @@ -12,6 +17,20 @@ pdfjam --outfile out.pdf in.pdf 1,3,4-7 +`--landscape` to set orientation of output pages. + +`--angle <angle>` to rotate (counter clockwise). + ## Images to pdf convert in1.jpg in2.jpg out.pdf + +## DjVu to pdf + + ddjvu -format=pdf file.fjvu file.pdf + +* `-quality=85`: can be used to produce smaller output + * `-quality=uncompressed`: disable compression +* `-page=23-48,59`: select pages to convert +* `-verbose` +* `-eachpage`: generates a separate file per page diff --git a/postgres.md b/postgres.md index 28a0043..ddca2e5 100644 --- a/postgres.md +++ b/postgres.md @@ -2,6 +2,17 @@ Default user, db: `postgres` +## `psql` CLI + + psql <database> <user> + +### Meta commands + +- `\c[onnect]`: connects to a database, new server (can specify dbname, username, +host, port, etc., use `-` to leave unspecfied) +- `\dt`: list tables + - There's a bunch of complicated `\d*` commands + ## User management Everything should be done as user `postgres`. @@ -39,3 +39,4 @@ Files can have a single arbitrary tag, persistent between restarts. * `uv` - deselect all * Or `:unmark` * Can also use `:unmark <regex>` +* `:mark <regex>`: selects all matching files diff --git a/rsync.md b/rsync.md new file mode 100644 index 0000000..9e2c2a3 --- /dev/null +++ b/rsync.md @@ -0,0 +1,23 @@ +# rsync + + rsync from/dir to/location + +Copies files, creating `to/location/dir` + + rsync from/dir/ to/location + +Copies the contents of `from/dir` to `to/location/` + +## Options + +Basic ones: + +- `-r/--recursive`: recurses directories +- `-v/--verbose`: increases verbosity +- `--delete`: deletes files from destination that weren't in the source +- `-z/--compress`: compress files during transfer + +### -a / --archive + +Turns on `-rlptgoD`. So recursive (`-r`), and preserves a bunch of stuff like +soft links, permissions, owners, modification times, special files. diff --git a/xdg-open.md b/xdg-open.md index a688517..6113679 100644 --- a/xdg-open.md +++ b/xdg-open.md @@ -6,6 +6,13 @@ to open it. The local database for applications to use is in `~/.config/mimeapps.list`. Need a `.desktop` file, which can be created under `~/.local/share/applications/`. +## Checking the database + + # Looks up program to open mime type + xdg-mime query default <mime type> + # Looks up mime type of file + xdg-mime query filetype <file> + ## Setting defaults Easiest to do with `mimeopen` (from `perl-file-mimeinfo` on Arch): |