<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<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>bash &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Tue, 18 Mar 2025 09:36:14 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>bash &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[Reboot and launch an Android app via ADB]]></title>
		<link>https://shkspr.mobi/blog/2022/02/reboot-and-launch-an-android-app-via-adb/</link>
					<comments>https://shkspr.mobi/blog/2022/02/reboot-and-launch-an-android-app-via-adb/#respond</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Thu, 10 Feb 2022 12:34:34 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[linux]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=41844</guid>

					<description><![CDATA[I&#039;m using an old Android phone as a webcam. The camera lens is great, the DroidCam software is nifty, but the Android OS behind it is old and dying. My phone often needs rebooting. Which means that the app also needs restarting.  The phone&#039;s screen faces away from me, so I can&#039;t interact with it.  This is a quick guide (mostly notes to myself) about rebooting and starting an app from the command…]]></description>
										<content:encoded><![CDATA[<p>I'm using an old Android phone as a webcam. The camera lens is great, the DroidCam software is nifty, but the Android OS behind it is old and dying. My phone often needs rebooting. Which means that the app also needs restarting.  The phone's screen faces away from me, so I can't interact with it.</p>

<p>This is a quick guide (mostly notes to myself) about rebooting and starting an app from the command line.</p>

<p>To find the package name, run</p>

<pre><code class="language-bash">adb shell pm list packages -f | grep -i PackageName
</code></pre>

<p>In my case, the package is called <code>com.dev47apps.droidcamx</code></p>

<p>To launch an app from your computer's shell, run</p>

<pre><code class="language-bash">adb shell monkey -p com.dev47apps.droidcamx 1
</code></pre>

<p>You can read more about the <a href="https://developer.android.com/studio/test/monkey">Android Test Monkey</a>.</p>

<p>Putting it all together in a shell script is as simple as:</p>

<pre><code class="language-bash">adb reboot
sleep 60
adb shell monkey -p com.dev47apps.droidcamx 1
</code></pre>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=41844&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2022/02/reboot-and-launch-an-android-app-via-adb/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[Convert Surround Sound WAV albums to individual opus files]]></title>
		<link>https://shkspr.mobi/blog/2018/03/convert-surround-sound-wav-albums-to-individual-opus-files/</link>
					<comments>https://shkspr.mobi/blog/2018/03/convert-surround-sound-wav-albums-to-individual-opus-files/#respond</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Sun, 18 Mar 2018 18:38:16 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[flac]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[opus]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=29185</guid>

					<description><![CDATA[As ever, notes to myself.  This is a method to take a .wav and .cue and transform it into individual files. In this case, .opus.  Transform to .flac  FLAC is a good intermediary file format, especially for surround sound files.  avconv -i file.wav out.flac  Transform to .opus  An optional step if you want smaller files. Maximum quality for 6 channel audio.  opusenc --bitrate 4096 out.flac…]]></description>
										<content:encoded><![CDATA[<p>As ever, notes to myself.  This is a method to take a <code>.wav</code> and <code>.cue</code> and transform it into individual files. In this case, <code>.opus</code>.</p>

<h3 id="transform-to-flac"><a href="https://shkspr.mobi/blog/2018/03/convert-surround-sound-wav-albums-to-individual-opus-files/#transform-to-flac">Transform to <code>.flac</code></a></h3>

<p>FLAC is a good intermediary file format, especially for surround sound files.</p>

<p><code>avconv -i file.wav out.flac</code></p>

<h3 id="transform-to-opus"><a href="https://shkspr.mobi/blog/2018/03/convert-surround-sound-wav-albums-to-individual-opus-files/#transform-to-opus">Transform to <code>.opus</code></a></h3>

<p>An optional step if you want smaller files.
Maximum quality for 6 channel audio.</p>

<p><code>opusenc --bitrate 4096 out.flac out.opus</code></p>

<h3 id="create-an-mkv"><a href="https://shkspr.mobi/blog/2018/03/convert-surround-sound-wav-albums-to-individual-opus-files/#create-an-mkv">Create an <code>.mkv</code></a></h3>

<p>Add to an MKV with all the chapter information.</p>

<p><code>mkvmerge -o test.mkv --chapters file.cue out.opus</code></p>

<h3 id="split-to-individual-files"><a href="https://shkspr.mobi/blog/2018/03/convert-surround-sound-wav-albums-to-individual-opus-files/#split-to-individual-files">Split to individual files</a></h3>

<p>Individual MKVs</p>

<p><code>mkvmerge test.mkv --split chapters:all -o track.mkv</code></p>

<h3 id="extract-the-audio"><a href="https://shkspr.mobi/blog/2018/03/convert-surround-sound-wav-albums-to-individual-opus-files/#extract-the-audio">Extract the Audio</a></h3>

<p>One at a time:</p>

<p><code>mkvextract tracks "track-001.mkv" 0:"individual.opus"</code></p>

<h2 id="all-in-one-bash-script"><a href="https://shkspr.mobi/blog/2018/03/convert-surround-sound-wav-albums-to-individual-opus-files/#all-in-one-bash-script">All-In-One  bash script</a></h2>

<pre><code class="language-bash">#!/bin/bash
json=$(ffprobe -i "file.mkv" -print_format json -show_chapters -loglevel error)
count=$(echo $json | jq ".chapters | length" )

mkvmerge test.mkv -D -S --split chapters:all -o "%02d.mkv"

COUNTER=1
while [ $COUNTER -le $count ]; do

  printf -v zerotrack "%02d" $COUNTER

  json=$(ffprobe -i "$zerotrack.mkv" -print_format json -show_chapters -loglevel error)
  title=$(echo $json | jq ".chapters[0].tags.title" -r)
  filename="[$zerotrack] $title"

  mkvextract tracks "$zerotrack.mkv" 0:"$filename.opus"
  let COUNTER=COUNTER+1 
done
</code></pre>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=29185&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2018/03/convert-surround-sound-wav-albums-to-individual-opus-files/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[Sort Folders Into Alphabetic Sub-Folders]]></title>
		<link>https://shkspr.mobi/blog/2017/01/sort-folders-into-alphabetic-sub-folders/</link>
					<comments>https://shkspr.mobi/blog/2017/01/sort-folders-into-alphabetic-sub-folders/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Mon, 02 Jan 2017 10:01:35 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tutorial]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=24553</guid>

					<description><![CDATA[Scratching my own itch.  I have a bunch of directories which I want moved into alphabetic sub-directories.  This is handy is you have a bunch of MP3s, books, or other catalogued files.  This bash script moves a top level directory (and all the files and subdirectories under it), to a folder based on the (upper-case) version of the first character of the directory name.  #!/bin/bash for dir in */…]]></description>
										<content:encoded><![CDATA[<p>Scratching my own itch.  I have a bunch of directories which I want moved into alphabetic sub-directories.  This is handy is you have a bunch of MP3s, books, or other catalogued files.</p>

<p>This bash script moves a top level directory (and all the files and subdirectories under it), to a folder based on the (upper-case) version of the first character of the directory name.</p>

<pre><code>#!/bin/bash
for dir in */ ; do
    start=${dir:0:1}
    mkdir -p ${start^^}
    mv "$dir" ${start^^}
done
</code></pre>

<p>Save that as <code>sort.sh</code>, make it executable with <code>chmod +x sort.sh</code> and run with <code>./sort.sh</code></p>

<p>It turns this:</p>

<pre><code>.
├── Adella
├── adrianna
├── Barb
├── bebe
├── Carleen
├── catherina
</code></pre>

<p>Into:</p>

<pre><code>.
├── A
│&nbsp;&nbsp; ├── Adella
│&nbsp;&nbsp; ├── adrianna
├── B
│&nbsp;&nbsp; ├── Barb
│&nbsp;&nbsp; └── bebe
├── C
 &nbsp;&nbsp; ├── Carleen
 &nbsp;&nbsp; ├── catherina
</code></pre>

<h2 id="how-it-works"><a href="https://shkspr.mobi/blog/2017/01/sort-folders-into-alphabetic-sub-folders/#how-it-works">How it works</a></h2>

<p>Let's break this down to see what everything does</p>

<ul>
<li><code>for dir in */ ; do</code></li>
<li>This loops through the current directory and finds every item which <em>ends</em> with a <code>/</code> - that is, all directories</li>
</ul>

<p>&nbsp;</p>

<ul>
<li><code>start=${dir:0:1}</code></li>
<li>Grab a <a href="http://www.tldp.org/LDP/abs/html/string-manipulation.html">sub-string</a> from the directory name. In this case, the first character.</li>
</ul>

<p>&nbsp;</p>

<ul>
<li><code>mkdir -p ${start^^}</code></li>
<li>Make a directory, <a href="http://superuser.com/questions/165157/what-does-mkdir-p-flag-do">use the <code>-p</code> flag to make sure we don't get an error when trying to create a duplicate directory</a>. The <a href="http://aty.sdsu.edu/bibliog/latex/debian/bash.html"><code>^^</code> command makes things upper case</a>.</li>
</ul>

<p>&nbsp;</p>

<ul>
<li><code>mv "$dir" ${start^^}</code></li>
<li>Move the directory we found into the newly created directory.</li>
</ul>

<p>&nbsp;</p>

<ul>
<li><code>done</code></li>
<li>Finish the loop</li>
</ul>

<h2 id="warnings"><a href="https://shkspr.mobi/blog/2017/01/sort-folders-into-alphabetic-sub-folders/#warnings">Warnings</a></h2>

<ul>
<li>Only works with folders - it won't move any files in your top level directory.</li>
<li>Non-ASCII characters are supported. For example, <code>你好</code> is sorted into <code>你</code>.</li>
<li>Handles directories with spaces, punctuation, and numbers at the start.</li>
<li>No doubt there is some horrific bug lurking in those half-dozen lines. Be a friend and drop me a note in the comments, would you?</li>
</ul>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=24553&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2017/01/sort-folders-into-alphabetic-sub-folders/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
