Examples http://meng6net.localhost/computing/example/ <p><small>Copyright © 2005-2020 by <code>Meng Lu &lt;lumeng3@gmail.com&gt;</code></small></p> Meng Lu's home page ikiwiki Tue, 12 Jan 2021 21:03:09 +0000 Examples of using `gpg-agent` http://meng6net.localhost/computing/example/examples_of_using_gpg-agent/ http://meng6net.localhost/computing/example/examples_of_using_gpg-agent/ GnuPG computing example Tue, 12 Jan 2021 21:03:09 +0000 2021-01-12T21:03:09Z <h2>Checking the status of <code>gpg-agent</code></h2> <pre><code>$ gpg-agent gpg-agent[7405]: no gpg-agent running in this session </code></pre> <h2>Starting <code>gpg-agent</code></h2> <p>Find number of files where string <code>ToDo</code> occurs</p> <pre><code>$ gpg-agent --daemon $ gpg-agent gpg-agent[9580]: gpg-agent running and available </code></pre> <h2>Re-starting <code>gpg-agent</code></h2> <p>The <code>gpg-connect-agent</code> is a utility to communicate with a running <code>gpg-agent</code> instance. It can be used to restart <code>gpg-agent</code>:</p> <pre><code>$ gpg-connect-agent reloadagent /bye OK $ gpg-agent gpg-agent[59922]: gpg-agent running and available $ gpg-connect-agent reloadagent /bye OK $ gpg-agent gpg-agent[60312]: gpg-agent running and available </code></pre> <p>Alternatively,</p> <pre><code>$ gpgconf --kill gpg-agent $ gpg-agent gpg-agent[12247]: no gpg-agent running in this session </code></pre> Examples of using wget http://meng6net.localhost/computing/example/examples_of_using_wget/ http://meng6net.localhost/computing/example/examples_of_using_wget/ computing note tip wget Sun, 03 May 2020 05:47:34 +0000 2020-12-14T03:46:01Z <h2>Download web pages recursively under an URL<sup id= "fnref:1"><a href="http://meng6net.localhost/computing/example/#fn:1" rel="footnote">1</a></sup></h2> <pre><code> wget \ --recursive \ --no-clobber \ --page-requisites \ --html-extension \ --convert-links \ --restrict-file-names=windows \ --domains example.com \ -nH --cut-dirs=some_subdir \ -e robots=off \ --random-wait \ --wait 5 \ --no-parent \ www.example.com/subdirectory/ </code></pre> <ul> <li>Substitute <code>example.com</code> and <code>www.example.com/subdirectory/</code> with relevant expressions in your problem.</li> <li><code>--recursive</code>: download the entire Web site.</li> <li><code>--domains website.org</code>: don't follow links outside website.org.</li> <li><code>--no-parent</code>: don't follow links outside the directory <code>subdirectory</code>.</li> <li><code>--page-requisites</code>: get all the elements that compose the page (images, CSS and so on).</li> <li><code>--html-extension</code>: save files with the .html extension.</li> <li><code>--convert-links</code>: convert links so that they work locally, off-line.</li> <li><code>--restrict-file-names=windows</code>: modify filenames so that they will work in Windows as well.</li> <li><code>--no-clobber</code>: don't overwrite any existing files (used in case the download is interrupted and resumed).</li> <li><code>-e robots=off</code>: force crawling regardless of robots.txt setting.</li> <li><code>-nH --cut-dirs=some_subdir</code>: cuts out hostname and subdirectory name.</li> <li><code>--random-wait</code>: randomizes the time between requests to vary between 0.5 and 1.5 times of the waiting time specified by the <code>--wait</code> option.</li> <li><code>--wait 5</code>: number of seconds to wait between requests. (See <code>--random-wait</code>.)</li> </ul> <h2>References</h2> <div class="footnotes"> <hr /> <ol> <li id="fn:1">linuxjournal.com. <em>Downloading an Entire Web Site with wget</em>. 2008. <a href= "https://www.linuxjournal.com/content/downloading-entire-web-site-wget"> https://www.linuxjournal.com/content/downloading-entire-web-site-wget</a><a href="http://meng6net.localhost/computing/example/#fnref:1" rev="footnote">↩</a></li> </ol> </div> Examples of using Evernote http://meng6net.localhost/computing/example/examples_of_using_Evernote/ http://meng6net.localhost/computing/example/examples_of_using_Evernote/ Evernote computing documentation example note software tip Wed, 11 Mar 2020 18:41:54 +0000 2020-03-11T18:41:54Z <h2>Resync all data</h2> <ol> <li>Open Evernote.app on macOS.</li> <li>Press <kbd>Shift</kbd>-<kbd>Option/Alt</kbd> and click the synchronization wheel icon next to the search input field (as of Evernote macOS version 7.14 and 2020-3).</li> </ol> <h2>Refresh database indices</h2> <ul> <li>Press <kbd>Option/Alt</kbd> and click menu item 'Option &gt; Troubleshooting'</li> <li>Click 'Recreate Full Text Search Index' and 'Recreate Spotlight Search Index'.</li> </ul> Examples of using `tree` http://meng6net.localhost/computing/example/examples_of_using_tree/ http://meng6net.localhost/computing/example/examples_of_using_tree/ Tue, 21 Jan 2020 20:00:14 +0000 2020-01-21T20:00:14Z <h2>Most frequent usage: <code>tree -N --prune</code></h2> <pre><code>$ tree -N --prune </code></pre> <ul> <li><code>-N</code>: In practice, this option allows many non-ASCII characters printed correctly.</li> <li><code>--prune</code>: Remove empty directories recursively from the output.</li> </ul> <p>(END)</p> <p><span class="createlink">tag:tree</span> <span class= "createlink">tag:computing</span> <span class= "createlink">tag:example</span> <span class= "createlink">tag:note</span></p> Examples of using afinfo http://meng6net.localhost/computing/example/examples_of_using_afinfo/ http://meng6net.localhost/computing/example/examples_of_using_afinfo/ afinfo audio computing example metadata note software Thu, 27 Dec 2018 19:29:57 +0000 2018-12-27T19:38:14Z <p>Get metadata of an audio or video file:</p> <pre><code>$ afinfo 'some_multimedia_file.m4a'' </code></pre> <p>Get the duration in the unit of seconds:</p> <pre> <code>$ afinfo 'some_multimedia_file.m4a' | awk '/estimated duration/ { print $3 }' </code></pre> <h2>References</h2> <ul> <li> https://stackoverflow.com/questions/8933053/check-duration-of-audio-files-on-the-command-line</li> </ul> Examples of using pandoc http://meng6net.localhost/computing/example/examples_of_using_pandoc/ http://meng6net.localhost/computing/example/examples_of_using_pandoc/ Tue, 25 Jul 2017 19:35:27 +0000 2017-07-25T19:35:27Z <h2>Convert a Markdown file to a Mediawiki markup file</h2> <pre> <code>$ pandoc -r markdown input.md -t mediawiki -o output.mediawiki </code></pre> <h2>References</h2> <ul> <li>http://pandoc.org/MANUAL.html</li> </ul> examples of using 7z http://meng6net.localhost/computing/example/examples_of_using_7z/ http://meng6net.localhost/computing/example/examples_of_using_7z/ Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Create a high-compression-level solid-compression archive in 7z format</h2> <pre> <code>7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on dir`date +%Y%m%d%H%M%S`.7z dir </code></pre> <p>Remarks:</p> <ul> <li><code>-si</code> gets the input from stdin</li> <li><code>-m0=lzma2</code> use the LZMA2 compression method (See this <a href= "https://superuser.com/questions/432025/different-compression-methods-in-7zip-which-is-best-suited-for-what-task"> superuser.com</a> thread for information about LZMA2 method). Use only when GBs of memory is available.</li> <li><code>-mx=9</code> highest compression level</li> <li><code>-ms=on</code> creates a <a href= "https://en.wikipedia.org/wiki/Solid_compression">solid compression</a>, (tar-based formats that are solid compressions include <code>tar.bz2</code>, <code>tar.gz</code>) TODO</li> </ul> <h3>Optionally create a tarball first</h3> <pre> <code>$ tar cfv - dir/ | 7z a -si -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on dir`date +%Y%m%d%H%M%S`.tar.7z </code></pre> <p>Remarks:</p> <ul> <li><code>-</code> creates the default tarball filename</li> </ul> <h2>Create a multi-volume ZIP archive</h2> <pre><code>$ 7z a -tzip -v14m archive.zip largedir/ </code></pre> <h2>Create a password protected archive and extract it</h2> <pre><code>$ 7z a -t7z -p myarchive.7z file1.txt file2.png *.cpp </code></pre> <p>Extract it:</p> <pre><code>$ 7z x myarchive.7z </code></pre> <h2>Create compressed <a href="">multi-volume archive</a> of a directory of multiple files and subdirectories</h2> <pre> <code>$ 7z a -t7z -mx=5 -v100m largedir ~/Desktop/Downloading/largedir/ 7-Zip 9.04 beta Copyright (c) 1999-2009 Igor Pavlov 2009-05-30 p7zip Version 9.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,2 CPUs) Scanning Creating archive largedir.7z Compressing largedir/largefile1.avi Compressing largedir/largefile2.avi Compressing largedir/largefile3.avi Compressing largedir/largefile4.avi Everything is Ok </code></pre> <p>Extract</p> <pre><code>$ 7z e largedir.7z.001 7-Zip 9.04 beta Copyright (c) 1999-2009 Igor Pavlov 2009-05-30 p7zip Version 9.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,2 CPUs) Processing archive: largedir.7z.001 Extracting largedir/largefile1.avi Extracting largedir/largefile2.avi Extracting largedir/largefile3.avi Extracting largedir/largefile4.avi Extracting largedir/largefile5.avi Extracting largedir Everything is Ok Folders: 1 Files: 5 Size: 463073364 Compressed: 104857600 $ </code></pre> <p>Remarks:</p> <ul> <li><code>-t7z</code> specifies type as <code>7z</code></li> <li><code>-v100m</code> specifies volume size to be at most 100MB</li> <li><code>-mx=5</code> specifies level of compression in range 0 - 9 with 9 being the most compressed</li> <li><code>largedir</code> is the name of the resultant archive, and if multiple volumes are created, the names are <code>largedir.001</code>, <code>largedir.002</code>, etc.</li> </ul> Examples of using Imagemagick http://meng6net.localhost/computing/example/examples_of_using_Imagemagick/ http://meng6net.localhost/computing/example/examples_of_using_Imagemagick/ Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Checking usage</h2> <p>If you installed <a href= "http://www.GraphicsMagick.org">GraphicsMagick</a>, do</p> <pre><code>$ gm GraphicsMagick 1.3.12 2010-03-08 Q8 http://www.GraphicsMagick.org/ Copyright (C) 2002-2010 GraphicsMagick Group. Additional copyrights and licenses apply to this software. See http://www.GraphicsMagick.org/www/Copyright.html for details. Usage: gm command [options ...] Where commands include: animate - animate a sequence of images benchmark - benchmark one of the other commands compare - compare two images composite - composite images together conjure - execute a Magick Scripting Language (MSL) XML script convert - convert an image or sequence of images display - display an image on a workstation running X help - obtain usage message for named command identify - describe an image or image sequence import - capture an application or X server screen mogrify - transform an image or sequence of images montage - create a composite image (in a grid) from separate images time - time one of the other commands version - obtain release version </code></pre> <h2>Checking basic properties of image</h2> <pre><code>$ identify Mathematica7.png Mathematica7.png PNG 1000x1048+0+0 DirectClass 8-bit 1.2M 0.000u 0:01 </code></pre> <p>Geometry is given as <code>&lt;width&gt;x&lt;height&gt;</code></p> <h2>Converting image format</h2> <p>Convert one image</p> <pre><code>$ convert source.png destination.jpg </code></pre> <p>Converting multiple images</p> <pre><code>$ mogrify -format jpg *.png </code></pre> <h2>Resizing images</h2> <p>Resize to a certain width and height automatically chosen to maintain aspect ratio</p> <pre><code>$ convert source.jpg -resize 800 destination.jpg </code></pre> <p>Resize all JPEG files (assuming all have file names <code>*.jpg</code>) in the path</p> <pre><code>$ mogrify -resize 800 *.jpg </code></pre> <p>Resize to a certain width and height which has same aspect ratio as the original image</p> <pre><code>$ convert source.jpg -resize 800x600 destination.jpg </code></pre> <p>If the geometry specification <code>&lt;widht&gt;x&lt;height&gt;</code> has a aspect ratio different from that of the original. It resizes to a certain width or height, which ever has a larger resizing fraction, and determine the other edge size automatically such that aspect ratio is unchanged</p> <pre><code>$ convert source.jpg -resize 800x1000000 destination.jpg $ convert source.jpg -resize 1000000x800 destination.jpg </code></pre> <p>Resize to a certain percentage</p> <pre><code>$ convert source.jpg -resize 75% destination.jpg </code></pre> <h2>Compressing image</h2> <pre><code>$ convert big_file.jpg -quality 60% small_file.jpg </code></pre> <h2>Trim off the edges of an image</h2> <p>Removes any edges that are exactly the same color as the pixels at the corner of the image.</p> <pre><code>$ convert non_trimmed.jpg -trim trimmed.jpg </code></pre> Examples of using ack http://meng6net.localhost/computing/example/examples_of_using_ack/ http://meng6net.localhost/computing/example/examples_of_using_ack/ ack computing example Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Find instances of <code>ToDo</code> in source files</h2> <pre><code>ack -r Client . </code></pre> <h2>Find number of files where string <code>ToDo</code> occurs</h2> <pre><code>ack -l 'ToDo' sourceDirectory | wc -l 12 </code></pre> <h2>Find string <code>"FooBar"</code> in any <code>.*</code> files ignoring certain directories</h2> <pre><code>$ pwd /User/lumeng $ ack --type=matlab --ignore-dir={subdir1,subdir2} "\"FooBar\"" </code></pre> <p>Remarks:</p> <ul> <li><code>/User/lumeng/subdir1</code>, <code>/User/lumeng/subdir2</code> are not searched;</li> <li><code>--type=matlab</code> specifies that files with file name extension <code>.m</code> is searched; Check <code>ack --help=type</code> for complete list of types;</li> </ul> <h2>Find <code>Plot</code> in Mathematica and related source code files</h2> <pre> <code>ack --type-add=wolfram:ext:.m,.nb,.cdf,.mt,.wl,.wlt --wolfram Plot </code></pre> <p>Optionally, add <code>--type-add=wolfram:ext:.m,.nb,.cdf,.mt,.wl,.wlt</code> to a <code>${HOME}/.ackrc</code> and ue</p> <pre><code>ack --wolfram Plot ack --nowolfram Plot </code></pre> Examples of using awk http://meng6net.localhost/computing/example/examples_of_using_awk/ http://meng6net.localhost/computing/example/examples_of_using_awk/ awk computing example tip Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Count number of lines</h2> <p>Count number of lines in a text file:</p> <pre><code>$ awk '{print NR}' file.txt </code></pre> <p>This will give correct answer even if there is no <code>EOL</code> character at the last line. In contrast <code>wc -l file.txt</code> would give wrong answer (1 less) in that case.</p> Examples of using Bash http://meng6net.localhost/computing/example/examples_of_using_bash/ http://meng6net.localhost/computing/example/examples_of_using_bash/ bash computing example Tue, 16 May 2017 23:59:39 +0000 2017-07-06T16:08:37Z <h2>Rename multiple files</h2> <h3>Remove "-2" from names of multiple files</h3> <pre><code>$ ls R0012455-2.jpg R0012462-2.jpg R0012466-2.jpg $ for i in *.jpg; do mv -i "$i" "${i/\-2/}"; done $ ls R0012455.jpg R0012462.jpg R0012466.jpg </code></pre> <h3>References</h3> <ul> <li><a href= "http://www.debian-administration.org/articles/150">Debian Administration: Easily renaming multiple files.</a></li> <li><a href= "http://www.nongnu.org/renameutils/">renameutils</a></li> </ul> <h2><code>echo</code></h2> <h3>Enable backslash-escaped characters</h3> <pre><code>$ echo "line1\nline2" line1\nline2 $ echo -e "line1 \n line2" line1 line2 </code></pre> <h2><code>read</code></h2> <h3>pause until user press a key</h3> <pre><code>read -p "Press any key to continue ..." </code></pre> <h2>Interate over a list of values</h2> <pre> <code>bash$ for i in {6,8,9,11}; do wget "http://www.weilishi.org/img/0401/$i.jpg"; done </code></pre> <p>Remarks:</p> <ul> <li>Notice that <code>{6, 8, 9, 11}</code> which contains white spaces does not work.</li> </ul> Examples of using command-line http://meng6net.localhost/computing/example/examples_of_using_command-line/ http://meng6net.localhost/computing/example/examples_of_using_command-line/ Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2><code>cd</code></h2> <p>Return to previous path:</p> <pre><code>cd - </code></pre> <h2>Notes</h2> <h2>See also</h2> <h2>References</h2> <h2>External links</h2> Examples of using curl http://meng6net.localhost/computing/example/examples_of_using_curl/ http://meng6net.localhost/computing/example/examples_of_using_curl/ computing curl tip Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Check TCP handshake and SSL handshake time cost for a domain</h2> <pre> <code>curl -w "TCP handshake: %{time_connect}, SSL handshake: %{time_appconnect}\n" -so /dev/null https://www.wolfram.com </code></pre> <p>References:</p> <ul> <li> <p><a href= "http://www.semicomplete.com/blog/geekery/ssl-latency.html">Jordan Sissel, "SSL handshake latency and HTTPS optimizations," 2010</a></p> </li> <li> <p><a href= "http://www.ruanyifeng.com/blog/2014/09/ssl-latency.html">阮一峰, 〈SSL延迟有多大?〉</a></p> </li> </ul> <h2>Download multiple files</h2> <pre> <code>curl -O http://www.cs.berkeley.edu/~sinclair/cs271/n[1-3].pdf </code></pre> <h2>References</h2> Examples of using CVS http://meng6net.localhost/computing/example/examples_of_using_cvs/ http://meng6net.localhost/computing/example/examples_of_using_cvs/ Tue, 16 May 2017 23:59:39 +0000 2017-06-26T20:30:45Z <h2>Check out a module and name the root directory different</h2> <pre><code>$ cvs checkout -d localDirName remoteModuleName &lt;snip&gt; $ ls $ localDirName </code></pre> <p>By default</p> <pre><code>$ cvs checkout remoteModuleName &lt;snip&gt; $ ls remoteModuleName </code></pre> <h2><code>.cvsignore</code></h2> <p>To ignore a subdirectory subdir in directory dir</p> <ul> <li>delete text <code>D/subdir////</code> if it exists from file <code>../dir/CVS/Entries</code></li> <li> <p>add text <code>subdir</code> in file <code>../dir/.cvsignore</code></p> </li> <li> <p>refresh <code>cvs status -l</code></p> </li> </ul> <h2>Replace a file with the latest version from the repository</h2> <pre><code>cvs update -C someFile </code></pre> <h2>References</h2> <ul> <li><a href="http://cvsbook.red-bean.com/cvsbook.html">Open Source Development with CVS</a></li> </ul> <h2>External links</h2> examples of using du http://meng6net.localhost/computing/example/examples_of_using_du/ http://meng6net.localhost/computing/example/examples_of_using_du/ Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Display the sizes of directories and files in current path</h2> <pre><code>$ du -hcs * 8.6G dir1 838M dir2 1.5M file1 56K file2 </code></pre> <ul> <li><code>-h</code> to use human-readable sizes</li> <li><code>-c</code> to display a total size</li> <li><code>-s</code> to display sizes only for directories and files directly under the current path but not in any subdirectory</li> </ul> Examples of using Eclipse http://meng6net.localhost/computing/example/examples_of_using_eclipse/ http://meng6net.localhost/computing/example/examples_of_using_eclipse/ computing documentation eclipse example note software Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Uninstalling plug-in</h2> <p>Preferences → Install/Update → Uninstall or update software that is already installed → select some plug-ins → click Uninstall</p> <h2>Move a project's directory</h2> <p>Suppose you have a project 'project1' which is at path <code>/home/XXX/workspace/project1/</code> and you want to move it to <code>/home/XXX/workspace/group/project1/</code>.</p> <p>In order to avoid destroying the metadata of the project such as working sets and .project file, use the refactor function in the menu rather than deleting and recreating the project.</p> <ol> <li>Create the directory <code>/home/XXX/workspace/group/</code>.</li> <li>Use menu Windows &gt; Views &gt; Other &gt; Navigator.</li> <li>Right click on the project of interest in the Navigator view.</li> <li>Choose refactor &gt; move, and select the new path <code>/home/XXX/workspace/group/</code>, and click OK.</li> </ol> <h2>Change a CVS repository to use 'ext' connection method</h2> <p>By default a CVS repostiory created in Eclipse uses a non-standard connection method 'extssh'. To change an existing project to use 'ext' connection method,</p> <ol> <li> <p>Window &gt; Open Perspective &gt; CVS Repository Exploring &gt; add a CVS repository with same setup as the 'extssh' repository but this time specify 'ext' as connection method.</p> </li> <li> <p>Preferences &gt; Team &gt; CVS &gt; Ext Connection Method &gt; check 'Use another connection method type to connect', choose 'connection type' as 'extssh'.</p> </li> <li> <p>Open Window &gt; View &gt; Navigator, in the Navigator view, right click on the interested project, go to menu Properties &gt; CVS &gt; Change Sharing &gt; choose the CVS repository with 'ext' connection method.</p> </li> </ol> <h2>Using the same physical directory as projects in different workspaces</h2> <ul> <li>Git clone (or CVS check out) a version controlled project to a centralized location on one's computer.</li> <li>In each Eclipse workspace that you need the repository or project, use the menu "File &gt; Import... General: Existing Projects in Workspace" to import the repository, but point it to the directory prepared in the last step. Make sure the "copy projects into workspace" checkbox is <em>unchecked</em>.</li> </ul> <h2>Notes</h2> <h2>See also</h2> <h2>References</h2> <h2>External links</h2> Examples of using Emacs http://meng6net.localhost/computing/example/examples_of_using_emacs/ http://meng6net.localhost/computing/example/examples_of_using_emacs/ Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Viewing</h2> <h3>Highlight all lines matching a regex</h3> <p>Highlight all lines wider than 79 columns:</p> <pre><code>m-x highlight-lines-matching-regexp .\{80\} </code></pre> <h2>Replace</h2> <h3>Remove empty lines</h3> <ul> <li> <p><kbd>M</kbd>-<kbd>%</kbd>: Query replace string (<a href= "http://www.gnu.org/software/emacs/manual/html_node/emacs/Query-Replace.html"><code>query-replace</code></a>).</p> </li> <li> <p><kbd>C</kbd>-<kbd>q</kbd>: Quote - enter original string now.</p> </li> <li> <p><kbd>C</kbd>-<kbd>j</kbd>, <kbd>C</kbd>-<kbd>j</kbd>: Two continuous <code>^J</code> characters. (Note an empty line is <strong>two</strong> continuous newline characters.)</p> </li> <li> <p><kbd>C</kbd>-<kbd>q</kbd>: Quote —— enter replacement string now.</p> </li> <li> <p><kbd>C</kbd>-<kbd>j</kbd>: <code>^J</code> character. (Replace empty line with <strong>one</strong> newline character.)</p> </li> </ul> <h3>Replace lines with string substituted</h3> <p>To replace lines like</p> <pre><code>echo "[INFO]example: 'development'" </code></pre> <p>with</p> <pre><code>read -p "examples: 'development':" -e INPUT </code></pre> <p>do</p> <ul> <li> <p>press key combination <kbd>M</kbd>-<kbd>x</kbd> and type in the command <code>query-replace-regexp</code>, or use the key binding for that: <kbd>C</kbd>-<kbd>M</kbd>-<kbd>%</kbd></p> </li> <li> <p>type in regex pattern <code>^echo \"\[INFO\]example: \(.*\)\"</code>, and press <kbd>Enter</kbd></p> </li> <li> <p>type in replacement pattern <code>read -p "examples: \1" -e INPUT</code>, and press <kbd>Enter</kbd></p> <blockquote> <ul> <li>Special characters in Emacs Lisp regex are <code>.</code>, <code>*</code>, <code>+</code>, <code>?</code>, <code>[</code>, <code>^</code>, <code>$</code>, and <code>\</code>. <code>]</code> is special if it matches an earlier <code>[</code> and ends a character alternative. <code>-</code> is special inside a character alternative. <code>[:</code> and balancing <code>:]</code> enclosing a character class are special. Any other character appearing in a regular expression is ordinary, unless a <code>\</code> precedes it.</li> <li>There are <a href= "http://www.gnu.org/s/emacs/manual/html_node/elisp/Regexp-Backslash.html#Regexp-Backslash"> back slash constructs</a>.</li> <li><code>\"</code>: I'm actually not sure why <code>"</code> needs escaping here.</li> <li><code>\[</code> and <code>\]</code>: needs escaping since <code>[</code> and <code>]</code> are special characters but it is the literal characters that needs matching.</li> <li><code>\(</code> and <code>\)</code>: needs escaping since <code>(</code> and <code>)</code> are non-special characters in Emacs Lisp regular expression, and needs escaping to use its special function as a <a href= "http://www.gnu.org/s/emacs/manual/html_node/elisp/Regexp-Backslash.html#Regexp-Backslash"> back slash construct</a>.</li> <li><code>\1</code> refers to the first matched group associated with <code>\(.*\)</code>.</li> </ul> </blockquote> </li> </ul> <p>Here is a list of examples for this type of replacing:</p> <p>(examples to be added)</p> <h3>Replace multiple continuous whitespaces inbetween words with one whitespace</h3> <p>Replace regexp `\b[:space:]+\b with ' ' (don't include the two ').</p> <h3>Comment out lines of form <code>{"OriginalString", "Unit"} -&gt; ".*"</code> in Mathematica code</h3> <pre> <code>Query replace regexp \({"OriginalString", "Unit"} -&gt; ".*"\)$ with: (* \1 *) </code></pre> <h3>Resolving version control repository merge conflicts</h3> <p>When resolving merge conflicts for files in version control repositories, oftentimes, one need to keep the top or bottom halves for all the conflict blocks of form</p> <p>&lt;&lt;&lt;&lt;&lt;&lt;&lt; XXX top code block line 1 top code block line 2</p> <h1>top code block line 3</h1> <p>bottom code block line 1 bottom code block line 2 bottom code block line 3</p> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <p>YYY</p> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> <h2>Check and change file encoding</h2> <p>Check the coding system of the file opened in the current buffer:</p> <p><code>describe-coding-system</code></p> <p>or with keybinding</p> <p><kbd>C</kbd>-<kbd>h</kbd> <kbd>C</kbd></p> <p>Save the buffer in file using a different encoding:</p> <p><kbd>C</kbd>-<kbd>x</kbd> <kbd>C</kbd>-<kbd>m</kbd> <kbd>f</kbd></p> <p>or force it in situ in the buffer immediately</p> <p><kbd>C</kbd>-<kbd>x</kbd> <kbd>C</kbd>-<kbd>m</kbd> <kbd>c</kbd> <code>utf-8</code> <kbd>Ent</kbd> <kbd>C</kbd>-<kbd>x</kbd> <kbd>C</kbd>-<kbd>w</kbd> <kbd>Ent</kbd></p> <p>Revert a buffer from file using a different coding system:</p> <p><code>revert-buffer-with-coding-system</code></p> <p>or with keybinding</p> <p><kbd>C</kbd>-<kbd>x</kbd> <kbd>Ent</kbd> <kbd>r</kbd></p> <ul> <li> <p>References</p> <p>http://emacswiki.org/emacs/ChangingEncodings</p> <p> http://www.gnu.org/software/emacs/manual/html_node/emacs/Specify-Coding.html</p> </li> </ul> <h2>Editing</h2> <h3>Edit a remote file</h3> <p>Press keys <kbd>C</kbd>-<kbd>x</kbd> <kbd>C</kbd>-<kbd>f</kbd> to bring cursor into the Emacs mini-buffer, type</p> <pre><code>/ssh:username@hostname.com:/path/to/file.txt </code></pre> <p>and <kbd>Ent</kbd>.</p> <h2>Customization</h2> <p><kbd>M</kbd>-<kbd>x</kbd> <code>customize-group</code> <kbd>Ent</kbd> <code>whitespace</code> <kbd>Ent</kbd> to enter into a buffer to customize <code>whitespace</code> mode options.</p> <h2>Modes that I use often</h2> <h3><code>mediawiki-mode</code></h3> <ul> <li><kbd>C</kbd>-<kbd>F5</kbd>: open new page.</li> <li><kbd>A</kbd>-<kbd>g</kbd>: refresh buffer with remote content, discarding local changes.</li> </ul> <h3>erc mode to chat in IRC</h3> <pre><code>M-x erc-select ... /join #haskell </code></pre> <h2>Note</h2> <ul> <li> <p><kbd>C</kbd>- is <kbd>Ctrl</kbd>- in most cases.</p> </li> <li> <p><kbd>M</kbd>- is <kbd>Alt</kbd>- in most cases.</p> </li> <li> <p>In Emacs <code>^J</code> is newline character.</p> </li> </ul> <h2>See also</h2> <ul> <li><span class="createlink">Key bindings of Emacs</span></li> </ul> <h2>References</h2> <ul> <li><a href= "http://www.gnu.org/s/emacs/manual/html_node/elisp/Regexp-Backslash.html#Regexp-Backslash"> 34.3.1.3 Backslash Constructs in Regular Expressions, GNU Emacs manual</a></li> <li><a href= "http://www.gnu.org/software/emacs/manual/html_node/emacs/Query-Replace.html"> 19.9.4 Query Replace, GNU Emacs manual</a> * [http://elpa.gnu.org/packages/ GNU Emacs Lisp Package Archive (ELPA) packages]. This *is standard Emacs' built-in repository of FSF sanctioned Emacs packages.</li> </ul> <h2>External links</h2> Examples of using ffmpeg http://meng6net.localhost/computing/example/examples_of_using_ffmpeg/ http://meng6net.localhost/computing/example/examples_of_using_ffmpeg/ Tue, 16 May 2017 23:59:39 +0000 2020-01-07T21:55:25Z <h2>Convert mp4 to avi</h2> <pre><code>$ ffmpeg -i infile.mp4 outfile.avi </code></pre> <h2>Resize a video or image</h2> <p>Resize a video such that its width is 1080 pixels and the aspect ratio is maintained, hence the height parameter is <code>-1</code>:</p> <pre><code>$ ffmpeg -i input.mp4 -vf scale=1080:-1 output.mp4 </code></pre> <h2>Convert to a specificed bitrate</h2> <pre><code>$ ffmpeg -i input.avi -b 64k output.avi </code></pre> <h2>Convert WAV audio file to MP3 format at a specified audio bitrate</h2> <pre><code>$ ffmpeg -i input.wav -acodec mp3 -ab 128k output.mp3 </code></pre> <h2>Convert mp3 audio file to Orbvis format at a specified audio bitrate</h2> <pre> <code>$ ffmpeg -i input.mp3 -acodec libvorbis -crf 15 output.ogg </code></pre> <ul> <li><code>-crf</code>: Use <a href= "https://web.archive.org/save/https://trac.ffmpeg.org/wiki/Encode/H.264"> Constant Rate Factor</a> to keep the best quality and don't care about the file size. The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible.</li> </ul> <h2>Convert avi file to specified audio sampling rate (22050 Hz), audio bitrate (32 kbps), and frame size (640x480)</h2> <pre> <code>$ ffmpeg -i input.avi -ar 22050 -ab 32 -s 640×480 video.mp4 </code></pre> <p>One can use named frame sizes such as</p> <pre><code>-s vga </code></pre> <h2>Combine multiple files into one file</h2> <pre> <code>$ ffmpeg -safe 0 -f concat -i ./my_file_list.txt -c copy output_file.mp3 </code></pre> <p><code>my_file_list.txt</code> is</p> <pre><code># some comment file './part_file_1.mp3' file './part_file_2.mp3' file './part_file_3.mp3' </code></pre> <h2>Trim a video or audio according to starting and ending times</h2> <pre> <code>ffmpeg -ss hh:mm:ss -to hh:mm:ss -i 'input.mp4' -c copy output.mp4 </code></pre> <h2>Options</h2> <h3>See formats and codecs available on your computer</h3> <pre><code>$ ffmpeg -formats </code></pre> <h2>References</h2> <ul> <li> https://opensource.com/article/17/6/ffmpeg-convert-media-file-formats</li> <li><a href="http://www.mygnulinux.com/?p=56">Converting video &amp; audio files using ffmpeg in GNU/Linux</a></li> <li><a href="http://ffmpeg.org/ffmpeg.html#Main-options">ffmpeg.org documentation: main options</a></li> <li><a href= "http://ffmpeg.org/ffmpeg.html#Video-Options">ffmpeg.org documentation: video options</a></li> <li><a href= "http://ffmpeg.org/ffmpeg.html#Audio-Options">ffmpeg.org documentation: audio options</a></li> </ul> <h2>External links</h2> Examples of using find http://meng6net.localhost/computing/example/examples_of_using_find/ http://meng6net.localhost/computing/example/examples_of_using_find/ Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Basic examples</h2> <h3>Find files by name</h3> <p>Find files in current path and its subdirectories which has <code>FooBar</code> in its file name:</p> <pre><code>$ find . -name *FooBar* </code></pre> <p>Allow both <code>FooBar</code> and <code>foobar</code> to be found by ignoring letter case:</p> <pre><code>$ find . -iname *FooBar* </code></pre> <p>or</p> <pre><code>$ find . -iname *foobar* </code></pre> <h3>Find empty directories</h3> <pre><code>find . -type d -empty </code></pre> <h3>Find broken symbolic links</h3> <pre><code>find -L . -type l </code></pre> <p>Remarks:</p> <ul> <li><code>-L</code> option let find resolve/follow symbolic links when possible.</li> <li><code>-type l</code> option selects only symbolic link files.</li> </ul> <p>Only symbolic link files whose destination is missing or itself a symbolic link file will be found.</p> <h3>Find symbolic links matching a pattern</h3> <p>Find in the current path any symbolic link whose name contains <code>'foobar'</code>:</p> <pre><code>find . -lname '*foobar*' </code></pre> <p>Case-insensitive:</p> <pre><code>find . -ilname '*foobar*' </code></pre> <h3>Find duplicate files</h3> <p>In a bash script:</p> <pre><code>#!/usr/bin/env bash FILENAME=`basename $0` DATETIME=`date +%Y%m%d%H%M%S` TMPFILE=`mktemp /tmp/${FILENAME}.${DATETIME}` || exit 1 find . \! -type d -exec cksum {} \; | sort | tee $TMPFILE | cut -f 1,2 -d ' ' | uniq -d | grep -if - $TMPFILE | awk '{print $3}' </code></pre> <p>Comment:</p> <ul> <li> <p><code>-</code> is Bash special character which means redirection from/to stdin or stdout</p> </li> <li> <p><code>tee $TMPFILE</code> copies stdout stream into the temporary file and pass along it through a pipe</p> </li> <li> <p><code>uniq -d</code> keeps the duplicated entries, i.e. files with same checksum value and file size</p> </li> </ul> <h3>Find large backup files to delete to free up disk space</h3> <pre> <code>$ find data -name *~ -size +100000k -exec ls -lhtc '{}' \; -rw-r--r-- 1 foobar _lpoperator 390M May 7 21:30 data/file1.txt~ -rw-r--r-- 1 foobar _lpoperator 253M May 7 21:30 data/file2.txt~ $ find data -name *~ -size +100000k -exec rm -i '{}' \; remove data/file1.txt~? y remove data/file2.txt~? y </code></pre> <h2>Find large files</h2> <p>Say your disk is running out of space and you want to find the large files which potentially can be removed:</p> <pre> <code>$ find -P -O2 . -type f -size +100M -user $USER -exec ls -sh '{}' &gt;&gt; $OUTPUTFILE \; </code></pre> <ul> <li> <p><code>-P</code>: use option to never follow symbolic links</p> </li> <li> <p><code>-O2</code>: use option to apply query optimization level 2, not available for some platforms including macOS 10.6</p> </li> <li> <p><code>.</code>: search in current path</p> </li> <li> <p><code>-type f</code>: test file type is regular file</p> </li> <li> <p><code>-size +100M</code>: test file size is larger than <code>100M</code></p> </li> <li> <p><code>-user $USER</code>: test file owner is <code>$USER</code></p> </li> <li> <p><code>-exec ls -sh '{}' &gt;&gt; $OUTPUTFILE</code>: execute command to save info to file</p> </li> </ul> <h2>Find <code>.DS_Store</code> files and remove them from version control repository</h2> <p>Suppose we use <code>git</code></p> <pre> <code>$ find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch -f rm '.DS_Store' rm 'Computing/.DS_Store' rm 'Computing/Programming/.DS_Store' rm 'Computing/Programming/Cpp/.DS_Store' rm 'Computing/Software/.DS_Store' rm 'Project/.DS_Store' </code></pre> <p>Remarks:</p> <ul> <li> <p><code>-print0</code>: print all output on same line</p> </li> <li> <p><code>-f</code>: to force removal</p> </li> <li> <p><code>--ignore-unmatch</code>: perform removing only if the file is in the Git repository</p> </li> </ul> <h2>Find recently modified files in a directory recursively</h2> <pre> <code>find . -type f -exec stat -f "%m%t%Sm %N" '{}' \; | sort -rn | head -20 | cut -f2- </code></pre> <p>If one installs GNU <code>find</code>, i.e. the <code>findutils</code> package on MacPorts, one can use its <code>-printf</code> option to print access time in sortable form and them sort the lines numerically:</p> <pre><code>gfind . -type f -printf '%A+\t%p\n' | sort -n </code></pre> <p>To remove the annoying fractional seconds parts:</p> <pre> <code>gfind -type f -printf '%A+\t%p\n' | sed 's/\.&lt;span class="createlink"&gt;:digit:&lt;/span&gt;\{10\}//' | sort -n gfind -type f -printf '%A+\t%p\n' | cut --complement -c 20-30 | sort -n </code></pre> <h2>List files in a directory recursively and sort by modification time</h2> <p>Print files and dates:</p> <pre> <code>find . -type f -exec stat -f "%m%t%Sm %N" '{}' \; | sort -rn | head -20 | cut -f2- </code></pre> <p>Print file full paths only:</p> <pre> <code>find "$PWD" -type f -exec stat -f $'%m\t%N' '{}' \; | sort -rn | cut -f2 </code></pre> <h2>Get the total size of files with name matching a given pattern</h2> <pre> <code>find . -name "foobarREGEX.txt" -ls | awk '{total += $7} END {print total}' </code></pre> <h2>Notes</h2> <h2>See also</h2> <h2>References</h2> <h2>External links</h2> Examples of using Gmail http://meng6net.localhost/computing/example/examples_of_using_gmail/ http://meng6net.localhost/computing/example/examples_of_using_gmail/ Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Find emails from some one excluding chats</h2> <p>In the search bar, query</p> <pre><code>from:FOOBAR@gmail.com -is:Chats </code></pre> <p>Find chats with someone:</p> <pre><code>from:FOOBAR@gmail.com is:Chats </code></pre>