Skip to content

Commit 6f04a87

Browse files
fixed typos, updated descriptions
1 parent 8f153e1 commit 6f04a87

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

assorted-text-processing-tools.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
1:2:3:4:5
258258
6:7:8:9:10
259259

260-
# use input redirection for file input
260+
# use redirection for file input
261261
$ &LTcolors_1.txt paste -d: - - -
262262
Blue:Brown:Orange
263263
Purple::
@@ -272,7 +272,7 @@
272272
</code></pre><h2 id=pr><a class=header href=#pr>pr</a></h2><blockquote><p>Paginate or columnate FILE(s) for printing.</blockquote><p>As stated in the above quote from the manual, the <code>pr</code> command is mainly used for those two tasks. This section will discuss only the columnate features and some miscellaneous tasks. Here's a pagination example if you are interested in exploring further. The <code>pr</code> command will add blank lines, a header and so on to make it suitable for printing.<pre><code class=language-bash>$ pr greeting.txt | head -n8
273273

274274

275-
2021-08-05 14:10 greeting.txt Page 1
275+
2022-06-11 10:48 greeting.txt Page 1
276276

277277

278278
Hi there
@@ -306,7 +306,7 @@
306306
1:2:3:4
307307
5:6:7:8
308308

309-
# unlike paste, pr doesn't add separator if last row has less columns to fill
309+
# unlike paste, pr doesn't add separators if the last row has less columns to fill
310310
$ seq 10 | pr -4ats,
311311
1,2,3,4
312312
5,6,7,8
@@ -327,7 +327,7 @@
327327
$ printf 'malayalam\nnoon\n' | rev
328328
malayalam
329329
noon
330-
</code></pre><h2 id=split><a class=header href=#split>split</a></h2><p>The <code>split</code> command is useful to divide the input into smaller parts based on number of lines, bytes, file size, etc. You can also execute another command on the divided parts before saving the results. An example use case is sending a large file as multiple parts as a workaround for online transfer size limits.<p>By default, the <code>split</code> command divides the input <code>1000</code> lines at a time. Newline character is the default line separator. You can pass a single file or <code>stdin</code> data as the input. Use <code>cat</code> if you need to concatenate multiple input sources. The output files will be named <code>xaa</code>, <code>xab</code>, <code>xac</code> and so on (where <code>x</code> is the prefix). If the filenames are exhausted, two more letters will be appended and the pattern will continue as needed. If the number of input lines is not evenly divisible, the last file will contain less than <code>1000</code> lines.<pre><code class=language-bash># divide input 1000 lines at a time
330+
</code></pre><h2 id=split><a class=header href=#split>split</a></h2><p>The <code>split</code> command is useful to divide the input into smaller parts based on number of lines, bytes, file size, etc. You can also execute another command on the divided parts before saving the results. An example use case is sending a large file as multiple parts as a workaround for online transfer size limits.<p>By default, the <code>split</code> command divides the input <code>1000</code> lines at a time. Newline character is the default line separator. You can pass a single file or <code>stdin</code> data as the input. Use <code>cat</code> if you need to concatenate multiple input sources. By default, the output files will be named <code>xaa</code>, <code>xab</code>, <code>xac</code> and so on (where <code>x</code> is the prefix). If the filenames are exhausted, two more letters will be appended and the pattern will continue as needed. If the number of input lines is not evenly divisible, the last file will contain less than <code>1000</code> lines.<pre><code class=language-bash># divide input 1000 lines at a time
331331
$ seq 10000 | split
332332

333333
# output filenames

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

searchindex.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

shell-customization.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
alias c3='cd ../../../'
9393

9494
alias ls='ls --color=auto'
95-
alias l='ls -ltrh'
95+
alias l='ls -ltrhG'
9696
alias la='l -A'
9797

9898
alias grep='grep --color=auto'
@@ -115,7 +115,7 @@
115115
# single Tab press will complete if there's only one match
116116
# multiple completions will be displayed otherwise
117117
set show-all-if-ambiguous on
118-
</code></pre><blockquote><p><img alt=info src=images/info.svg> You can use <code>bind -f ~/.inputrc</code> or press <code>Ctrl+x Ctrl+r</code> to apply changes from the <code>.inputrc</code> file to the current shell session.</blockquote><h3 id=further-reading><a class=header href=#further-reading>Further Reading</a></h3><ul><li><a href=https://mrzool.cc/writing/sensible-bash/>Sensible bash customizations</a><li><a href=https://blog.sanctum.geek.nz/shell-config-subfiles/>Shell config subfiles</a><li><a href=https://unix.stackexchange.com/q/30925/109046>unix.stackexchange: when to use alias, functions and scripts</a><li><a href=https://unix.stackexchange.com/q/3467/109046>unix.stackexchange: what does rc in bashrc stand for</a></ul><h2 id=readline-shortcuts><a class=header href=#readline-shortcuts>Readline shortcuts</a></h2><p>Quoting from <a href=https://www.gnu.org/software/bash/manual/bash.html#Readline-Interaction>bash manual: Readline Interaction</a>:<blockquote><p>Often during an interactive session you type in a long line of text, only to notice that the first word on the line is misspelled. The Readline library gives you a set of commands for manipulating the text as you type it in, allowing you to just fix your typo, and not forcing you to retype the majority of the line. Using these editing commands, you move the cursor to the place that needs correction, and delete or insert the text of the corrections.</blockquote><p>By default, command line editing bindings are styled after <a href=https://www.gnu.org/software/emacs/>Emacs</a> (a text editor). You can switch to Vi mode (another text editor) if you wish. This section will discuss some of the often used Emacs style key bindings.<h3 id=tab-completion><a class=header href=#tab-completion>Tab completion</a></h3><p>The tab key helps you complete commands, aliases, filenames and so on, depending on the context. If there is only one possible completion, it will be done on single tab press. Otherwise, you can press the tab key twice to get a list of possible matches (if there are any).<p>Use <code>set show-all-if-ambiguous on</code> as seen earlier in the <a href=#inputrc>.inputrc</a> section to combine the single and double tab presses into a single action.<blockquote><p><img alt=info src=./images/info.svg> See <a href=https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion>bash manual: Programmable Completion</a> for more details.</blockquote><h3 id=searching-history><a class=header href=#searching-history>Searching history</a></h3><p>You can use <code>Ctrl+r</code> to search command history. After pressing this key sequence, type characters you wish to match from history, then press the <code>Esc</code> key to return to the command prompt or press <code>Enter</code> to execute the command.<p>You can press <code>Ctrl+r</code> repeatedly to move backwards through matching entries and <code>Ctrl+s</code> to move forwards. If <code>Ctrl+s</code> is not working as expected, see <a href=https://unix.stackexchange.com/q/332791/109046>unix.stackexchange: disable ctrl-s</a>.<p>As discussed in the <a href=#inputrc>.inputrc</a> section, you can use custom key mappings to search based on starting characters of the command.<h3 id=moving-the-cursor><a class=header href=#moving-the-cursor>Moving the cursor</a></h3><p>The documentation uses <strong>Meta</strong> (<code>M-</code> prefix) and notes that this key is labeled as <code>Alt</code> on many keyboards. The documentation also mentions that you can also use the <code>Esc</code> key for such combinations.<ul><li><code>Alt+b</code> move the cursor to the start of the current or previous word<li><code>Alt+f</code> move the cursor to the end of the next word<li><code>Ctrl+a</code> or <code>Home</code> move cursor to the beginning of the command line<li><code>Ctrl+e</code> or <code>End</code> move cursor to the end of the command line</ul><blockquote><p><img alt=info src=./images/info.svg> One difference between <code>Alt</code> and <code>Esc</code> combinations is that you can keep pressing <code>b</code> or <code>f</code> while holding the <code>Alt</code> key down. The <code>Esc</code> combinations are two different key presses, whereas <code>Alt</code> has to be kept pressed down for the shortcut to take effect.</blockquote><h3 id=deleting-characters><a class=header href=#deleting-characters>Deleting characters</a></h3><ul><li><code>Alt+Backspace</code> (or <code>Esc+Backspace</code>) delete backwards up to word boundary<li><code>Ctrl+w</code> delete backwards up to whitespace boundary<li><code>Ctrl+u</code> delete from the character before the cursor till the start of the line<li><code>Ctrl+k</code> delete from the cursor location to the end of the command line</ul><h3 id=clear-screen><a class=header href=#clear-screen>Clear screen</a></h3><ul><li><code>Ctrl+l</code> preserve whatever is typed and clear the terminal screen</ul><blockquote><p><img alt=info src=./images/info.svg> Note that <code>Ctrl+l</code> doesn't try to remove the scrollback buffer altogether. Use the <code>clear</code> command for that purpose.</blockquote><h3 id=swap-words-and-characters><a class=header href=#swap-words-and-characters>Swap words and characters</a></h3><ul><li><code>Alt+t</code> (or <code>Esc+t</code>) swap the previous two words<li><code>Ctrl+t</code> swap the previous two characters <ul><li>for example, if you typed <code>sp</code> instead of <code>ps</code>, press <code>Ctrl+t</code> when the cursor is to the right of <code>sp</code></ul></ul><h3 id=insert-arguments><a class=header href=#insert-arguments>Insert arguments</a></h3><ul><li><code>Alt+.</code> (or <code>Esc+.</code>) insert the last argument from the previous command, multiple presses will traverse through second last command and so on <ul><li>for example, if <code>cat temp.txt</code> was the last command used, pressing <code>Alt+.</code> will insert <code>temp.txt</code><li>you can also use <code>!$</code> to represent the last argument from the previous command</ul></ul><h3 id=further-reading-1><a class=header href=#further-reading-1>Further Reading</a></h3><ul><li><a href=https://www.gnu.org/software/bash/manual/bash.html#Bindable-Readline-Commands>bash manual: Bindable Readline Commands</a><li><a href=https://wiki.archlinux.org/title/readline>wiki.archlinux: Simpler introduction to Readline</a><li><a href=https://cupfullofcode.com/blog/2013/07/03/efficient-command-line-navigation/index.html>Efficient command line navigation</a></ul><h2 id=copy-and-paste><a class=header href=#copy-and-paste>Copy and paste</a></h2><p>Shortcuts for copy-paste operations in the terminal are shown below. You might be able to customize these shortcuts in terminal preferences.<ul><li><code>Shift+Ctrl+c</code> copy the highlighted portion to the clipboard<li><code>Shift+Ctrl+v</code> paste clipboard contents<li><code>Shift+Insert</code> paste the last highlighted portion (not necessarily the clipboard contents)</ul><p>You can also press middle mouse button instead of the <code>Shift+Insert</code> shortcut. This is not limited to the terminal, but works in any application. Use the <code>xinput</code> command to enable/disable mouse button clicks. First, use <code>xinput</code> without any arguments and spot the number corresponding to your mouse. As an example, assuming the device number is <code>11</code>, you can use the following commands:<ul><li><code>xinput set-button-map 11 1 0 3</code> to disable middle button click<li><code>xinput set-button-map 11 1 2 3</code> to enable middle button click</ul><h2 id=exercises><a class=header href=#exercises>Exercises</a></h2><p><strong>1)</strong> Which command would you use to display the name and value of all or specific environment variables?<p><strong>2)</strong> If you add an alias for an already existing command (<code>ls</code> for example), how would you invoke the original command instead of the alias?<p><strong>3)</strong> Why doesn't the alias shown below work? What would you use instead?<pre><code class=language-bash># doesn't work as expected
118+
</code></pre><blockquote><p><img alt=info src=images/info.svg> You can use <code>bind -f ~/.inputrc</code> or press <code>Ctrl+x Ctrl+r</code> to apply changes from the <code>.inputrc</code> file to the current shell session.</blockquote><h3 id=further-reading><a class=header href=#further-reading>Further Reading</a></h3><ul><li><a href=https://mrzool.cc/writing/sensible-bash/>Sensible bash customizations</a><li><a href=https://blog.sanctum.geek.nz/shell-config-subfiles/>Shell config subfiles</a><li><a href=https://unix.stackexchange.com/q/30925/109046>unix.stackexchange: when to use alias, functions and scripts</a><li><a href=https://unix.stackexchange.com/q/3467/109046>unix.stackexchange: what does rc in bashrc stand for</a></ul><h2 id=readline-shortcuts><a class=header href=#readline-shortcuts>Readline shortcuts</a></h2><p>Quoting from <a href=https://www.gnu.org/software/bash/manual/bash.html#Readline-Interaction>bash manual: Readline Interaction</a>:<blockquote><p>Often during an interactive session you type in a long line of text, only to notice that the first word on the line is misspelled. The Readline library gives you a set of commands for manipulating the text as you type it in, allowing you to just fix your typo, and not forcing you to retype the majority of the line. Using these editing commands, you move the cursor to the place that needs correction, and delete or insert the text of the corrections.</blockquote><p>By default, command line editing bindings are styled after <a href=https://www.gnu.org/software/emacs/>Emacs</a> (a text editor). You can switch to Vi mode (another text editor) if you wish. This section will discuss some of the often used Emacs style key bindings.<h3 id=tab-completion><a class=header href=#tab-completion>Tab completion</a></h3><p>The tab key helps you complete commands, aliases, filenames and so on, depending on the context. If there is only one possible completion, it will be done on single tab press. Otherwise, you can press the tab key twice to get a list of possible matches (if there are any).<p>Use <code>set show-all-if-ambiguous on</code> as seen earlier in the <a href=#inputrc>.inputrc</a> section to combine the single and double tab presses into a single action.<blockquote><p><img alt=info src=./images/info.svg> See <a href=https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion>bash manual: Programmable Completion</a> for more details.</blockquote><h3 id=searching-history><a class=header href=#searching-history>Searching history</a></h3><p>You can use <code>Ctrl+r</code> to search command history. After pressing this key sequence, type characters you wish to match from history, then press the <code>Esc</code> key to return to the command prompt or press <code>Enter</code> to execute the command.<p>You can press <code>Ctrl+r</code> repeatedly to move backwards through matching entries and <code>Ctrl+s</code> to move forwards. If <code>Ctrl+s</code> is not working as expected, see <a href=https://unix.stackexchange.com/q/332791/109046>unix.stackexchange: disable ctrl-s</a>.<p>As discussed in the <a href=#inputrc>.inputrc</a> section, you can use custom key mappings to search based on starting characters of the command.<h3 id=moving-the-cursor><a class=header href=#moving-the-cursor>Moving the cursor</a></h3><p>The documentation uses <strong>Meta</strong> (<code>M-</code> prefix) and notes that this key is labeled as <code>Alt</code> on many keyboards. The documentation also mentions that you can also use the <code>Esc</code> key for such combinations.<ul><li><code>Alt+b</code> move the cursor to the start of the current or previous word<li><code>Alt+f</code> move the cursor to the end of the next word<li><code>Ctrl+a</code> or <code>Home</code> move cursor to the beginning of the command line<li><code>Ctrl+e</code> or <code>End</code> move cursor to the end of the command line</ul><blockquote><p><img alt=info src=./images/info.svg> One difference between <code>Alt</code> and <code>Esc</code> combinations is that you can keep pressing <code>b</code> or <code>f</code> while holding the <code>Alt</code> key down. The <code>Esc</code> combinations are two different key presses, whereas <code>Alt</code> has to be kept pressed down for the shortcut to take effect.</blockquote><h3 id=deleting-characters><a class=header href=#deleting-characters>Deleting characters</a></h3><ul><li><code>Alt+Backspace</code> (or <code>Esc+Backspace</code>) delete backwards up to word boundary<li><code>Ctrl+w</code> delete backwards up to whitespace boundary<li><code>Ctrl+u</code> delete from the character before the cursor till the start of the line<li><code>Ctrl+k</code> delete from the cursor location to the end of the command line</ul><h3 id=clear-screen><a class=header href=#clear-screen>Clear screen</a></h3><ul><li><code>Ctrl+l</code> preserve whatever is typed and clear the terminal screen</ul><blockquote><p><img alt=info src=./images/info.svg> Note that <code>Ctrl+l</code> doesn't try to remove the scrollback buffer altogether. Use the <code>clear</code> command for that purpose.</blockquote><h3 id=swap-words-and-characters><a class=header href=#swap-words-and-characters>Swap words and characters</a></h3><ul><li><code>Alt+t</code> (or <code>Esc+t</code>) swap the previous two words<li><code>Ctrl+t</code> swap the previous two characters <ul><li>for example, if you typed <code>sp</code> instead of <code>ps</code>, press <code>Ctrl+t</code> when the cursor is to the right of <code>sp</code></ul></ul><h3 id=insert-arguments><a class=header href=#insert-arguments>Insert arguments</a></h3><ul><li><code>Alt+.</code> (or <code>Esc+.</code>) insert the last argument from the previous command, multiple presses will traverse through second last command and so on <ul><li>for example, if <code>cat temp.txt</code> was the last command used, pressing <code>Alt+.</code> will insert <code>temp.txt</code><li>you can also use <code>!$</code> to represent the last argument from the previous command</ul></ul><h3 id=further-reading-1><a class=header href=#further-reading-1>Further Reading</a></h3><ul><li><a href=https://www.gnu.org/software/bash/manual/bash.html#Bindable-Readline-Commands>bash manual: Bindable Readline Commands</a><li><a href=https://wiki.archlinux.org/title/readline>wiki.archlinux: Simpler introduction to Readline</a><li><a href=https://cupfullofcode.com/blog/2013/07/03/efficient-command-line-navigation/index.html>Efficient command line navigation</a></ul><h2 id=copy-and-paste><a class=header href=#copy-and-paste>Copy and paste</a></h2><p>Shortcuts for copy-paste operations in the terminal are shown below. You might be able to customize these shortcuts in the terminal preferences.<ul><li><code>Shift+Ctrl+c</code> copy the highlighted portion to the clipboard<li><code>Shift+Ctrl+v</code> paste clipboard contents<li><code>Shift+Insert</code> paste the last highlighted portion (not necessarily the clipboard contents)</ul><p>You can also press middle mouse button instead of the <code>Shift+Insert</code> shortcut. This is not limited to the terminal, works in many other applications too. You can use the <code>xinput</code> command to enable/disable mouse button clicks. First, use <code>xinput</code> without any arguments and spot the number corresponding to your mouse. As an example, assuming the device number is <code>11</code>, you can use the following commands:<ul><li><code>xinput set-button-map 11 1 0 3</code> to disable middle button click<li><code>xinput set-button-map 11 1 2 3</code> to enable middle button click</ul><h2 id=exercises><a class=header href=#exercises>Exercises</a></h2><p><strong>1)</strong> Which command would you use to display the name and value of all or specific environment variables?<p><strong>2)</strong> If you add an alias for an already existing command (<code>ls</code> for example), how would you invoke the original command instead of the alias?<p><strong>3)</strong> Why doesn't the alias shown below work? What would you use instead?<pre><code class=language-bash># doesn't work as expected
119119
$ alias ext='echo "${1##*.}"'
120120
$ ext ip.txt
121121
ip.txt

0 commit comments

Comments
 (0)