<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Command-Line on blog.iankulin.com</title><link>https://blog.iankulin.com/tags/command-line/</link><description>Recent content in Command-Line on blog.iankulin.com</description><generator>Hugo</generator><language>en-AU</language><lastBuildDate>Sun, 23 Apr 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://blog.iankulin.com/tags/command-line/index.xml" rel="self" type="application/rss+xml"/><item><title>Why use './' in front of filenames?</title><link>https://blog.iankulin.com/why-use-in-front-of-filenames/</link><pubDate>Sun, 23 Apr 2023 00:00:00 +0000</pubDate><guid>https://blog.iankulin.com/why-use-in-front-of-filenames/</guid><description>&lt;p&gt;In Linux (and MS-DOS I guess) the period signifies the current directory, so if I have a file in the current directory called &lt;code&gt;test.txt&lt;/code&gt;, I can refer to it as &lt;code&gt;test.txt&lt;/code&gt; or &lt;code&gt;./test.txt&lt;/code&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ian@enrico-rider:~$ cat test.txt
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;test
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ian@enrico-rider:~$ cat ./test.txt
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;test
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I mostly see this in references to files in HTML and have often wondered why. Here it is being used in a Udemy course I&amp;rsquo;m following.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-04-19-at-10.49.00-am.jpg" alt=""&gt;&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s one of those things that&amp;rsquo;s difficult to Google, so these days my reflex is to ask ChatGPT such questions.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://blog.iankulin.com/images/screen-shot-2023-04-19-at-11.17.53-am.png"&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-04-19-at-11.17.53-am.png" width="800" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Okay. That makes sense for executable files. If you just type in the name, Linux will look in the current directory, then if not found, in each of the directories in your $PATH variable. But if you add the ./ to the front, it will only look in your current directory. This claim of ChatGPT&amp;rsquo;s is easily tested, lets try with &lt;code&gt;cat&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ian@enrico-rider:~$ cat test.txt
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;test
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ian@enrico-rider:~$ ./cat test.txt
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-bash: ./cat: No such file or directory
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ian@enrico-rider:~$ cp /usr/bin/cat cat
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ian@enrico-rider:~$ ./cat test.txt
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;test
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So that checks out, but it doesn&amp;rsquo;t explain the main place I see it - in HTML.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-04-19-at-12.00.12-pm.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Again, that makes sense. But it still doesn&amp;rsquo;t answer why the instructor in my course is using it for:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cp /etc/passwd ./users.txt
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-04-19-at-12.06.52-pm.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Lol - I feel this is a real edge case. I can see it being more a problem with the first file rather than the second one. eg.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://blog.iankulin.com/images/screen-shot-2023-04-19-at-12.21.05-pm.png"&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-04-19-at-12.21.05-pm.png" width="800" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So, TL:DR; using &amp;lsquo;./&amp;rsquo; in front of a filename can be useful when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;executing a shell script in the current directory (to avoid ambiguity with other executable files in your PATH);&lt;/li&gt;
&lt;li&gt;when running a command that takes filenames as arguments, and the filename might be confused with an argument;&lt;/li&gt;
&lt;li&gt;in HTML to avoid confusion between the directory the current file is in and the root directory of the web server.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Recursively Deleting Files in Linux</title><link>https://blog.iankulin.com/recursively-deleting-files-in-linux/</link><pubDate>Fri, 14 Apr 2023 00:00:00 +0000</pubDate><guid>https://blog.iankulin.com/recursively-deleting-files-in-linux/</guid><description>&lt;p&gt;I&amp;rsquo;ve been using this rsync command to backup files from my NAS to a USB drive. The &amp;ndash;excludes are to avoid copying over some junk hidden files - some created by MacOS and some by Synology.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sudo rsync -rvit --exclude &amp;#39;*@eaDir*&amp;#39; --exclude &amp;#39;.DS_Store&amp;#39; /volume1/media/ /volumeUSB1/usbshare1-2/media --del
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;.DS_Store&lt;/code&gt; files seem to be dropped by MacOS every time I view a directory on the NAS from my MacBook. They&amp;rsquo;re not doing any harm, and they presumably do something handy for the Mac - remembering the view settings for that folder or some such. Nevertheless, they annoy me. It makes sense to not back them up - they don&amp;rsquo;t serve any useful purpose in that context.&lt;/p&gt;
&lt;p&gt;If I wanted to delete them anyway, how would I go about it? They are scattered randomly around, including in sub-directories of sub-directories. Is there some recursive flag I can add to &lt;code&gt;rm&lt;/code&gt; to accomplish this?&lt;/p&gt;
&lt;p&gt;I found a better solution on &lt;a href="https://askubuntu.com/questions/377438/how-can-i-recursively-delete-all-files-of-a-specific-extension-in-the-current-di"&gt;AskUbuntu&lt;/a&gt;, we can use the &lt;code&gt;find&lt;/code&gt; command. This way it&amp;rsquo;s easy to safely test your filename matching first before you destroy any files.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;find . -name &amp;#34;.DS_Store&amp;#34; -type f
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;-name&lt;/code&gt; is clear enough, and the &lt;code&gt;-type f&lt;/code&gt; option is just saying to look for files (rather than directories etc). The period at the start is the location, ie, start in the directory above so the current working directory is included. Once you&amp;rsquo;ve tuned this, you can add &lt;code&gt;-delete&lt;/code&gt; to go nuclear.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;find . -name &amp;#34;.DS_Store&amp;#34; -type f -delete
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item></channel></rss>