Table of Contents
- 1.
git- 1.1. Nomenclature
- 1.2. Subcommands
- 1.2.1.
clone - 1.2.2.
status - 1.2.3.
log - 1.2.4.
add - 1.2.5.
checkout - 1.2.6.
switch - 1.2.7.
commit - 1.2.8.
tag - 1.2.9.
branch - 1.2.10.
merge - 1.2.11.
fetch - 1.2.12.
pull - 1.2.13.
push - 1.2.14.
diff - 1.2.15.
reset - 1.2.16.
restore - 1.2.17.
revert - 1.2.18.
cherry-pick - 1.2.19.
rebase - 1.2.20.
stash - 1.2.21.
notes - 1.2.22.
worktree - 1.2.23.
submodule - 1.2.24.
bisect - 1.2.25.
instaweb - 1.2.26.
gc - 1.2.27.
blame - 1.2.28.
clean - 1.2.29.
maintenance
- 1.2.1.
- 1.3. Config
- 1.4. Hook
- 1.5. Credential
- 1.6. Under the Hood
- 1.7. Reference
- 2.
sed - 3.
awk - 4.
find - 5.
tmux - 6.
pandoc - 7. Gnuplot
- 8. Graphviz
- 9. GNU Lilypond
- 10. Chromium
- 11. Machine Control
- 12. File Manipulation
- 12.1.
which - 12.2.
whereis - 12.3.
whatis - 12.4.
apropos - 12.5.
locate - 12.6.
namei - 12.7.
umask - 12.8.
mknod [OPTION] NAME TYPE [MAJOR] [MINOR] - 12.9.
split - 12.10.
link - 12.11.
entr - 12.12.
mkfifo - 12.13.
tee - 12.14.
sync - 12.15.
od - 12.16.
dd - 12.17.
shred - 12.18.
stdbuf - 12.19.
truncate - 12.20.
lsof - 12.21.
tar - 12.22.
zip - 12.23.
cpio - 12.24.
stow - 12.25.
cwebpanddwebp - 12.26.
qpdf
- 12.1.
- 13. Text Manipulation
- 14. Process Manipulation
- 15. Programming
- 16. Audio Player
- 17. Miscellaneous
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^NmeansN=th parent when current commit is a merge of multiple commits, and =~NmeansNparents 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. -ato add the changes of the tracked files before commiting.-Cor-c=(edit the message) to use the existing commit object, probably there because of =git reset.--amendto replace the tip of the commit with a new one, effectively amending it.--no-editto keep the commit message.
--fixup,--squash: Marks the commit that it is to be squashed whengit 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 commitis required. - This enables creating a single commit with single parent.
- Change current working tree into the merged state, but not
committed. Therefore,
1.2.11. fetch
- Local branch is created when one
checkoutthe 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, Ordiff X Yfor diff betweenXandY. git diff <ref> [<ref>=HEAD] > <patchfile>stores the diff that can be applied bygit apply <patchfile>.
1.2.15. reset
- Uncommit or Unstage or hard reset.
--soft: only moves theHEAD,--hard: moves theHEADand reset the index and working tree.- The current
HEADgets stored toORIG_HEAD.
1.2.16. restore
- Restore files to a specific state. Add path at the end. It does
not affect the
indexunless--staged -s <tree>--source=<tree>: Specify commit, branch to restore from. Restore fromindexif 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: performgit commit --amendon 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 then. The latest stash is0. 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, likeHEAD,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
HEADof 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
~/.gitconfigor$XDG_CONFIG_HOME/git/config.- The latter is only used when
.gitconfigdoes not exist andgit/configdoes.
- The latter is only used when
- Local configuration is in
.git/configwithin the repository, it will shadow the global one. - Set configuration by
git config <options> <section>.<key> <value>.--globalfor the global configurations.
1.3.1. Structure
usernameemail
credentialhelper:storeandcacheis 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.5. Credential
1.6. Under the Hood
- https://youtu.be/reacnJArQXc?si=YdDC5LmtrIlhJZlh
git addcreates the blob objects for the changed files.git commitcreates the commit object, and the tree objects that are affected.
1.6.1. Objects
git cat-fileto 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
\nwithNULL, then^,$,\nmatches withNULL. This enables multi-line editing.
- Replace
-n--quiet--silent- Suppress the automatic printing of pattern space
-e SCRIPT- Each command in the script is separated by a newline.
\w\s.\ddoes not work. Use[0-9]\0,&for the entire match[abc]*\Uto upper,\Lto lower,\Ereturn to normal
-r-E--regexp-extended(abc)\1\NGrouping{N}+?repeat.
-f SCRIPTFILE
2.2. Commands
: LABEL#COMMENTADDRESS { COMMANDS }
2.2.1. Addresses
NUMBER,FIRST~STEPmatch line numbers$last line/REGEXT/\<C><REGEXP><C>line that matches the0,ADDRESSuntilADDRESSis foundADDRESS,+NNlines follwingADDRESSADDRESS,~NfromADDRESSto the line numberNor its multiples.
2.2.2. Zero-, One-Address Commands
=print the line numbera TEXTappend text into the next line.\<ret>is used to insert newlines.i TEXTinsert text into the previous line.qquitr FILENAMEappend text from the file.Rappend one line at a time from the file
2.2.3. Address Range Commands
c TEXTddelete pattern spacehcopy pattern space to hold space,Happend to hold spacegcopy hold space to pattern space,Gappend to pattern spacenread the next line into the pattern space,Nappend into the pattern spacepprint the pattern spaces/REGEXP/REPLACEMENT/replace the within pattern space.\1through\9is available, with-r\0or&can be used without-r
s/^/REPLACEMENT/appends in the beginning of a line.\<PATTERN\>matches a word. same as\bPATTERN\b\ddoes not match the number since they are strings.
w FILENAMEwrite the pattern space to a file.Wwrite one line at a timey/SOURCE/DEST/transliterate. See ((669f0999-d1e0-46f6-b0cf-0f57d2148067))b LABELbranch toLABEL. IfLABELis omitted branch to the end of script.t LABELif substitution succeeds, branch toLABEL,T LABELif no substitution succeeds.
2.3. Examples
sed -z 's/\ntime: /T/g' -i **/*.mdsed '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 ofyacc,bison.
3.1. Syntax
pattern { action }
3.1.1. Patterns
BEGIN,ENDspecial pattern that matches the start and end of a programBEGINcan 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
|, $0is the entire record.$Nis the =N=th field.
- ** Special Variables
ARGCthe number of argumentsARGVarray of argumentsFSfield separator regular expressionNRthe current line numberOFSoutput field separatorFILENAMEthe current input file path
4. find
find [STARTING_POINTS...] EXPRESSION
STARTING POINTis any directory or file- Multiple of them can be given and each one of them is traversed left to right.
- Current directory is assumed when not given.
EXPRESSION: any expression evaluates to either true or false.- Global: Always true
-maxdepth N: 0 means the starting point itself, and 1 means the child of it, and so on.-mindepth N: does not evaluate the expression when depth is less thanN
- Test: true if matched
-name PATTERN: match the file name using the shell file name pattern (*,?)-iname PATTERN: case insensitive match-path PATTERN: match the entire file path to the pattern.-regex PATTERN: use regular expression to match the file name.-type {b|c|f|s|...}match the file type-size N[k|M|G]size ofNkilo/mega/gigabytes.-amin N, accessedNminiutes ago,-atime NaccessedNdays ago+Nor-Ncan be used to indicate "more than" and "less than".-cmin N,-ctime N,-mmin N,-mtime Nfor changes and modified reprectively.
- Action: true on seccess.
-delete-exec COMMAND \;: run the command for the matched file.'{}'is replaced by the file name. Note that\and'are there to prevent the shell parsing it.-print: print the full file name-prune: stop descending further into this directory.-quit: exit.
- Operator
\( EXPR \): force precedence\! EXPR,-not EXPR(not POSIX): true ifEXPRis false.EXPR1 EXPR2,EXPR1 -a EXPR2,EXPR1 -and EXPR2(not POSIX)EXPR1 -o EXPR2,EXPR1 -or EXPR2(not POSIX): it has lower precedence than AND.EXPR1 , EXPR2:EXPR1is evaluated and discared. The value ofEXPR2is the value of the list.
- Global: Always true
-printis implicit after the whole expression, unless-delete,-exec,-print, … is used.
5. tmux
Prefix C-b
:enter tmux command
5.1. Windows
c(new-window) create new window'select by window index0, …,9select windown,pnext and previous window&(kill-window) kill current window
5.2. Panes
"split pane horizontally%split pane vertically<arrow>change paneonext pane in current window;previously active paneC-orotate forwardM-1, …,M-5preset layoutSPCnext preset layoutC-<arrow>resize by one cell,M-<arrow>resize by five cells{,}swap current pane with previous or next panemmark current paneztoggle maximization of current panex(kill-pane) kill current pane
5.3. Sessions
d(detach-client) detach
5.4. Configuration
In the order of precedence:
~/.tmux.conf$XDG_CONFIG_HOME/tmux/tmux.conf~/.config/tmux/tmux.conf/etc/tmux.conf
Written with tmux commands
6. pandoc
6.1. Extensions
auto_identifiers: Add id field, even if it does not have the id field itself.
6.2. Filter
Define a function with a name of a element, that returns a new element.
pandoc.ELEMENTcreate a new element.
7. Gnuplot
8. Graphviz
9. GNU Lilypond
- Music Engraving Tool by GNU project
- It was originally part of the ./tex.html
- LilyPond — Notation Reference
- LilyPond — Learning Manual
- LilyPond — Application Usage
9.1. Control
9.1.1. Staff
\new Staff \with { CONFIG } { NOTES }creates a staff with the CONFIG options\numericTimeSignature\omit SYMBOLClef\override StaffSymbol.line-count = #N\clef treble|alto|tenor|bass|...\time FRACTIONOBJECT.stencil = ##fremove the symbol\break: new line
9.1.2. Notes
- Pitch:
a-glow A to G.'to raise an octave,,to lower an octave. - Length:
1-16for Nth notes..to add the dot. - Articulation:
-^,->,-.,--,-_after the name. - Accidental:
isesafter 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 }
- e.g.
- Rest:
r
9.1.3. Repeat
\repeat volta|segno|unfold|... N { NOTES }
9.1.4. Options
#(ly:set-option 'SYM #t)sets the-dSYMflag
9.1.5. Paper
9.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
Fetafrom theEmmentalerset
9.2. CLI
9.2.1. lilypond
.lyfile--format=FORMATchange the main output format--svg,--pngadditionally generate image files-dSYM--define-defaults[SYM[=VAL]|no-SYM]=previewto compile the first line, or in musical term, the first system.cropto crop the image to the contentresolutionpaper-sizebackend: Either'psor'svghelp
9.2.2. lilypond-book
.lytexfile- Compile a ./tex.html file containing
lilypondenvironment.
10. Chromium
@history,@tabs,@bookmarksare available in the search bar.- another search engine can be added in the Settings > Search Engine tab.
10.1. Google Search
"word"to enforce the inclusion of the word
10.2. Developer Tools
F12to openC-S-pto open command prompt.
11. Machine Control
11.1. systemctl soft-reboot
Keep the kernel, reboot the user space.
12. File Manipulation
12.1. which
Probe what program or alias the following will execute.
12.2. whereis
Show the location of binary, source code (if available), and manpage.
12.3. whatis
Show the manpage entry.
12.4. apropos
Fuzzy-find through the manpages.
12.5. locate
It has been Unix tool for a while.
slocalte(secure locate),mlocate(merging locate),plocate(posting locate) are the implementations in order.locatesymlinks to the specific implementation.
updatedbcommand 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)
12.6. namei
list the files with their type.
12.7. umask
Set the creation file mode for the current environment.
12.8. mknod [OPTION] NAME TYPE [MAJOR] [MINOR]
-m--mode=MODEpermission modeTYPEbbuffered block filecubuffered/unbuffered character filepFIFO
MAJOR MINOR- It must be specified for
bcu 0x0X0== hexadecimal, octal, decimal
- It must be specified for
12.9. split
- Divide a file into smaller ones.
-b: size,-n: division,-lline,--filter'gzip > $FILE.gz'=: post-action hook.
12.10. link
- Creates hard link by directly interacting with the system.
12.11. entr
- 7 Essential Command Line Tools 2022 - YouTube
- Enter.
- Automatically run commands when given file is saved.
12.12. mkfifo
- Creates a named pipe, which can be accessed from multiple sessions.
12.13. tee
- Pipe input to both standard output and a file.
12.14. sync
- Flushes cached data.
12.15. od
- Octal dump. POSIX. Can be used for other bases.
12.16. dd
- The options are given as variables format
bsibsobsbyte sizeifofinput, output filescountskipconvconvert while copying,statusprogress
12.17. shred
Zeroes out the file and then unlink
12.18. stdbuf
Controls the buffer of standard input and output.
12.19. truncate
Modifies file size.
12.20. lsof
List open files
- Note that everything is a file in UNIX-like systems.
-ilist all open network connections?
12.21. tar
tape archive
-ccreate. should be used with-fto set the archive filename-xextract. should be used with-fto select the archive- It detects the compression algorithm automatically, but it can be set manually also.
-a--auto-compressdetect the compression algorithm based on the archive suffix.
-fselect the file or filename.-vverbose- filter through
-zgzip,=-Z=compress,-jbzip2,-Jxz,-I COMMANDuseCOMMAND.
12.22. zip
zip OPTIONS ARCHIVE FILES
12.23. cpio
copy in and out. It copies files between archives and directories.
-o--create-i--extract--file--block-size=BLOCK-SIZEset the I/O block size-D--directory=DIR-cold portable archive format,-H--format=FORMATuse theFORMAT, the default format one isnewc?binobsolete binary formatodcold POSIX.1 portable formatnewcnew SVR4 portable formatcrcSVR4 format with checksumtarustarhpbinhpodc
12.24. stow
- NEVER lose dotfiles again with GNU Stow - YouTube
- put dotfiles in one directory, for ease of management and migration.
12.25. cwebp and dwebp
- Compress and decompress into and out of
.webp dwebp WEBP -o PNG/JPGcwebp IMAGE -o WEBP -q [0-100]
12.26. qpdf
Transform PDF files. For example, encryption and decryption, or web optimization.
13. Text Manipulation
13.1. join
- Relational SQL-like join on two text files.
13.2. fold
- Wrap the text to a specified width.
13.3. pr
- Paginate or columnate text for printing.
13.4. tac
- Reverse strings.
13.5. shuf
- Shuffle input.
13.6. sort
- Sort input.
13.7. sed
- See
13.8. uniq
- Make each word from input unique.
13.9. tr
- Translate(replace) single byte characters.
13.10. jp2a
- Convert JPEG image to ASCII art.
13.11. comm
- Perform set operations.
$ comm -12 A B- Flags
1: Remove elements only in the first set2: Remove elements only in the second set3: Remove elements in both the first and the second set
13.12. seq
seq <initial> <increment> <quantity>
13.13. jq
- jq: A Practical Guide - YouTube
- JSON Queryer
14. Process Manipulation
14.1. pstree
- Show the entire process tree.
14.2. top
- Monitor the processes
- Keybindings
hhelp<>change the sorted columnfchange the properties to displayZchange the color schemeAtoggle multi-window viewVtoggle forest (process trees)vfold a branch
Wsave this presetihide idle processesctoggle full commandsu,ofilter 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/…). qexit
- Keybindings
14.3. nproc
- Show the number of processors.
14.4. nice
- Set a
nicevalue to a program so that smaller valued ones finish faster on average.
14.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.
14.6. timeout
timeout 2h <command>- Terminate the command based on time.
14.7. env
- Set environment variables for the process
14.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
14.9. yes
Print y repeatedly, so that it can be piped to another program.
14.10. printenv
Print the current environment variables.
15. Programming
15.1. nm
list symbols from object files
15.2. Reverse Engineering
15.2.1. IDA
15.2.2. Ghidra
15.2.3. objdump
16. Audio Player
16.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.
16.2. mplayer
It is a CLI tool, that has separate frontend: smplayer, etc.
These tools is not well-maintained.
16.3. mpv
Audio and video player based on MPlayer, mplayer2, and FFmpeg.
mpv-mpris./linux.html#org49f15ec support
16.3.1. OSC Customization
- On Screen Controller (OSC) is the set of GUI elements
- It can be customized with ./lua.html.
- I found this: GitHub - maoiscat/mpv-osc-modern: Another mpv osc script
17. Miscellaneous
17.1. neofetch
- It is configurable
17.2. cowsay
- Animals other than cow is also available.
17.3. fortune
- Random quotes
17.4. figlet
- ASCII text stylizer
17.5. lolcat
17.6. cava
- Audio visualizer
17.7. pipes
- Screensaver
17.8. wtf
17.9. minimodem
- Generate modem signal based on input.
17.10. tldr
- Short version of man page. It provides a quick snippets.
17.11. id
- Show
uid,gidand others of a given user (current user if unprovided).
17.12. fzf
- Fuzzy find command.
17.13. btop
rocm-smi-lib is required to display GPU informations.
17.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 | mif n=0 return m; else return n,n & mif n=0 && m=0 return 0; else return n- Precedence is controlled by parenthesis. They need to be escaped in Bash.
17.15. date
- Print datetime
-d STRING--date=STRINGuse this datetime.+FMTformat it-u--utc--universalprint or set UTC--rfc-3339={date|hours|minutes|seconds|ns}-I--iso-8601={date|hours|minutes|seconds|ns}use ISO format
17.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
forloop is the predicate expression, that stops the loop if zero. - The first and third expression can be omitted.
- The second expression for the
- The function is defined with the keyword
define - Strings are always surrounded by double quote
"print LISTdoes the printing of a comma separatedLIST.
- The exit keyword is
quit
- The interactive environment evaluates the statement or
expression and print them.
- No support for different base