Table of Contents

1. git

  • Git was initially created by Linus Benedict Torvalds to manage the Linux kernel.

1.1. Nomenclature

1.1.1. Working Tree

  • Or worktree
  • The entire file including the files under the .git/, which means all its history and current state.

1.2. Subcommands

1.2.1. clone

--depth DEPTH clone the number of recent commits specified.

1.2.2. status

  • Show status.

1.2.3. log

  • It shows commits reachable from HEAD, which means past commits.
  • log [([^]<ref>)*] To control the scope, one can specify which commit to start logging.
    • <ref>=(HEAD|<hash>|<tag>|<branch>)(^N|~N)* where ^N means N=th parent when current commit is a merge of multiple commits, and =~N means N parents back.
  • --graph: Show graph
  • --oneline: One line per commit
  • --decorate:

1.2.4. add

  • Stage diffs so that it can be readily committed. Add path at the end
  • -p --patch: Add /hunks/(blocks of changes) individually.

Use reset <file> or restore --staged <file> to undo.

1.2.5. checkout

  • Move HEAD.
$ git checkout <hash|name>

            HEAD
             v
        <branchname>
             v
---O----O----O

======V======

  HEAD   <branchname>
   v         v
---O----O----O

1.2.6. switch

  • Switch branch.

1.2.7. commit

  • Add commit, move branch reference and HEAD.
  • -a to add the changes of the tracked files before commiting.
  • -C or -c=(edit the message) to use the existing commit object, probably there because of =git reset.
  • --amend to replace the tip of the commit with a new one, effectively amending it.
    • --no-edit to keep the commit message.
  • --fixup, --squash: Marks the commit that it is to be squashed when git rebase --autosquash
$ git commit

    <branchname> <- HEAD
        v
---O----O

======V======

        <branchname> <- HEAD
             v
---O----O----O

1.2.8. tag

  • Tag is a immovable identifier.
$ git tag <tagname>

        <branchname>
             v
---O----O----O
    ^
HEAD

======V======

        <branchname>
             v
---O----O----O
   ^
<tagname> <- HEAD

1.2.9. branch

  • Branch is a identifier that moves along as one commits.
$ git branch <branchname>

     <main>
        v
---O----O
   ^
  HEAD

======V======

     <main>
        v
---O----O
   ^
<branchname> <- HEAD

1.2.10. merge

  • Git does three-way merging which analyzes base, local, remote and produces best result.
$ git merge <feature>

    <main> <- HEAD
        v
---O----O
    \---O
        ^
    <feature>

======V======

          <main> <- HEAD
             v
---O----O----O
    \---O---/
        ^
    <feature>
  • --squash
    • Change current working tree into the merged state, but not committed. Therefore, git commit is required.
    • This enables creating a single commit with single parent.

1.2.11. fetch

  • Local branch is created when one checkout the remote branch, and the local branch has an upstream pointer that is connected to the remote branch.
$ git fetch <remote/origin/main>

      HEAD
        v
    <main> ~> <remote/origin/main>
        |_______/
        v
---O----O

======V======

      HEAD
        v
    <main> ~> <remote/origin/main>
        |         |
        v         v
---O----O----O----O

1.2.12. pull

  • Merge local and remote branch.
$ git pull <remote/origin/main>

      HEAD
        v
    <main> ~> <remote/origin/main>
        |         |
        v         v
---O----O----O----O

======V======

      HEAD
        v
    <main> ~> <remote/origin/main>
        \_________|
                  v
---O----O----O----O

1.2.13. push

  • Checks if any divergence happened and if it did git refuses to push. To resolve this one needs to merge the remote branch.
  • --force-with-lease: Only force push if the remote is the same as the local.

1.2.14. diff

  • Changes of working tree (the current state) from the HEAD, Or diff X Y for diff between X and Y.
  • git diff <ref> [<ref>=HEAD] > <patchfile> stores the diff that can be applied by git apply <patchfile>.

1.2.15. reset

  • Uncommit or Unstage or hard reset.
  • --soft: only moves the HEAD, --hard: moves the HEAD and reset the index and working tree.
  • The current HEAD gets stored to ORIG_HEAD.

1.2.16. restore

  • Restore files to a specific state. Add path at the end. It does not affect the index unless --staged
  • -s <tree> --source=<tree>: Specify commit, branch to restore from. Restore from index if unspecified.
  • --staged: Unstage

1.2.17. revert

  • Commit the inverse of previous commits.

1.2.18. cherry-pick

  • Commit just one commit within other branch onto the current branch.

1.2.19. rebase

  • Commit current branch on top of another branch.
  • git rebase -i <ref>: Perform rebase on <ref>. This means the commits after <ref> will be available for rebasing.
    • fixup: append to the previous commit.
    • squash: append the previous commit to itself.
    • reword: change the commit message.
    • edit: perform git commit --amend on the commit.

1.2.20. stash

  • Temporarily stores diffs in a separate area.
  • Name of stash looks like stash@{n} which can be referenced by only the n. The latest stash is 0.
  • git stash push
    • -k --keep-index: Stash only the changes.
    • -S --staged: Stash only the index.
  • git stash pop: Apply the stash and drop it. They must match the index.
  • git stash list, git stash drop <stash>

1.2.21. notes

  • Add notes to commits. It does not affect the commit at all.

1.2.22. worktree

  • add <path> <commit-ish>: copy the entire repository into the <path> (except the per-worktree files, like HEAD, index, …) and link it to the current one. It is a linked worktree.

1.2.23. submodule

  • If a git repository is inside a git repository, then the outer repository only tracks the HEAD of the inner repository.

1.2.24. bisect

  • Track down a bug by bisecting the commits.

1.2.25. instaweb

  • Open a GUI in the browser

1.2.26. gc

  • Garbage collection for tidying up the git files.

1.2.27. blame

  • See who wrote certain code

1.2.28. clean

  • Remove unnecessary files.

1.2.29. maintenance

  • start

1.3. Config

  • Global configuration is in ~/.gitconfig or $XDG_CONFIG_HOME/git/config.
    • The latter is only used when .gitconfig does not exist and git/config does.
  • Local configuration is in .git/config within the repository, it will shadow the global one.
  • Set configuration by git config <options> <section>.<key> <value>.
    • --global for the global configurations.

1.3.1. Structure

  • user
    • name
    • email
  • credential
    • helper: store and cache is provided by default.
  • alias
    • Short string to be used as a subcommand.
  • {{video https://youtu.be/aolI_Rz0ZqY?si=ZFHkS8qCT6Uh5GrA}}
  • gpg
    • Sign your commit
  • maintenance
    • Automatically maintain your repository

1.4. Hook

  • Within the .git/hooks

1.6. Under the Hood

1.6.1. Objects

  • git cat-file to inspect objects
  • Every object is hashed and stored in the same way within the .git/objects/ directory.
  • They are referenced by their hash.
  • Commit
    • Contains the reference to the root tree.
  • Tree
    • Correspond to the directory in the file structure.
    • Contains the reference to trees and blobs within the directory.
  • Blob
    • Correspond to a file.

2. sed

  • Stream Editor
    • It processes text line by line.
  • The stream version of the ed, the original UNIX text file editor, which also used similar commands.
  • The structure is inherited by .

2.1. Options

  • -i
    • In-place editing. Directly changes the text file.
  • -z
    • Replace \n with NULL, then ^, $, \n matches with NULL. This enables multi-line editing.
  • -n --quiet --silent
    • Suppress the automatic printing of pattern space
  • -e SCRIPT
    • Each command in the script is separated by a newline.
    • \w \s. \d does not work. Use [0-9]
    • \0, & for the entire match
    • [abc] *
    • \U to upper, \L to lower, \E return to normal
  • -r -E --regexp-extended
    • (abc) \1 \N Grouping
    • {N} + ? repeat.
  • -f SCRIPTFILE

2.2. Commands

  • : LABEL
  • #COMMENT
  • ADDRESS { COMMANDS }

2.2.1. Addresses

  • NUMBER, FIRST~STEP match line numbers
  • $ last line
  • /REGEXT/ \<C><REGEXP><C> line that matches the
  • 0,ADDRESS until ADDRESS is found
  • ADDRESS,+N N lines follwing ADDRESS
  • ADDRESS,~N from ADDRESS to the line number N or its multiples.

2.2.2. Zero-, One-Address Commands

  • = print the line number
  • a TEXT append text into the next line. \<ret> is used to insert newlines.
  • i TEXT insert text into the previous line.
  • q quit
  • r FILENAME append text from the file. R append one line at a time from the file

2.2.3. Address Range Commands

  • c TEXT
  • d delete pattern space
  • h copy pattern space to hold space, H append to hold space
  • g copy hold space to pattern space, G append to pattern space
  • n read the next line into the pattern space, N append into the pattern space
  • p print the pattern space
  • s/REGEXP/REPLACEMENT/ replace the within pattern space.
    • \1 through \9 is available, with -r
      • \0 or & can be used without -r
    • s/^/REPLACEMENT/ appends in the beginning of a line.
    • \<PATTERN\> matches a word. same as \bPATTERN\b
    • \d does not match the number since they are strings.
  • w FILENAME write the pattern space to a file. W write one line at a time
  • y/SOURCE/DEST/ transliterate. See ((669f0999-d1e0-46f6-b0cf-0f57d2148067))
  • b LABEL branch to LABEL. If LABEL is omitted branch to the end of script.
  • t LABEL if substitution succeeds, branch to LABEL, T LABEL if no substitution succeeds.

2.3. Examples

  • sed -z 's/\ntime: /T/g' -i **/*.md
  • sed 's/^/# /' # comment out

3. awk

  • Al *A*ho, Peter *W*einberger, Brian *K*ernighan
  • The text file manipulator, powered by yacc
    • with a Scripting Language
    • The program is reimplemented under GNU project as gawk, powered by the reimplementation of yacc, bison.

3.1. Syntax

  • pattern { action }

3.1.1. Patterns

  • BEGIN, END special pattern that matches the start and end of a program
    • BEGIN can be used for initialization of the environment variables.
  • /regex/
  • || && ! ? : ,

3.1.2. Actions

  • print, printf
    • "TEXT"
    • It can be redirected to a file with > and >>
    • It can be piped to external commands with |,
    • $0 is the entire record. $N is the =N=th field.
  • ** Special Variables
    • ARGC the number of arguments
    • ARGV array of arguments
    • FS field separator regular expression
    • NR the current line number
    • OFS output field separator
    • FILENAME the current input file path

4. pandoc

4.1. Extensions

  • auto_identifiers: Add id field, even if it does not have the id field itself.

4.2. Filter

Define a function with a name of a element, that returns a new element.

  • pandoc.ELEMENT create a new element.

5. Gnuplot

6. Graphviz

7. GNU Lilypond

7.1. Control

7.1.1. Staff

  • \new Staff \with { CONFIG } { NOTES } creates a staff with the CONFIG options
  • \numericTimeSignature
  • \omit SYMBOL Clef
  • \override StaffSymbol.line-count = #N
  • \clef treble|alto|tenor|bass|...
  • \time FRACTION
  • OBJECT.stencil = ##f remove the symbol
  • \break: new line

7.1.2. Notes

  • Pitch: a - g low A to G. ' to raise an octave, , to lower an octave.
  • Length: 1 - 16 for Nth notes. . to add the dot.
  • Articulation: -^, ->, -., --, -_ after the name.
  • Accidental: is es after the name.
  • Beaming: [ <notes> ] after a note
  • Slur: ( <notes> )
  • Tie: ~, only the length needs to be specified.
  • Chord: replace the note name with < <notes> >
  • Tuplet: \tuplet FRACTION { NOTES }
    • e.g. \tuplet 3/2 { b4 4 4 }
  • Rest: r

7.1.3. Repeat

  • \repeat volta|segno|unfold|... N { NOTES }

7.1.4. Options

  • #(ly:set-option 'SYM #t) sets the -dSYM flag

7.1.5. Paper

7.1.5.1. Notation Font
  • Copy the font files into /usr/share/lilypond/current/fonts/otf
  • #(define fonts (set-global-fonts #:music "FONTNAME" #:brace "FONTNAME")
  • The default font is Feta from the Emmentaler set

7.2. CLI

7.2.1. lilypond

  • .ly file
  • --format=FORMAT change the main output format
  • --svg, --png additionally generate image files
  • -dSYM --define-defaults[SYM[=VAL]|no-SYM]=
    • preview to compile the first line, or in musical term, the first system.
    • crop to crop the image to the content
    • resolution
    • paper-size
    • backend: Either 'ps or 'svg
    • help

7.2.2. lilypond-book

  • .lytex file
  • Compile a ./tex.html file containing lilypond environment.

8. Chromium

  • @history, @tabs, @bookmarks are available in the search bar.
  • another search engine can be added in the Settings > Search Engine tab.

8.1. Google Search

  • "word" to enforce the inclusion of the word

8.2. Developer Tools

  • F12 to open
  • C-S-p to open command prompt.

9. File Manipulation

9.1. locate

It has been Unix tool for a while.

  • slocalte (secure locate), mlocate (merging locate), plocate (posting locate) are the implementations in order.
    • locate symlinks to the specific implementation.
  • updatedb command needs to run to build the databse at /var/lib/plocate/plocate.db.
  • plocate
    • It uses trigrams to index the database the index is inverted (from trigrams to files)

9.2. umask

Set the creation file mode for the current environment.

9.3. mknod [OPTION] NAME TYPE [MAJOR] [MINOR]

  • -m --mode=MODE permission mode
  • TYPE
    • b buffered block file
    • c u buffered/unbuffered character file
    • p FIFO
  • MAJOR MINOR
    • It must be specified for b c u
    • 0x 0X 0 == hexadecimal, octal, decimal

9.4. split

  • Divide a file into smaller ones.
  • -b: size, -n: division, -l line, --filter'gzip > $FILE.gz'=: post-action hook.

9.5. link

  • Creates hard link by directly interacting with the system.

9.6. entr

9.7. mkfifo

  • Creates a named pipe, which can be accessed from multiple sessions.

9.8. tee

  • Pipe input to both standard output and a file.

9.9. sync

  • Flushes cached data.

9.10. od

  • Octal dump. POSIX. Can be used for other bases.

9.11. dd

  • The options are given as variables format
  • bs ibs obs byte size
  • if of input, output files
  • count skip
  • conv convert while copying, status progress

9.12. shred

Zeroes out the file and then unlink

9.13. stdbuf

Controls the buffer of standard input and output.

9.14. truncate

Modifies file size.

9.15. lsof

List open files

  • Note that everything is a file in UNIX-like systems.
  • -i list all open network connections?

9.16. tar

tape archive

  • -c create. should be used with -f to set the archive filename
  • -x extract. should be used with -f to select the archive
    • It detects the compression algorithm automatically, but it can be set manually also.
    • -a --auto-compress detect the compression algorithm based on the archive suffix.
  • -f select the file or filename.
  • -v verbose
  • filter through -z gzip ,=-Z= compress, -j bzip2, -J xz, -I COMMAND use COMMAND.

9.17. zip

  • zip OPTIONS ARCHIVE FILES

9.18. cpio

copy in and out. It copies files between archives and directories.

  • -o --create
  • -i --extract
  • --file
  • --block-size=BLOCK-SIZE set the I/O block size
  • -D --directory=DIR
  • -c old portable archive format, -H --format=FORMAT use the FORMAT, the default format one is newc?
    • bin obsolete binary format
    • odc old POSIX.1 portable format
    • newc new SVR4 portable format
    • crc SVR4 format with checksum
    • tar
    • ustar
    • hpbin
    • hpodc

9.19. stow

9.20. cwebp and dwebp

  • Compress and decompress into and out of .webp
  • dwebp WEBP -o PNG/JPG
  • cwebp IMAGE -o WEBP -q [0-100]

9.21. qpdf

Transform PDF files. For example, encryption and decryption, or web optimization.

10. Text Manipulation

10.1. join

  • Relational SQL-like join on two text files.

10.2. fold

  • Wrap the text to a specified width.

10.3. pr

  • Paginate or columnate text for printing.

10.4. tac

  • Reverse strings.

10.5. shuf

  • Shuffle input.

10.6. sort

  • Sort input.

10.7. sed

  • See

10.8. uniq

  • Make each word from input unique.

10.9. tr

  • Translate(replace) single byte characters.

10.10. jp2a

  • Convert JPEG image to ASCII art.

10.11. comm

  • Perform set operations.
    • $ comm -12 A B
    • Flags
      • 1 : Remove elements only in the first set
      • 2 : Remove elements only in the second set
      • 3 : Remove elements in both the first and the second set

10.12. seq

  • seq <initial> <increment> <quantity>

10.13. jq

11. Process Manipulation

11.1. pstree

  • Show the entire process tree.

11.2. top

  • Monitor the processes
    • Keybindings
      • h help
      • < > change the sorted column
      • f change the properties to display
      • Z change the color scheme
      • A toggle multi-window view
      • V toggle forest (process trees)
        • v fold a branch
      • W save this preset
      • i hide idle processes
      • c toggle full commands
      • u, o filter processes
      • Toggle: <C-p> namespaces (cgroup: , ipc: , …), <C-n> environment variables, <C-u> supplementary groups (plugdev, wheel, harry), <C-k> full commands, <C-g> control groups (0::/user.slice/…).
      • q exit

11.3. nproc

  • Show the number of processors.

11.4. nice

  • Set a nice value to a program so that smaller valued ones finish faster on average.

11.5. fuser

  • Show which process is using a file or a device. With -n tcp <port> flag, it shows which process is using a tcp port.

11.6. timeout

  • timeout 2h <command>
    • Terminate the command based on time.

11.7. env

  • Set environment variables for the process

11.8. parallel

  • GNU Parallel
    • Execute multiple jobs of the command given in a special format, each with given arguments.
    • {} argument, {.} argument without file extension, …
    • ::: arguments, < arguments file

12. Programming

12.1. nm

list symbols from object files

12.2. Reverse Engineering

12.2.1. IDA

12.2.2. Ghidra

12.2.3. objdump

13. Audio Player

13.1. mpd

It is the media server that can host various musics. I feel like this is not a good option for personal music player.

13.2. mplayer

It is a CLI tool, that has separate frontend: smplayer, etc. These tools is not well-maintained.

13.3. mpv

Audio and video player based on MPlayer, mplayer2, and FFmpeg.

13.3.1. OSC Customization

14. Miscellaneous

14.1. neofetch

  • It is configurable

14.2. cowsay

  • Animals other than cow is also available.

14.3. fortune

  • Random quotes

14.4. figlet

  • ASCII text stylizer

14.5. lolcat

14.6. cava

  • Audio visualizer

14.7. pipes

  • Screensaver

14.9. minimodem

  • Generate modem signal based on input.

14.10. tldr

  • Short version of man page. It provides a quick snippets.

14.11. id

  • Show uid, gid and others of a given user (current user if unprovided).

14.12. fzf

  • Fuzzy find command.

14.13. btop

rocm-smi-lib is required to display GPU informations.

14.14. expr

Evaluate the expression. Each component of the expression must be separated by space, and the reserved characters must be escaped.

  • String manipulation with
    • STRING : REGEXP, match STRING REGEXP, length, index, substr STRING POS LEN
  • Arithmetic operation with
    • + - * / % > < = >=
    • n | m if n=0 return m; else return n, n & m if n=0 && m=0 return 0; else return n
    • Precedence is controlled by parenthesis. They need to be escaped in Bash.

14.15. date

  • Print datetime
    • -d STRING --date=STRING use this datetime.
    • +FMT format it
    • -u --utc --universal print or set UTC
    • --rfc-3339={date|hours|minutes|seconds|ns}
    • -I --iso-8601={date|hours|minutes|seconds|ns} use ISO format

14.16. bc

  • Arbitrary precision calculator
    • It might be using C library for math
    • The syntax is similar to except without semicolon and types.
      • The interactive environment evaluates the statement or expression and print them.
        • The second expression for the for loop is the predicate expression, that stops the loop if zero.
        • The first and third expression can be omitted.
      • The function is defined with the keyword define
      • Strings are always surrounded by double quote "
        • print LIST does the printing of a comma separated LIST.
      • The exit keyword is quit
    • No support for different base

Created: 2025-05-13 Tue 01:21