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
Ctrl-w o return to only One window
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
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