<p>Bash Oneliner learning station. This blog will focus on bash commands for parsing biological data, which are tsv files(tab-separated values); some of the commands are for Ubuntu system maintaining. I apologize that there won't be any citation of the code, but they are probably from dear Google and Stackoverflow. Not all the code here are oneliner (if the ';' counts..). English and bash are not my first language, so... correct me anytime, tks!!</p>
<hr>
<spanclass="credits left">Project maintained by <ahref="https://github.com/onceupon">onceupon</a></span>
<spanclass="credits right">Hosted on GitHub Pages — Theme by <ahref="https://twitter.com/michigangraham">mattgraham</a></span>
</div>
<h2>
<aid="handy-bash-oneliner-commands-for-tsv-file-editing"class="anchor"href="#handy-bash-oneliner-commands-for-tsv-file-editing"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>Handy Bash oneliner commands for tsv file editing</h2>
<aid="extract-text-bewteen-words-eg-w1w2"class="anchor"href="#extract-text-bewteen-words-eg-w1w2"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>extract text bewteen words (e.g. w1,w2)</h5>
<aid="grep-lines-without-word-eg-bbo"class="anchor"href="#grep-lines-without-word-eg-bbo"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>grep lines without word (e.g. bbo)</h5>
<aid="count-occurrence-eg-three-times-a-line-count-three-times"class="anchor"href="#count-occurrence-eg-three-times-a-line-count-three-times"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>count occurrence (e.g. three times a line count three times)</h5>
<aid="color-the-match-eg-bbo"class="anchor"href="#color-the-match-eg-bbo"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>COLOR the match (e.g. bbo)!</h5>
<aid="grep-search-all-files-in-a-directoryeg-bbo"class="anchor"href="#grep-search-all-files-in-a-directoryeg-bbo"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>grep search all files in a directory(e.g. bbo)</h5>
<aid="search-all-files-in-directory-only-output-file-names-with-matcheseg-bbo"class="anchor"href="#search-all-files-in-directory-only-output-file-names-with-matcheseg-bbo"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>search all files in directory, only output file names with matches(e.g. bbo)</h5>
<aid="grep-or-eg-a-or-b-or-c-or-d"class="anchor"href="#grep-or-eg-a-or-b-or-c-or-d"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>grep OR (e.g. A or B or C or D)</h5>
<pre><code>grep 'A\|B\|C\|D'
</code></pre>
<h5>
<aid="grep-and-eg-a-and-b"class="anchor"href="#grep-and-eg-a-and-b"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>grep AND (e.g. A and B)</h5>
<aid="grep-all-content-of-a-filea-from-fileb"class="anchor"href="#grep-all-content-of-a-filea-from-fileb"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>grep all content of a fileA from fileB</h5>
<p>[<ahref="#handy-bash-oneliner-commands-for-tsv-file-editing">back to top</a>]</p>
<h5>
<aid="remove-lines-with-word-eg-bbo"class="anchor"href="#remove-lines-with-word-eg-bbo"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>remove lines with word (e.g. bbo)</h5>
<aid="delete-last-line"class="anchor"href="#delete-last-line"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>delete last line</h5>
<aid="add-n-every-nth-character-eg-every-4th-character"class="anchor"href="#add-n-every-nth-character-eg-every-4th-character"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>add \n every nth character (e.g. every 4th character)</h5>
<aid="substitution-eg-replace-a-by-b"class="anchor"href="#substitution-eg-replace-a-by-b"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>substitution (e.g. replace A by B)</h5>
<aid="print-every-nth-lines"class="anchor"href="#print-every-nth-lines"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>print every nth lines</h5>
<aid="print-every-third-line-including-the-first-line"class="anchor"href="#print-every-third-line-including-the-first-line"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>print every third line including the first line</h5>
<aid="remove-leading-whitespace-and-tabs"class="anchor"href="#remove-leading-whitespace-and-tabs"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>remove leading whitespace and tabs</h5>
<aid="remove-only-leading-whitespace"class="anchor"href="#remove-only-leading-whitespace"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>remove only leading whitespace</h5>
<aid="add-a-column-to-the-end"class="anchor"href="#add-a-column-to-the-end"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>add a column to the end</h5>
e.g. add the filename to every last column of the file</p>
<divclass="highlight highlight-source-shell"><pre><spanclass="pl-k">for</span><spanclass="pl-smi">i</span><spanclass="pl-k">in</span><spanclass="pl-s"><spanclass="pl-pds">$(</span>ls<spanclass="pl-pds">)</span></span><spanclass="pl-k">;</span><spanclass="pl-k">do</span> sed -i <spanclass="pl-s"><spanclass="pl-pds">"</span>s/$/\t<spanclass="pl-smi">$i</span>/<spanclass="pl-pds">"</span></span><spanclass="pl-smi">$i</span><spanclass="pl-k">;</span><spanclass="pl-k">done</span></pre></div>
<aid="print-a-number-of-lines-eg-line-10th-to-line-33-rd"class="anchor"href="#print-a-number-of-lines-eg-line-10th-to-line-33-rd"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>print a number of lines (e.g. line 10th to line 33 rd)</h5>
<p>[<ahref="#handy-bash-oneliner-commands-for-tsv-file-editing">back to top</a>]</p>
<h5>
<aid="set-tab-as-field-separator"class="anchor"href="#set-tab-as-field-separator"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>set tab as field separator</h5>
<aid="output-as-tab-separated-also-as-field-separator"class="anchor"href="#output-as-tab-separated-also-as-field-separator"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>output as tab separated (also as field separator)</h5>
<aid="print-number-of-characters-on-each-line"class="anchor"href="#print-number-of-characters-on-each-line"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>print number of characters on each line</h5>
<aid="find-number-of-columns"class="anchor"href="#find-number-of-columns"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>find number of columns</h5>
<aid="check-if-there-is-a-comma-in-a-column-eg-column-1"class="anchor"href="#check-if-there-is-a-comma-in-a-column-eg-column-1"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>check if there is a comma in a column (e.g. column $1)</h5>
<aid="split-and-do-for-loop"class="anchor"href="#split-and-do-for-loop"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>split and do for loop</h5>
<divclass="highlight highlight-source-shell"><pre>awk <spanclass="pl-s"><spanclass="pl-pds">'</span>{split($2, a,",");for (i in a) print $1"\t"a[i]} filename </span></pre></div>
<h5>
<aid="print-all-lines-before-nth-occurence-of-a-string-eg-stop-print-lines-when-bbo-appears-7-times"class="anchor"href="#print-all-lines-before-nth-occurence-of-a-string-eg-stop-print-lines-when-bbo-appears-7-times"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>print all lines before nth occurence of a string (e.g stop print lines when bbo appears 7 times)</h5>
<aid="add-string-to-the-beginning-of-a-column-eg-add-chr-to-column-3"class="anchor"href="#add-string-to-the-beginning-of-a-column-eg-add-chr-to-column-3"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>add string to the beginning of a column (e.g add "chr" to column $3)</h5>
<aid="usage-and-meaning-of-nr-and-fnr"class="anchor"href="#usage-and-meaning-of-nr-and-fnr"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>usage and meaning of NR and FNR</h5>
<aid="round-all-numbers-of-file-eg-2-significant-figure"class="anchor"href="#round-all-numbers-of-file-eg-2-significant-figure"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>round all numbers of file (e.g. 2 significant figure)</h5>
<aid="give-numberindex-to-every-row"class="anchor"href="#give-numberindex-to-every-row"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>give number/index to every row</h5>
<aid="prompt-before-execution"class="anchor"href="#prompt-before-execution"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>prompt before execution</h5>
<divclass="highlight highlight-source-shell"><pre><spanclass="pl-c1">echo</span> a b c <spanclass="pl-k">|</span>xargs -p -n 3</pre></div>
<h5>
<aid="print-command-along-with-output"class="anchor"href="#print-command-along-with-output"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>print command along with output</h5>
<aid="with-find-and-rm"class="anchor"href="#with-find-and-rm"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>with find and rm</h5>
<aid="move-files-to-folder"class="anchor"href="#move-files-to-folder"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>move files to folder</h5>
<aid="move-first-100th-files-to-a-directory-eg-d1"class="anchor"href="#move-first-100th-files-to-a-directory-eg-d1"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>move first 100th files to a directory (e.g. d1)</h5>
<aid="copy-all-files-from-a-to-b"class="anchor"href="#copy-all-files-from-a-to-b"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>copy all files from A to B</h5>
<divclass="highlight highlight-source-shell"><pre>ls <spanclass="pl-k">|</span>xargs -n1 -I file sed -i <spanclass="pl-s"><spanclass="pl-pds">'</span>/^Pos/d<spanclass="pl-pds">'</span></span> filename</pre></div>
<h5>
<aid="add-the-file-name-to-the-first-line-of-file"class="anchor"href="#add-the-file-name-to-the-first-line-of-file"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>add the file name to the first line of file</h5>
<aid="count-all-files"class="anchor"href="#count-all-files"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>count all files</h5>
<aid="to-filter-txt-to-a-single-line"class="anchor"href="#to-filter-txt-to-a-single-line"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>to filter txt to a single line</h5>
<aid="count-files-within-directories"class="anchor"href="#count-files-within-directories"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>count files within directories</h5>
<aid="count-lines-in-all-file-also-count-total-lines"class="anchor"href="#count-lines-in-all-file-also-count-total-lines"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>count lines in all file, also count total lines</h5>
<p>[<ahref="#handy-bash-oneliner-commands-for-tsv-file-editing">back to top</a>]</p>
<h5>
<aid="list-all-sub-directoryfile-in-the-current-directory"class="anchor"href="#list-all-sub-directoryfile-in-the-current-directory"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>list all sub directory/file in the current directory</h5>
<aid="list-all-files-under-the-current-directory"class="anchor"href="#list-all-files-under-the-current-directory"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>list all files under the current directory</h5>
<aid="list-all-directories-under-the-current-directory"class="anchor"href="#list-all-directories-under-the-current-directory"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>list all directories under the current directory</h5>
<aid="edit-all-files-under-current-directory-eg-replace-www-with-ww"class="anchor"href="#edit-all-files-under-current-directory-eg-replace-www-with-ww"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>edit all files under current directory (e.g. replace 'www' with 'ww')</h5>
<divclass="highlight highlight-source-shell"><pre>find <spanclass="pl-c1">.</span> name <spanclass="pl-s"><spanclass="pl-pds">'</span>*.php<spanclass="pl-pds">'</span></span> -exec sed -i <spanclass="pl-s"><spanclass="pl-pds">'</span>s/www/w/g<spanclass="pl-pds">'</span></span> {} <spanclass="pl-cce">\;</span></pre></div>
<aid="find-and-output-only-filename-eg-mso"class="anchor"href="#find-and-output-only-filename-eg-mso"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>find and output only filename (e.g. "mso")</h5>
<aid="find-and-delete-file-with-size-less-than-eg-74-byte"class="anchor"href="#find-and-delete-file-with-size-less-than-eg-74-byte"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>find and delete file with size less than (e.g. 74 byte)</h5>
<p>[<ahref="#handy-bash-oneliner-commands-for-tsv-file-editing">back to top</a>]</p>
<h5>
<aid="while-loop-column-subtraction-of-a-file-eg-a-3-columns-file"class="anchor"href="#while-loop-column-subtraction-of-a-file-eg-a-3-columns-file"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>while loop, column subtraction of a file (e.g. a 3 columns file)</h5>
<divclass="highlight highlight-source-shell"><pre><spanclass="pl-k">while</span><spanclass="pl-c1">read</span> a b c<spanclass="pl-k">;</span><spanclass="pl-k">do</span><spanclass="pl-c1">echo</span><spanclass="pl-s"><spanclass="pl-pds">$((</span><spanclass="pl-smi">$c</span><spanclass="pl-k">-</span><spanclass="pl-smi">$b</span><spanclass="pl-pds">))</span></span><spanclass="pl-k">;</span><spanclass="pl-k">done</span><spanclass="pl-k"><</span><spanclass="pl-s"><spanclass="pl-pds"><(</span>head filename<spanclass="pl-pds">)</span></span></pre></div>
<p>//there is a space between the two '<'s</p>
<h5>
<aid="while-loop-sum-up-column-subtraction"class="anchor"href="#while-loop-sum-up-column-subtraction"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>while loop, sum up column subtraction</h5>
<divclass="highlight highlight-source-shell"><pre>i=0<spanclass="pl-k">;</span><spanclass="pl-k">while</span><spanclass="pl-c1">read</span> a b c<spanclass="pl-k">;</span><spanclass="pl-k">do</span><spanclass="pl-s"><spanclass="pl-pds">((</span>i<spanclass="pl-k">+=</span><spanclass="pl-smi">$c</span><spanclass="pl-k">-</span><spanclass="pl-smi">$b</span><spanclass="pl-pds">))</span></span><spanclass="pl-k">;</span><spanclass="pl-c1">echo</span><spanclass="pl-smi">$i</span><spanclass="pl-k">;</span><spanclass="pl-k">done</span><spanclass="pl-k"><</span><spanclass="pl-s"><spanclass="pl-pds"><(</span>head filename<spanclass="pl-pds">)</span></span></pre></div>
<p>[<ahref="#handy-bash-oneliner-commands-for-tsv-file-editing">back to top</a>]</p>
<h5>
<aid="download-all-from-a-page"class="anchor"href="#download-all-from-a-page"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>download all from a page</h5>
<p>[<ahref="#handy-bash-oneliner-commands-for-tsv-file-editing">back to top</a>]</p>
<h5>
<aid="random-pick-100-lines-from-a-file"class="anchor"href="#random-pick-100-lines-from-a-file"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>random pick 100 lines from a file</h5>
<aid="random-order-lucky-draw"class="anchor"href="#random-order-lucky-draw"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>random order (lucky draw)</h5>
<divclass="highlight highlight-source-shell"><pre><spanclass="pl-k">for</span><spanclass="pl-smi">i</span><spanclass="pl-k">in</span> a b c d e<spanclass="pl-k">;</span><spanclass="pl-k">do</span><spanclass="pl-c1">echo</span><spanclass="pl-smi">$i</span><spanclass="pl-k">;</span><spanclass="pl-k">done</span><spanclass="pl-k">|</span> shuf</pre></div>
<h5>
<aid="echo-series-of-random-numbers-between-a-range-eg-generate-15-random-numbers-from-0-10"class="anchor"href="#echo-series-of-random-numbers-between-a-range-eg-generate-15-random-numbers-from-0-10"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>echo series of random numbers between a range (e.g. generate 15 random numbers from 0-10)</h5>
<aid="echo-a-random-number"class="anchor"href="#echo-a-random-number"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>echo a random number</h5>
<aid="random-from-0-9"class="anchor"href="#random-from-0-9"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>random from 0-9</h5>
<aid="random-from-1-10"class="anchor"href="#random-from-1-10"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>random from 1-10</h5>
<divclass="highlight highlight-source-shell"><pre><spanclass="pl-c1">echo</span><spanclass="pl-s"><spanclass="pl-pds">'</span>heres the content<spanclass="pl-pds">'</span></span><spanclass="pl-k">|</span> mail -A <spanclass="pl-s"><spanclass="pl-pds">'</span>file.txt<spanclass="pl-pds">'</span></span> -s <spanclass="pl-s"><spanclass="pl-pds">'</span>mail.subject<spanclass="pl-pds">'</span></span> me@gmail.com</pre></div>
<p>//use -a flag to set send from (-a "From: <ahref="mailto:some@mail.tld">some@mail.tld</a>")</p>
<h5>
<aid="xls-to-csv"class="anchor"href="#xls-to-csv"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>.xls to csv</h5>
<aid="get-last-historyrecord-filename"class="anchor"href="#get-last-historyrecord-filename"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>get last history/record filename</h5>
<aid="send-data-to-last-edited-file"class="anchor"href="#send-data-to-last-edited-file"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>send data to last edited file</h5>
<aid="run-history-number-eg-53"class="anchor"href="#run-history-number-eg-53"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>run history number (e.g. 53)</h5>
<aid="run-last-command"class="anchor"href="#run-last-command"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>run last command</h5>
<aid="run-last-command-that-began-with-eg-cat-filename"class="anchor"href="#run-last-command-that-began-with-eg-cat-filename"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>run last command that began with (e.g. cat filename)</h5>
<aid="download-file-if-necessary"class="anchor"href="#download-file-if-necessary"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>Download file if necessary</h5>
<spanclass="pl-c1">echo</span><spanclass="pl-s"><spanclass="pl-pds">"</span>downloading test data...<spanclass="pl-pds">"</span></span>
wget <spanclass="pl-smi">$url</span>
<spanclass="pl-k">fi</span></pre></div>
<h5>
<aid="wget-to-a-filename-when-a-long-name"class="anchor"href="#wget-to-a-filename-when-a-long-name"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>wget to a filename (when a long name)</h5>
<aid="wget-files-to-a-folder"class="anchor"href="#wget-files-to-a-folder"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>wget files to a folder</h5>
<aid="delete-current-bash-command"class="anchor"href="#delete-current-bash-command"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>delete current bash command</h5>
<aid="add-things-to-history-eg-addmetohistory"class="anchor"href="#add-things-to-history-eg-addmetohistory"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>add things to history (e.g. "addmetohistory")</h5>
<aid="sleep-awhile-or-wait-for-a-moment-or-schedule-a-job"class="anchor"href="#sleep-awhile-or-wait-for-a-moment-or-schedule-a-job"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>sleep awhile or wait for a moment or schedule a job</h5>
<aid="count-the-time-for-executing-a-command"class="anchor"href="#count-the-time-for-executing-a-command"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>count the time for executing a command</h5>
<aid="backup-with-rsync"class="anchor"href="#backup-with-rsync"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>backup with rsync</h5>
<p>//skip files that are newer on receiver (i prefer this one!)</p>
<h5>
<aid="make-all-directories-at-one-time"class="anchor"href="#make-all-directories-at-one-time"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>make all directories at one time!</h5>
//this will create project/doc/html/; project/doc/info; project/lib/ext ,etc</p>
<h5>
<aid="run-command-only-if-another-command-returns-zero-exit-status-well-done"class="anchor"href="#run-command-only-if-another-command-returns-zero-exit-status-well-done"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>run command only if another command returns zero exit status (well done)</h5>
<divclass="highlight highlight-source-shell"><pre><spanclass="pl-c1">cd</span> tmp/ <spanclass="pl-k">&&</span> tar xvf <spanclass="pl-k">~</span>/a.tar</pre></div>
<h5>
<aid="run-command-only-if-another-command-returns-non-zero-exit-status-not-finish"class="anchor"href="#run-command-only-if-another-command-returns-non-zero-exit-status-not-finish"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>run command only if another command returns non-zero exit status (not finish)</h5>
<aid="extract-to-a-path"class="anchor"href="#extract-to-a-path"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>extract to a path</h5>
<aid="use-backslash--to-break-long-command"class="anchor"href="#use-backslash--to-break-long-command"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>use backslash "\" to break long command</h5>
<divclass="highlight highlight-source-shell"><pre>VAR=<spanclass="pl-smi">$PWD</span><spanclass="pl-k">;</span><spanclass="pl-c1">cd</span><spanclass="pl-k">~</span><spanclass="pl-k">;</span> tar xvf -C <spanclass="pl-smi">$VAR</span> file.tar</pre></div>
<p>//PWD need to be capital letter</p>
<h5>
<aid="list-file-type-of-file-eg-tmp"class="anchor"href="#list-file-type-of-file-eg-tmp"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>list file type of file (e.g. /tmp/)</h5>
<aid="search-from-history"class="anchor"href="#search-from-history"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>search from history</h5>
<p>//for variable i, replace all 'a' with a comma</p>
<h5>
<aid="read-user-input"class="anchor"href="#read-user-input"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>read user input</h5>
<aid="sum-up-input-list-eg-seq-10"class="anchor"href="#sum-up-input-list-eg-seq-10"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>sum up input list (e.g. seq 10)</h5>
<aid="find-average-of-input-listfile"class="anchor"href="#find-average-of-input-listfile"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>find average of input list/file</h5>
<aid="echo-size-of-variable"class="anchor"href="#echo-size-of-variable"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>echo size of variable</h5>
<divclass="highlight highlight-source-shell"><pre><spanclass="pl-k">declare</span> -A array=()</pre></div>
<h5>
<aid="send-a-directory"class="anchor"href="#send-a-directory"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>send a directory</h5>
<p>[<ahref="#handy-bash-oneliner-commands-for-tsv-file-editing">back to top</a>]</p>
<h5>
<aid="snapshot-of-the-current-processes"class="anchor"href="#snapshot-of-the-current-processes"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>snapshot of the current processes</h5>
<aid="show-ip-address"class="anchor"href="#show-ip-address"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>show IP address</h5>
<aid="check-system-version"class="anchor"href="#check-system-version"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>check system version</h5>
<aid="linux-programmers-manuel-hier--description-of-the-filesystem-hierarchy"class="anchor"href="#linux-programmers-manuel-hier--description-of-the-filesystem-hierarchy"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>Linux Programmer's Manuel: hier- description of the filesystem hierarchy</h5>
<aid="check-system-x86-64"class="anchor"href="#check-system-x86-64"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>check system (x86-64)</h5>
<aid="surf-the-net"class="anchor"href="#surf-the-net"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>surf the net</h5>
<aid="add-user-set-passwd"class="anchor"href="#add-user-set-passwd"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>add user, set passwd</h5>
<aid="edit-variable-for-bash-eg-displaying-the-whole-path"class="anchor"href="#edit-variable-for-bash-eg-displaying-the-whole-path"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>edit variable for bash, (e.g. displaying the whole path)</h5>
<divclass="highlight highlight-source-shell"><pre>1. joe <spanclass="pl-k">~</span>/.bash_profile
<divclass="highlight highlight-source-shell"><pre>1. joe <spanclass="pl-k">~</span>/.bash_profile
2. <spanclass="pl-c1">alias</span> pd=<spanclass="pl-s"><spanclass="pl-pds">"</span>pwd<spanclass="pl-pds">"</span></span> //no more need to <spanclass="pl-c1">type</span> that <spanclass="pl-s"><spanclass="pl-pds">'</span>w<spanclass="pl-pds">'</span></span><spanclass="pl-k">!</span>
<aid="list-all-environment-variables-for-current-user"class="anchor"href="#list-all-environment-variables-for-current-user"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>list all environment variables for current user</h5>
<aid="soft-link-program-to-bin"class="anchor"href="#soft-link-program-to-bin"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>soft link program to bin</h5>
<aid="jump-to-different-node"class="anchor"href="#jump-to-different-node"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>jump to different node</h5>
<aid="check-port-active-internet-connection"class="anchor"href="#check-port-active-internet-connection"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>check port (active internet connection)</h5>
<aid="find-whick-link-to-a-file"class="anchor"href="#find-whick-link-to-a-file"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>find whick link to a file</h5>
<aid="check-where-a-command-link-to-eg-python"class="anchor"href="#check-where-a-command-link-to-eg-python"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>check where a command link to (e.g. python)</h5>
<aid="list-total-size-of-a-directory"class="anchor"href="#list-total-size-of-a-directory"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>list total size of a directory</h5>
<aid="store-current-directory"class="anchor"href="#store-current-directory"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>store current directory</h5>
<aid="show-disk-usage"class="anchor"href="#show-disk-usage"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>show disk usage</h5>
<aid="show-current-runlevel"class="anchor"href="#show-current-runlevel"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>show current runlevel</h5>
<aid="report-user-quotes-on-device"class="anchor"href="#report-user-quotes-on-device"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>report user quotes on device</h5>
<aid="get-entries-in-a-number-of-important-databases"class="anchor"href="#get-entries-in-a-number-of-important-databases"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>get entries in a number of important databases</h5>
<aid="change-owner-of-file"class="anchor"href="#change-owner-of-file"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>change owner of file</h5>
<aid="list-current-mount-detail"class="anchor"href="#list-current-mount-detail"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>list current mount detail</h5>
<aid="list-current-usernames-and-user-numbers"class="anchor"href="#list-current-usernames-and-user-numbers"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>list current usernames and user-numbers</h5>
<aid="get-all-username"class="anchor"href="#get-all-username"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>get all username</h5>
<aid="show-all-users"class="anchor"href="#show-all-users"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>show all users</h5>
<aid="show-all-groups"class="anchor"href="#show-all-groups"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>show all groups</h5>
<aid="show-group-of-user"class="anchor"href="#show-group-of-user"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>show group of user</h5>
<aid="show-uid-gid-group-of-user"class="anchor"href="#show-uid-gid-group-of-user"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>show uid, gid, group of user</h5>
<aid="check-if-its-root"class="anchor"href="#check-if-its-root"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>check if it's root</h5>
<aid="find-out-cpu-information"class="anchor"href="#find-out-cpu-information"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>find out CPU information</h5>
<aid="set-quota-for-user-eg-disk-soft-limit-120586240-hard-limit-125829120"class="anchor"href="#set-quota-for-user-eg-disk-soft-limit-120586240-hard-limit-125829120"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>set quota for user (e.g. disk soft limit: 120586240; hard limit: 125829120)</h5>
<aid="show-quota-for-user"class="anchor"href="#show-quota-for-user"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>show quota for user</h5>
<aid="check-user-login"class="anchor"href="#check-user-login"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>check user login</h5>
<aid="edit-path-for-all-users"class="anchor"href="#edit-path-for-all-users"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>edit path for all users</h5>
<aid="find-maximum-number-of-processes"class="anchor"href="#find-maximum-number-of-processes"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>find maximum number of processes</h5>
<aid="show-and-set-user-limit"class="anchor"href="#show-and-set-user-limit"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>show and set user limit</h5>