diff options
author | johannst <johannst@users.noreply.github.com> | 2021-01-14 21:30:05 +0000 |
---|---|---|
committer | johannst <johannst@users.noreply.github.com> | 2021-01-14 21:30:05 +0000 |
commit | 4ebfabeb0a29e58e6ac06435601b81ad11c564d9 (patch) | |
tree | 2afb3b9d483cd8cb406f66c8853b1fa2db73c420 /print.html | |
parent | f6fa901a0906fc6ba8c6d851060d646c3049f8ea (diff) | |
download | notes-4ebfabeb0a29e58e6ac06435601b81ad11c564d9.tar.gz notes-4ebfabeb0a29e58e6ac06435601b81ad11c564d9.zip |
deploy: 4de58de1947bf4fcfe16db8e9d2c9c920b1441d1
Diffstat (limited to 'print.html')
-rw-r--r-- | print.html | 156 |
1 files changed, 150 insertions, 6 deletions
@@ -83,7 +83,7 @@ <nav id="sidebar" class="sidebar" aria-label="Table of contents"> <div id="sidebar-scrollbox" class="sidebar-scrollbox"> - <ol class="chapter"><li class="expanded "><a href="tools/index.html"><strong aria-hidden="true">1.</strong> Tools</a></li><li><ol class="section"><li class="expanded "><a href="tools/zsh.html"><strong aria-hidden="true">1.1.</strong> zsh</a></li><li class="expanded "><a href="tools/bash.html"><strong aria-hidden="true">1.2.</strong> bash</a></li><li class="expanded "><a href="tools/fish.html"><strong aria-hidden="true">1.3.</strong> fish</a></li><li class="expanded "><a href="tools/tmux.html"><strong aria-hidden="true">1.4.</strong> tmux</a></li><li class="expanded "><a href="tools/git.html"><strong aria-hidden="true">1.5.</strong> git</a></li><li class="expanded "><a href="tools/awk.html"><strong aria-hidden="true">1.6.</strong> awk</a></li><li class="expanded "><a href="tools/emacs.html"><strong aria-hidden="true">1.7.</strong> emacs</a></li><li class="expanded "><a href="tools/gpg.html"><strong aria-hidden="true">1.8.</strong> gpg</a></li><li class="expanded "><a href="tools/gdb.html"><strong aria-hidden="true">1.9.</strong> gdb</a></li><li class="expanded "><a href="tools/radare2.html"><strong aria-hidden="true">1.10.</strong> radare2</a></li></ol></li><li class="expanded "><a href="monitor/index.html"><strong aria-hidden="true">2.</strong> Resource analysis & monitor</a></li><li><ol class="section"><li class="expanded "><a href="monitor/lsof.html"><strong aria-hidden="true">2.1.</strong> lsof</a></li><li class="expanded "><a href="monitor/pidstat.html"><strong aria-hidden="true">2.2.</strong> pidstat</a></li><li class="expanded "><a href="monitor/pgrep.html"><strong aria-hidden="true">2.3.</strong> pgrep</a></li><li class="expanded "><a href="monitor/pmap.html"><strong aria-hidden="true">2.4.</strong> pmap</a></li><li class="expanded "><a href="monitor/pstack.html"><strong aria-hidden="true">2.5.</strong> pstack</a></li></ol></li><li class="expanded "><a href="trace_profile/index.html"><strong aria-hidden="true">3.</strong> Trace and Profile</a></li><li><ol class="section"><li class="expanded "><a href="trace_profile/strace.html"><strong aria-hidden="true">3.1.</strong> strace</a></li><li class="expanded "><a href="trace_profile/ltrace.html"><strong aria-hidden="true">3.2.</strong> ltrace</a></li><li class="expanded "><a href="trace_profile/perf.html"><strong aria-hidden="true">3.3.</strong> perf</a></li><li class="expanded "><a href="trace_profile/oprofile.html"><strong aria-hidden="true">3.4.</strong> OProfile</a></li><li class="expanded "><a href="trace_profile/time.html"><strong aria-hidden="true">3.5.</strong> time</a></li></ol></li><li class="expanded "><a href="binary/index.html"><strong aria-hidden="true">4.</strong> Binary</a></li><li><ol class="section"><li class="expanded "><a href="binary/od.html"><strong aria-hidden="true">4.1.</strong> od</a></li><li class="expanded "><a href="binary/xxd.html"><strong aria-hidden="true">4.2.</strong> xxd</a></li><li class="expanded "><a href="binary/readelf.html"><strong aria-hidden="true">4.3.</strong> readelf</a></li><li class="expanded "><a href="binary/objdump.html"><strong aria-hidden="true">4.4.</strong> objdump</a></li><li class="expanded "><a href="binary/nm.html"><strong aria-hidden="true">4.5.</strong> nm</a></li></ol></li><li class="expanded "><a href="development/index.html"><strong aria-hidden="true">5.</strong> Development</a></li><li><ol class="section"><li class="expanded "><a href="development/c++filt.html"><strong aria-hidden="true">5.1.</strong> c++filt</a></li><li class="expanded "><a href="development/c++.html"><strong aria-hidden="true">5.2.</strong> c++</a></li><li class="expanded "><a href="development/glibc.html"><strong aria-hidden="true">5.3.</strong> glibc</a></li><li class="expanded "><a href="development/gcc.html"><strong aria-hidden="true">5.4.</strong> gcc</a></li><li class="expanded "><a href="development/make.html"><strong aria-hidden="true">5.5.</strong> make</a></li><li class="expanded "><a href="development/ld.so.html"><strong aria-hidden="true">5.6.</strong> ld.so</a></li></ol></li><li class="expanded "><a href="arch/index.html"><strong aria-hidden="true">6.</strong> Arch</a></li><li><ol class="section"><li class="expanded "><a href="arch/x86_64.html"><strong aria-hidden="true">6.1.</strong> x86_64</a></li><li class="expanded "><a href="arch/arm64.html"><strong aria-hidden="true">6.2.</strong> arm64</a></li></ol></li></ol> + <ol class="chapter"><li class="expanded "><a href="tools/index.html"><strong aria-hidden="true">1.</strong> Tools</a></li><li><ol class="section"><li class="expanded "><a href="tools/zsh.html"><strong aria-hidden="true">1.1.</strong> zsh</a></li><li class="expanded "><a href="tools/bash.html"><strong aria-hidden="true">1.2.</strong> bash</a></li><li class="expanded "><a href="tools/fish.html"><strong aria-hidden="true">1.3.</strong> fish</a></li><li class="expanded "><a href="tools/tmux.html"><strong aria-hidden="true">1.4.</strong> tmux</a></li><li class="expanded "><a href="tools/git.html"><strong aria-hidden="true">1.5.</strong> git</a></li><li class="expanded "><a href="tools/awk.html"><strong aria-hidden="true">1.6.</strong> awk</a></li><li class="expanded "><a href="tools/emacs.html"><strong aria-hidden="true">1.7.</strong> emacs</a></li><li class="expanded "><a href="tools/gpg.html"><strong aria-hidden="true">1.8.</strong> gpg</a></li><li class="expanded "><a href="tools/gdb.html"><strong aria-hidden="true">1.9.</strong> gdb</a></li><li class="expanded "><a href="tools/radare2.html"><strong aria-hidden="true">1.10.</strong> radare2</a></li></ol></li><li class="expanded "><a href="monitor/index.html"><strong aria-hidden="true">2.</strong> Resource analysis & monitor</a></li><li><ol class="section"><li class="expanded "><a href="monitor/lsof.html"><strong aria-hidden="true">2.1.</strong> lsof</a></li><li class="expanded "><a href="monitor/ss.html"><strong aria-hidden="true">2.2.</strong> ss</a></li><li class="expanded "><a href="monitor/pidstat.html"><strong aria-hidden="true">2.3.</strong> pidstat</a></li><li class="expanded "><a href="monitor/pgrep.html"><strong aria-hidden="true">2.4.</strong> pgrep</a></li><li class="expanded "><a href="monitor/pmap.html"><strong aria-hidden="true">2.5.</strong> pmap</a></li><li class="expanded "><a href="monitor/pstack.html"><strong aria-hidden="true">2.6.</strong> pstack</a></li></ol></li><li class="expanded "><a href="trace_profile/index.html"><strong aria-hidden="true">3.</strong> Trace and Profile</a></li><li><ol class="section"><li class="expanded "><a href="trace_profile/strace.html"><strong aria-hidden="true">3.1.</strong> strace</a></li><li class="expanded "><a href="trace_profile/ltrace.html"><strong aria-hidden="true">3.2.</strong> ltrace</a></li><li class="expanded "><a href="trace_profile/perf.html"><strong aria-hidden="true">3.3.</strong> perf</a></li><li class="expanded "><a href="trace_profile/oprofile.html"><strong aria-hidden="true">3.4.</strong> OProfile</a></li><li class="expanded "><a href="trace_profile/time.html"><strong aria-hidden="true">3.5.</strong> time</a></li></ol></li><li class="expanded "><a href="binary/index.html"><strong aria-hidden="true">4.</strong> Binary</a></li><li><ol class="section"><li class="expanded "><a href="binary/od.html"><strong aria-hidden="true">4.1.</strong> od</a></li><li class="expanded "><a href="binary/xxd.html"><strong aria-hidden="true">4.2.</strong> xxd</a></li><li class="expanded "><a href="binary/readelf.html"><strong aria-hidden="true">4.3.</strong> readelf</a></li><li class="expanded "><a href="binary/objdump.html"><strong aria-hidden="true">4.4.</strong> objdump</a></li><li class="expanded "><a href="binary/nm.html"><strong aria-hidden="true">4.5.</strong> nm</a></li></ol></li><li class="expanded "><a href="development/index.html"><strong aria-hidden="true">5.</strong> Development</a></li><li><ol class="section"><li class="expanded "><a href="development/c++filt.html"><strong aria-hidden="true">5.1.</strong> c++filt</a></li><li class="expanded "><a href="development/c++.html"><strong aria-hidden="true">5.2.</strong> c++</a></li><li class="expanded "><a href="development/glibc.html"><strong aria-hidden="true">5.3.</strong> glibc</a></li><li class="expanded "><a href="development/gcc.html"><strong aria-hidden="true">5.4.</strong> gcc</a></li><li class="expanded "><a href="development/make.html"><strong aria-hidden="true">5.5.</strong> make</a></li><li class="expanded "><a href="development/ld.so.html"><strong aria-hidden="true">5.6.</strong> ld.so</a></li></ol></li><li class="expanded "><a href="arch/index.html"><strong aria-hidden="true">6.</strong> Arch</a></li><li><ol class="section"><li class="expanded "><a href="arch/x86_64.html"><strong aria-hidden="true">6.1.</strong> x86_64</a></li><li class="expanded "><a href="arch/arm64.html"><strong aria-hidden="true">6.2.</strong> arm64</a></li></ol></li></ol> </div> <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div> </nav> @@ -178,6 +178,115 @@ bindkey -r in-str remove binding for `in-str` # zle -l list all functions for keybindings # man zshzle(1) STANDARD WIDGETS: get description of functions </code></pre> +<p>Access edit buffer in zle widget:</p> +<pre><code class="language-zsh">$BUFFER # Entire edit buffer content +$LBUFFER # Edit buffer content left to cursor +$RBUFFER # Edit buffer content right to cursor + +# create zle widget which adds text right of the cursor +function add-text() { + RBUFFER="some text $RBUFFER" +} +zle -N add-text + +bindkey "^p" add-text +</code></pre> +<h2><a class="header" href="#parameter" id="parameter">Parameter</a></h2> +<p>Default value:</p> +<pre><code class="language-zsh"># default value +echo ${foo:-defval} # defval +foo=bar +echo ${foo:-defval} # bar +</code></pre> +<p>Alternative value:</p> +<pre><code class="language-zsh">echo ${foo:+altval} # '' +foo=bar +echo ${foo:+altval} # altval +</code></pre> +<p>Check variable set, error if not set:</p> +<pre><code class="language-zsh">echo ${foo:?msg} # print `msg` and return errno `1` +foo=bar +echo ${foo:?msg} # bar +</code></pre> +<p>Sub-string <code>${var:offset:length}</code>:</p> +<pre><code class="language-zsh">foo=abcdef +echo ${foo:1:3} # bcd +</code></pre> +<p>Trim prefix <code>${var#prefix}</code>:</p> +<pre><code class="language-zsh">foo=bar.baz +echo ${foo#bar} # .baz +</code></pre> +<p>Trim suffix <code>${var%suffix}</code>:</p> +<pre><code class="language-zsh">foo=bar.baz +echo ${foo%.baz} # bar +</code></pre> +<p>Substitute pattern <code>${var/pattern/replace}</code>:</p> +<pre><code class="language-zsh">foo=aabbccbbdd +echo ${foo/bb/XX} # aaXXccbbdd +echo ${foo//bb/XX} # aaXXccXXdd +# replace prefix +echo ${foo/#bb/XX} # aabbccbbdd +echo ${foo/#aa/XX} # XXbbccbbdd +# replace suffix +echo ${foo/%bb/XX} # aabbccbbdd +echo ${foo/%dd/XX} # aabbccbbXX +</code></pre> +<blockquote> +<p>Note: <code>prefix</code>/<code>suffix</code>/<code>pattern</code> are expanded as pathnames.</p> +</blockquote> +<h2><a class="header" href="#variables" id="variables">Variables</a></h2> +<pre><code class="language-zsh"># Variable with local scope +local var=val + +# Read-only variable +readonly var=bal +</code></pre> +<p>Indexed arrays:</p> +<pre><code class="language-zsh">arr=(aa bb cc dd) +echo $arr[1] # aa +echo $arr[-1] # dd + +arr+=(ee) +echo $arr[-1] # ee + +echo $arr[1,3] # aa bb cc +</code></pre> +<p>Associative arrays:</p> +<pre><code class="language-zsh">typeset -A arr +arr[x]='aa' +arr[y]='bb' +echo $arr[x] # aa +</code></pre> +<p>Tied arrays:</p> +<pre><code class="language-zsh">typeset -T VEC vec=(1 2 3) '|' + +echo $vec # 1 2 3 +echo $VEC # 1|2|3 +</code></pre> +<p>Unique arrays (set):</p> +<pre><code>typeset -U vec=(1 2 3) + +echo $vec # 1 2 3 +vec+=(1 2 4) +echo $vec # 1 2 3 4 +</code></pre> +<h3><a class="header" href="#expansion-flags" id="expansion-flags">Expansion Flags</a></h3> +<p>Join array to string <code>j:sep:</code>:</p> +<pre><code class="language-zsh">foo=(1 2 3 4) +echo ${(j:-:)foo} # 1-2-3-4 +echo ${(j:\n:)foo} # join with new lines +</code></pre> +<p>Split string to array <code>s:sep</code>:</p> +<pre><code class="language-zsh">foo='1-2-3-4' +bar=(${(s:-:)foo}) # capture as array +echo $bar # 1 2 3 4 +echo $bar[2] # 2 +</code></pre> +<p>Upper/Lower case string:</p> +<pre><code class="language-zsh">foo=aaBB +echo ${(L)foo} # aabb +echo ${(U)foo} # AABB +</code></pre> <h2><a class="header" href="#completion" id="completion">Completion</a></h2> <h3><a class="header" href="#installation" id="installation">Installation</a></h3> <p>Completion functions are provided via files and need to be placed in a location @@ -186,7 +295,7 @@ covered by <code>$fpath</code>. By convention the completion files are names as <pre><code class="language-zsh">#compdef _foo foo function _foo() { - ... + ... } </code></pre> <p>Alternatively one can install a completion function explicitly by calling <code>compdef <FUNC> <CMD></code>.</p> @@ -282,10 +391,13 @@ function _foo() { # expand cartesian product {a,b}{c,d} </code></pre> -<h3><a class="header" href="#parameter" id="parameter">Parameter</a></h3> -<pre><code class="language-bash"># default param +<h3><a class="header" href="#parameter-1" id="parameter-1">Parameter</a></h3> +<pre><code class="language-bash"># default value bar=${foo:-some_val} # if $foo set, then bar=$foo else bar=some_val +# alternate value +bar=${foo:+bla $foo} # if $foo set, then bar="bla $foo" else bar="" + # check param set bar=${foo:?msg} # if $foo set, then bar=$foo else exit and print msg @@ -456,7 +568,7 @@ complete -F _foo foo <li><code>fish_default_key_bindings</code> to use default key bindings</li> <li><code>fish_vi_key_bindings</code> to use vi key bindings</li> </ul> -<h2><a class="header" href="#variables" id="variables">Variables</a></h2> +<h2><a class="header" href="#variables-1" id="variables-1">Variables</a></h2> <p>Available scopes</p> <ul> <li><code>local</code> variable local to a block</li> @@ -1386,6 +1498,7 @@ executed. To workaround that bug one can create a wrapper function which calls <h1><a class="header" href="#resource-analysis--monitor" id="resource-analysis--monitor">Resource analysis & monitor</a></h1> <ul> <li><a href="monitor/./lsof.html">lsof</a></li> +<li><a href="monitor/./ss.html">ss</a></li> <li><a href="monitor/./pidstat.html">pidstat</a></li> <li><a href="monitor/./pgrep.html">pgrep</a></li> <li><a href="monitor/./pmap.html">pmap</a></li> @@ -1434,9 +1547,40 @@ executed. To workaround that bug one can create a wrapper function which calls <p>Show open connections to <code>localhost</code> for <code>$USER</code>:</p> <pre><code class="language-markdown">lsof -a -u $USER -i @localhost </code></pre> +<h2><a class="header" href="#open-connection-to-specific-port" id="open-connection-to-specific-port">Open connection to specific port</a></h2> +<p>Show open connections to port <code>:1234</code> for <code>$USER</code>:</p> +<pre><code class="language-markdown">lsof -a -u $USER -i :1234 +</code></pre> <h2><a class="header" href="#ipv4-tcp-connections-in-established-state" id="ipv4-tcp-connections-in-established-state">IPv4 TCP connections in <code>ESTABLISHED</code> state</a></h2> <pre><code class="language-markdown">lsof -i 4TCP -s TCP:ESTABLISHED </code></pre> +<h1><a class="header" href="#ss8" id="ss8">ss(8)</a></h1> +<pre><code class="language-markdown">ss [option] [filter] +</code></pre> +<pre><code class="language-markdown">[option] + -p ..... Show process using socket + -l ..... Show sockets in listening state + -4/-6 .. Show IPv4/6 sockets + -x ..... Show unix sockets + -n ..... Show numeric ports (no resolve) + -O ..... Oneline output per socket +</code></pre> +<pre><code class="language-markdown">[filter] + dport/sport PORT .... Filter for destination/source port + dst/src ADDR ........ Filter for destination/source address + + and/or .............. Logic operator + ==/!= ............... Comparison operator + + (EXPR) .............. Group exprs +</code></pre> +<h1><a class="header" href="#examples-3" id="examples-3">Examples</a></h1> +<p>Show all tcp IPv4 sockets connecting to port <code>443</code>:</p> +<pre><code class="language-markdown">ss -4 'dport 443' +</code></pre> +<p>Show all tcp IPv4 sockets that don't connect to port <code>443</code> or connect to address <code>1.2.3.4</code>.</p> +<pre><code class="language-markdown">ss -4 'dport != 443 or dst 1.2.3.4' +</code></pre> <h1><a class="header" href="#pidstat1" id="pidstat1">pidstat(1)</a></h1> <pre><code class="language-markdown">pidstat [opt] [interval] [cont] -U [user] show username instead UID, optionally only show for user @@ -1504,7 +1648,7 @@ major_pagefault: Happens when the page needed is NOT in memory, the kernel trace=signal ............... trace signal related syscalls signal ..................... trace signals delivered to the process </code></pre> -<h1><a class="header" href="#examples-3" id="examples-3">Examples</a></h1> +<h1><a class="header" href="#examples-4" id="examples-4">Examples</a></h1> <p>Trace <code>open(2)</code> & <code>socket(2)</code> syscalls for a running process + child processes:</p> <pre><code class="language-markdown">strace -f -e trace=open,socket -p <pid> </code></pre> |