Skip to content

Nix

files

fd  = file descriptor
fd 0    = stdin
fd 1    = stdout
fd 2    = stderr

redirect stdout to file:                command > x
                same as:                command 1> x
redirect stderr to file:                command 2> x
redirect stdout to x, stderr to y:      command 1> x 2> y
redirect stderr and   stdout to x:      command &> x
                          same as:      command 2>&1 > x

find

find . -name "pattern"          # find any objects with a name pattern
find . -name "pattern" -type f  # find any files with a name pattern
find . -mtime -1                # find any objects modified within the past day
find . -name "regex_abc" -type f -exec grep -nH regex_xyz {} \;
        # find any file with regex_abc whose contents contain regex_xyz

journalctl

journalctl -u (name) -n (last-n-lines) -S (since) -U (until)

-u (name)          unit name
-f                 follow
-n                 show last 10 entries
-S --since (datetime)
-U --until (datetime)

Datetime options include:
"2022-01-01 09:00:00"
"2022-01-01"
09:00
today
yesterday
"1 hour ago"
"10 minutes ago"

vi

finding things

f{c}         find the next instance of character 
F{c}         find the previous instance of character
/{pattern}   find the next instance of pattern
?{pattern}   find the previous instance of pattern
*            find the next instance of word under cursor
n            after find, go to the next instance
N            after find, go to the previous instance

replacing things

:s/old/new/g     replace old with new only on current line
:n,m s/old/new/g replace old with new only on lines n to m
:%s/old/new/g    replace old with new globally
                 %s is special symbol in ed for all rows in file

vital ops

u                undo last sequence of change

buffers

:e               select a file to edit from local folder
:ls              list loaded files in buffers
:bn              buffer next
:bp              buffer previous
:bdelete n       buffer delete n

windows

Ctrl-w s         split horizontal window
Ctrl-w v         split vertical window
Ctrl-w h/j/k/l   window jump- up, down, left, right
Ctrl-w Ctrl-w    window cycle
Ctrl-w c         close window
Ctrl-w =         resize window sizes all equal

visual blocks

v                select block by character
V                select block by line
Ctrl-v           select block

moving around

$                jump to end of line
dw               delete word forward
daw              delete a word
dd               delete line

reformatting

:set textwidth=65
v
gq

bookmarks

m(c)             mark position with character c
'(c)             jump back to position c

macros

q(r)             record a macro to register r
@(r)             playback macro r
n@(r)            playback macro r n number of times

markdown

To turn off markdown marking _ as an error:
add these lines into:
/.vim/after/syntax/markdown.vim

syn match markdownError "\w\@<=\w\@="
syn match markdownIgnore "\$x_i\$"

ssh

ssh-keygen
ssh-add -l 
ssh-add (file containing private key)
ssh -T git@bitbucket.org

tmux

ctrl-t c        create new window
ctrl-t w        list windows
ctrl-t p        previous window
ctrl-t n        next window
ctrl-t 0..9     jump to window by number
ctrl-t spacebar toggle pane layout
ctrl-t v        split pane vertically
ctrl-t s        split pane horizontally
ctrl-t [        enter copy mode, can scroll up down
ctrl-t pgup     enter copy mode, page up

file types

xdg-mime query default application/pdf
xdg-mime default xpdf.desktop application/pdf