<?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>command line &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/command-line/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Fri, 25 Apr 2025 08:00:45 +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>command line &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[Use WP CLI to find all blog posts without a featured image - two methods]]></title>
		<link>https://shkspr.mobi/blog/2023/10/use-wp-cli-to-find-all-blog-posts-without-a-featured-image-two-methods/</link>
					<comments>https://shkspr.mobi/blog/2023/10/use-wp-cli-to-find-all-blog-posts-without-a-featured-image-two-methods/#respond</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Tue, 10 Oct 2023 11:34:15 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=47413</guid>

					<description><![CDATA[This uses the wp shell command. It gives you an interactive prompt into which you can do various WordPress &#34;things&#34;.  One small annoyance is that it doesn&#039;t like multi-line entry. It treats every hit of the enter key as &#34;plz run the codez&#34; - so, at the end of this blog post, I&#039;ve put the commands in copy-n-paste format.  Once you&#039;ve installed WP CLIP, go to the command line and run wp shell.…]]></description>
										<content:encoded><![CDATA[<p>This uses <a href="https://developer.wordpress.org/cli/commands/shell/">the <code>wp shell</code> command</a>. It gives you an interactive prompt into which you can do various WordPress "things".</p>

<p>One small annoyance is that it doesn't like multi-line entry. It treats every hit of the enter key as "plz run the codez" - so, at the end of this blog post, I've put the commands in copy-n-paste format.</p>

<p>Once you've installed WP CLIP, go to the command line and run <code>wp shell</code>. You'll be greeted with an interactive prompt <code>wp&gt;</code></p>

<h2 id="method-one-quick-search"><a href="https://shkspr.mobi/blog/2023/10/use-wp-cli-to-find-all-blog-posts-without-a-featured-image-two-methods/#method-one-quick-search">Method One - Quick Search</a></h2>

<p>This command constructs a query which gets <em>all</em> posts, which have been published, where there is no thumbnail ID.  Note - this isn't quite the same as not having a featured image.</p>

<pre><code class="language-php">$args = array(
    'post_type'     =&gt; 'post',
    'post_status'   =&gt; array('publish'),
    'posts_per_page'=&gt; -1,
    'meta_query'    =&gt; array(
        array(
            'key' =&gt; '_thumbnail_id',
            'compare' =&gt; 'NOT EXISTS'
        )
    ),
);
</code></pre>

<p>Next we run that query. It will dump quite a lot of information into the screen, we'll format it shortly.</p>

<pre><code class="language-php">$query = new WP_Query( $args );
</code></pre>

<p>Finally, we loop through all the posts the query has found and print them out in a nice format.</p>

<pre><code class="language-php">$posts = $query-&gt;posts;
foreach ( $posts as $post ) {
    echo $post-&gt;post_date . " " . $post-&gt;guid . " " . $post-&gt;post_title . "\n";
}
</code></pre>

<p>That will give you the date, link, and title of every post where there is no featured image set.</p>

<h3 id="copy-and-paste-snippet"><a href="https://shkspr.mobi/blog/2023/10/use-wp-cli-to-find-all-blog-posts-without-a-featured-image-two-methods/#copy-and-paste-snippet">Copy and Paste Snippet</a></h3>

<pre><code class="language-php">$args = array( 'post_type' =&gt; 'post', 'post_status' =&gt; array('publish'), 'posts_per_page'=&gt; -1,  'meta_query' =&gt; array(       array( 'key' =&gt; '_thumbnail_id', 'value' =&gt; '?', 'compare' =&gt; 'NOT EXISTS' ) ),);
$query = new WP_Query( $args );
$posts = $query-&gt;posts;
foreach ( $posts as $post ) { echo $post-&gt;post_date . " " . $post-&gt;guid . " " . $post-&gt;post_title . "\n"; }
</code></pre>

<h2 id="method-two-full-search"><a href="https://shkspr.mobi/blog/2023/10/use-wp-cli-to-find-all-blog-posts-without-a-featured-image-two-methods/#method-two-full-search">Method Two - Full Search</a></h2>

<p>Sometimes the WordPress database can get a little confused. It will say there is a post thumbnail, but when you try to retrieve it, there's nothing there!</p>

<p>This method is slightly slower if you have lots of posts. It goes through every single post and checks whether the featured image can be retrieved. If not it will let you know.</p>

<pre><code class="language-php">$args = array(
    'post_type'     =&gt; 'post',
    'post_status'   =&gt; array('publish'),
    'posts_per_page'=&gt; -1,
);

$posts = get_posts( $args );

foreach ( $posts =&gt; $post) {
    if( get_the_post_thumbnail( $post ) == "" ) {
        echo $post-&gt;post_date . " " . $post-&gt;guid . " " . $post-&gt;post_title . "\n"; }
}
</code></pre>

<h3 id="copy-and-paste-snippet"><a href="https://shkspr.mobi/blog/2023/10/use-wp-cli-to-find-all-blog-posts-without-a-featured-image-two-methods/#copy-and-paste-snippet">Copy and Paste Snippet</a></h3>

<pre><code class="language-php">foreach (get_posts( array( 'post_type' =&gt; 'post', 'post_status' =&gt; array('publish'), 'posts_per_page' =&gt; -1,) ) as $post) { if(get_the_post_thumbnail($post)== "") { echo $post-&gt;post_date . " " . $post-&gt;guid . " " . $post-&gt;post_title . "\n"; } }
</code></pre>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=47413&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2023/10/use-wp-cli-to-find-all-blog-posts-without-a-featured-image-two-methods/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[Generating Random Chiptunes on Linux]]></title>
		<link>https://shkspr.mobi/blog/2016/04/generating-random-chiptunes-on-linux/</link>
					<comments>https://shkspr.mobi/blog/2016/04/generating-random-chiptunes-on-linux/#respond</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Mon, 25 Apr 2016 13:46:36 +0000</pubDate>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=22790</guid>

					<description><![CDATA[I like to listen to music while I work. I find - especially in an open plan office - that it is an essential aid to concentration.  That said, I find music with lyrics particularly problematic as my brain prefers to concentrate on the words rather than the task in hand.  On long flights, I often use a white noise generator to drown out sound.  I&#039;ve recently started listening to random music.  A…]]></description>
										<content:encoded><![CDATA[<p>I like to listen to music while I work. I find - <a href="https://web.archive.org/web/20160519204613/https://tommorris.org/tag/open%20plan">especially in an open plan office</a> - that it is an essential aid to concentration.</p>

<p>That said, I find music with lyrics particularly problematic as my brain prefers to concentrate on the words rather than the task in hand.</p>

<p>On long flights, I often use a <a href="https://f-droid.org/en/packages/net.pmarks.chromadoze/">white noise generator</a> to drown out sound.</p>

<p>I've recently started listening to random music.  A simple command line script to generate a highly synthetic / chiptune / glitchnoise neverending piece of music.</p>

<p>This code is <em>shamelessly</em> ripped off from <a href="http://blog.robertelder.org/bash-one-liner-compose-music/">Robert Elder's blog post</a> and the subsequent <a href="https://news.ycombinator.com/item?id=11238247">HackerNews discussion</a></p>

<pre><code class="language-bash">cat /dev/urandom | \
   hexdump -v -e '/1 "%u\n"' | \
   awk '{ split("0,3,5,6,7,10,12",a,","); \
   for (i = 0; i &lt; 1; i+= 0.0001) \
   printf("%08X\n", 100*sin(1382*exp((a[$1 % 8]/12)*log(2))*i)) }' | \
   xxd -r -p | \
   aplay -c 2 -f S32_LE -r 24000
</code></pre>

<p>Copy &amp; paste that into your Ubuntu terminal and it should sound something like this:
</p>

<p>I don't know enough music theory or maths to determine what will sound pleasant and what won't.  But a little bit of fiddling got me this jaunty little number:</p>

<pre><code class="language-bash">cat /dev/urandom | \
   hexdump -v -e '/1 "%u\n"' | \
   awk '{ split("0,1,2,4,8",a,","); \
   for (i = 0; i &lt; 1; i+= 0.0001) \
   printf("%08X\n", 100*sin(1382*exp((a[$1 % 8]/12)*log(2))*i)) }' | \
   xxd -r -p | \
   aplay -c 2 -f S32_LE -r 30000
</code></pre>

<p>It's not quite up to the standards of Daft Punk - but it covers up the noise of the office and allows me to concentrate without (audible) distraction.</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=22790&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2016/04/generating-random-chiptunes-on-linux/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
