<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gighop &#8211; Tech Junk</title>
	<atom:link href="https://gighop.com/author/gighop/feed/" rel="self" type="application/rss+xml" />
	<link>https://gighop.com</link>
	<description>My random corner of the internet</description>
	<lastBuildDate>Sat, 29 Apr 2023 16:09:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
	<item>
		<title>Use base64 to perfectly preserve formatting when copy/pasting between terminals, ssh sessions, serial connections, etc.</title>
		<link>https://gighop.com/__trashed/</link>
					<comments>https://gighop.com/__trashed/#respond</comments>
		
		<dc:creator><![CDATA[gighop]]></dc:creator>
		<pubDate>Sat, 29 Apr 2023 15:47:10 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<guid isPermaLink="false">https://gighop.com/?p=75</guid>

					<description><![CDATA[Credit to Reddit user u/will_try_not_to for this trick. Here&#8217;s another example of &#8220;what&#8217;s old is new again&#8221; &#8211; remember how a long time ago, you]]></description>
										<content:encoded><![CDATA[
<p>Credit to Reddit user <a href="https://www.reddit.com/user/will_try_not_to/" target="_blank" rel="noreferrer noopener">u/will_try_not_to</a> for this trick.</p>



<p>Here&#8217;s another example of &#8220;what&#8217;s old is new again&#8221; &#8211; remember how a long time ago, you interacted with a modem by giving it textual commands, and then it connected you to distant machines, which you also spoke to in text, and when you wanted to send and receive binary files, you had to encode those as text too?</p>



<p>Well, that still works, and the commands needed to encode/decode it are installed by default pretty much everywhere, so that means you can…</p>



<ul class="wp-block-list">
<li>Suppose there&#8217;s some system you connect to through a VPN and then two jump boxes. You&#8217;ve ssh&#8217;d all the way there, but were lazy and didn&#8217;t bother port-forwarding (if that&#8217;s even allowed), and now you need to get a copy of some config file. Instead of copy/pasting it a bit at a time, or trying to make your scrollback buffer and text wrapping cooperate (and still convert tabs to weird numbers of spaces…), you can:</li>
</ul>



<p>on the sending side: <code>cat file.conf | base64</code></p>



<p>Now you don&#8217;t have to worry about formatting at all*! Just copy all the base64 text as a block, and on the receive side: <code>base64 -d > file.conf_from_remote</code></p>



<p>now paste the text, press enter, then ctrl+d when you&#8217;re done, and you have a binary-identical copy of the file on your local system, regardless of how many spaces, newlines, and messed up terminal wrapping you copied.</p>



<ul class="wp-block-list">
<li>The caveat: sometimes you&#8217;ll run into this on decode: &#8220;base64: invalid input&#8221;. In that case, try <code>base64 -di</code> as the decode command &#8211; for some weird reason, certain versions of the base64 utility can&#8217;t even decode their own input by default, because they decide to insert newlines on encode, but barf immediately on any non-base64 character on decode…including newlines. I have seen this behaviour primarily on old Gentoo boxes, Solaris, and ancient versions of CentOS and Red Hat.</li>
</ul>



<ul class="wp-block-list">
<li>Doesn&#8217;t even have to be a remote system of course. I use this sometimes when I can&#8217;t be arsed to deal with <code>sudo</code>/<code>chmod</code>/<code>chown </code>when copying a file between sessions running as different restricted users, or across a chroot, container, VM, etc.</li>
</ul>



<p>Next trick:<br>Suppose you&#8217;re editing a file locally and you want to copy a piece of a remote file, and it&#8217;s very important to exactly preserve the indenting and whitespace (because it&#8217;s python, yaml, or you&#8217;ve forgotten about &#8220;:set paste&#8221; in vim and internalised the notion that auto-indent is forever…but &#8220;set paste&#8221; doesn&#8217;t help you with tabs not surviving a terminal display anyway). You can do this:</p>



<p>shift+V to go to visual select line mode; select the block you want</p>



<p>type <code>:! base64</code> &lt;enter></p>



<p>copy &amp; paste the block into your other vim, then select the base64 text</p>



<p>type <code>:! base64 -d</code> &lt;enter></p>



<p>and there it is, in all its tabular/nonprinting/emoji/16-bit-big-endian-unicode-because-why-not glory. (You&#8217;ll want to undo the encode step on the source system, obviously.)</p>



<p>Don&#8217;t believe me that it&#8217;s 100% binary identical? Select the text blocks on both sides and check:</p>



<p><code>:! md5sum</code></p>



<p>(Incidentally, if the block of text you want is really small or your local one is very similar already, you can skip the base64 and just edit it manually and just use md5sum to confirm you got it right.)</p>



<p><strong>If your file or block of text is longer than a screenful</strong><br>Pipe it to gzip first:</p>



<p><code>cat file.txt | gzip -9 | base64</code></p>



<p><code>base64 -d | gunzip > file.txt_copy</code></p>



<p>(For very small inputs, gzip often produces slightly fewer bytes than xz and even zstd, plus it&#8217;s available practically everywhere.)</p>



<p>You can also scrunch down the base64 a little more by setting the line-width to unlimited (<code>base64 -w 0</code>), but be aware that:</p>



<ul class="wp-block-list">
<li>Some implementations are buggy when it comes to very long lines (the opposite problem of the earlier caveat).</li>
</ul>



<ul class="wp-block-list">
<li>Even if the base64 command is OK with it, sometimes the terminal program isn&#8217;t.</li>
</ul>



<ul class="wp-block-list">
<li>4096 bytes per line is a common threshold at which something barfs.</li>
</ul>



<ul class="wp-block-list">
<li>It can make the copy/pasting more error-prone, as it&#8217;s easier to miss a single character somewhere (and if you accidentally paste it in the wrong place, it makes more of a mess… on the other hand, at least your shell history will only have one bogus entry on accidental paste instead of 150. Ask me how many times I&#8217;ve seen &#8220;<code>-bash: H4sIAAAAAAACAxXJQQ6AIAxE0b2nmJu49RoVxmgiLaFFw+2V3X/5m71IooiTUAakWNeAHaBGszpm: No such file or directory -bash: ztn1etic2Iki7r/ugczUKM68Lh893ENmSgAAAA==: No such file or directory</code>&#8221; :P).</li>
</ul>



<p><strong>Important note for sysadmins and especially network people</strong><br>I mentioned serial connections at the beginning of this. I cannot believe how many times I&#8217;ve see people laboriously copy a few lines at a time, paste them into their terminal window, wait (9600 8 N 1 only goes so fast, y&#8217;all…), copy a few more… and then cross their fingers and pray that no characters got lost, and none of the accidental extra whitespace will matter, when restoring a switch configuration.</p>



<p>The civilised way to do this is to be in shell mode on the switch instead of config mode (and if your switches don&#8217;t have a basic Linux-like shell, consider switching to some that do), and do a base64 copy/paste as described, and then compare checksums. Especially if gzip is available on the switch, this is much, much faster and more reliable, and then you can do a local &#8220;load config&#8221; and not have any terminal issues in config mode.</p>



<p>(Some may argue that transferring over tftp or some variant of DHCP-mediated auto-provision is &#8220;more civilised&#8221;, but 1, you&#8217;re in this situation because your network is buggered so that might not be an option, and 2, I bet if you held a race, the base64 person would be done long before the tftp person has even finished the &#8220;how the crap do I get this server listening again?! why is it not serving files?!&#8221; stage of cursing, never mind the &#8220;I fat-fingered a subnet mask&#8221; or &#8220;oh yeah, we block tftp at the firewall for this subnet now, don&#8217;t we?&#8221; stages of cursing.)</p>



<p><strong>If your remote system is weird and doesn&#8217;t have a base64 command</strong><br>Good chance it still does and it&#8217;s just part of something else. Hint: openssl has it built in (<code>openssl base64</code> is equivalent to <code>base64</code>) if that&#8217;s available (e.g. Juniper switches I think). <code>openssl md5</code> also works if you&#8217;re missing md5sum, but also try just <code>md5</code>, because it&#8217;s called that on some unixes (I want to say Juniper switches again? or Mac OS?).</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gighop.com/__trashed/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Check disk space utilization in Linux</title>
		<link>https://gighop.com/check-disk-space-utilization-in-linux/</link>
					<comments>https://gighop.com/check-disk-space-utilization-in-linux/#respond</comments>
		
		<dc:creator><![CDATA[gighop]]></dc:creator>
		<pubDate>Sun, 13 Dec 2020 22:23:16 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<guid isPermaLink="false">https://gighop.com/?p=25</guid>

					<description><![CDATA[Let&#8217;s say your partition (for example, &#8216;/&#8217;) is getting full, but you don&#8217;t know where to look to take care of the issue. You can]]></description>
										<content:encoded><![CDATA[
<p>Let&#8217;s say your partition (for example, &#8216;/&#8217;) is getting full, but you don&#8217;t know where to look to take care of the issue. You can run the following that will give you a list of the directories sorted from the largest to smallest in GiB:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:false,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">du -h / --max-depth 5 | grep -P '^[0-9\.]+G' | sort -n -r</pre></div>



<p>The output of the command will look something like this:</p>



<pre class="wp-block-code"><code>17G     /
8.2G    /home
4.8G    /usr
2.2G    /usr/local/cpanel
2.2G    /usr/local
1.3G    /run/log/journal/8936098ee7011e65401ba43c5f52e098
1.3G    /run/log/journal
1.3G    /run/log
1.3G    /run
1.1G    /var
1.1G    /backup</code></pre>



<p>In my case, I ran this from a server that doesn&#8217;t have much installed, but you get the idea. By default this command will check the &#8216;/&#8217; partition/directory (du -h /), iterate 5 levels deep (&#8211;max-depth 5), and only display directories that are at least 1GiB in size (grep -P &#8216;^[0-9.]+G&#8217;).  You can change up the values to fine tune the output to your needs. For example, lets say you want to start at the current directory, show 2 levels deep, and only show directories that are at least 1MiB in size, but under 1GiB:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:false,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}">du -h . --max-depth 2 | grep -P '^[0-9\.]+M' | sort -n -r</pre></div>



<p>In this case, I was within &#8216;/backup&#8217;, so the output would look like this:</p>



<pre class="wp-block-code"><code>555M    ./2020-12-13
514M    ./2020-12-13/accounts
503M    ./monthly/2020-12-01
503M    ./monthly
41M     ./2020-12-13/system
12M     ./.meta</code></pre>



<p>This is a very useful command that I personally utilize just about every day. Let me know how useful this has been for you in the comments.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gighop.com/check-disk-space-utilization-in-linux/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>First!</title>
		<link>https://gighop.com/first/</link>
					<comments>https://gighop.com/first/#respond</comments>
		
		<dc:creator><![CDATA[gighop]]></dc:creator>
		<pubDate>Sat, 12 Dec 2020 13:56:56 +0000</pubDate>
				<category><![CDATA[Rant]]></category>
		<guid isPermaLink="false">https://gighop.com/?p=19</guid>

					<description><![CDATA[This is the first post on my site. As is tradition, there is no useful information here.]]></description>
										<content:encoded><![CDATA[
<p>This is the first post on my site. As is tradition, there is no useful information here.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gighop.com/first/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
