<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Commands on Aamnah - Frontend Web Developer</title>
    <link>https://aamnah.com/notes/commands/</link>
    <description>Recent content in Commands on Aamnah - Frontend Web Developer</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 06 Jun 2024 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://aamnah.com/notes/commands/rss.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Copy contents to clipboard form command line (Ubuntu, macOS)</title>
      <link>https://aamnah.com/notes/commands/xclip-pbcopy-copy-file-contents-to-clipboard/</link>
      <pubDate>Mon, 26 Jul 2021 12:07:12 +0500</pubDate>
      <guid>https://aamnah.com/notes/commands/xclip-pbcopy-copy-file-contents-to-clipboard/</guid>
      <description>&lt;h4 id=&#34;macos&#34;&gt;macOS&lt;/h4&gt;&#xA;&lt;p&gt;macOS comes with &lt;code&gt;pbcopy&lt;/code&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;pbcopy &amp;lt; ~/.ssh/id_rsa.pub&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# or &lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;cat ~/.ssh/id_rsa.pub &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; pbcopy&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;ubuntu&#34;&gt;Ubuntu&lt;/h4&gt;&#xA;&lt;p&gt;On Ubuntu you can use &lt;code&gt;xclip&lt;/code&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;sudo apt install xclip&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;xclip -selection clipboard -i &amp;lt; inputFile&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# xclip -sel c &amp;lt; inputFile&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;clipboard&lt;/code&gt; is a parameter for &lt;code&gt;-selection&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;-i&lt;/code&gt; means inoput (standard input or file). Since &lt;em&gt;file&lt;/em&gt; is default, you can omit the &lt;code&gt;-i&lt;/code&gt; in most cases&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;-i, -in&#xA;      read text into X selection from standard input or files (default)&#xA;&#xA;-o, -out&#xA;      print the selection to standard out (generally for piping to a file or program)&#xA;&#xA;-selection&#xA;      specify which X selection to use, options are &amp;#34;primary&amp;#34; to use XA_PRIMARY (default), &amp;#34;secondary&amp;#34; for XA_SECONDARY or &amp;#34;clipboard&amp;#34; for XA_CLIPBOARD&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: &lt;code&gt;xclip&lt;/code&gt; and &lt;code&gt;xsel&lt;/code&gt; are X11 utilities, they manipulate the X11 selections, so can only be used in a X11 environment where &lt;code&gt;$DISPLAY&lt;/code&gt; is set. Running in a terminal only context (e.g. WSL or headless) will give you this error:&lt;/p&gt;</description>
    </item>
    <item>
      <title>[gcp --parents] Copy selected files and recreate folder structure</title>
      <link>https://aamnah.com/notes/commands/copy-files-recreate-folder-structure/</link>
      <pubDate>Fri, 23 Jun 2017 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/commands/copy-files-recreate-folder-structure/</guid>
      <description>&lt;h3 id=&#34;why&#34;&gt;Why?&lt;/h3&gt;&#xA;&lt;p&gt;Makes it easier to copy a default OpenCart extension. Find the files by name and copy them while also creating the required folder structure.&lt;/p&gt;&#xA;&lt;h3 id=&#34;how&#34;&gt;How&lt;/h3&gt;&#xA;&lt;p&gt;Use the &lt;code&gt;cp&lt;/code&gt; command with &lt;code&gt;--parents&lt;/code&gt; flag.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;cp --parents admin/controller/extension/payment/bank_transfer.php easypaisa/&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Won&amp;rsquo;t work on macOS by default, so &lt;code&gt;brew install coreutils&lt;/code&gt; first and then use &lt;code&gt;gcp&lt;/code&gt; instead of &lt;code&gt;cp&lt;/code&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;gcp --parents admin/controller/extension/payment/bank_transfer.php easypaisa/&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;easypaisa&#xA;└── admin&#xA;    └── controller&#xA;        └── extension&#xA;            └── payment&#xA;                └── bank_transfer.php&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;&#xA;&lt;h3 id=&#34;extractclone-an-opencart-extension-with-one-command&#34;&gt;Extract/Clone an OpenCart Extension with one command&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;find . -iname &lt;span class=&#34;s1&#34;&gt;&amp;#39;bank_transfer.*&amp;#39;&lt;/span&gt; -exec gcp --parents &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; foo/ &lt;span class=&#34;se&#34;&gt;\;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;{}&lt;/code&gt; will be replaced with the path name of the file. The last token, &lt;code&gt;\;&lt;/code&gt; is there only to mark the end of the exec expression. &lt;code&gt;foo&lt;/code&gt; is the directory you&amp;rsquo;re assumed to have created before running the command&lt;/p&gt;</description>
    </item>
    <item>
      <title>[grep, sed] Find and Replace string in multiple files</title>
      <link>https://aamnah.com/notes/commands/grep-sed-find-and-replace-string-in-multiple-files/</link>
      <pubDate>Wed, 06 Jan 2016 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/commands/grep-sed-find-and-replace-string-in-multiple-files/</guid>
      <description>&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# replace all htttp://link to https://link in all files&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;grep -rl &lt;span class=&#34;s1&#34;&gt;&amp;#39;http://&amp;#39;&lt;/span&gt; ./ &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; xargs sed -i &lt;span class=&#34;s1&#34;&gt;&amp;#39;s|http://|https://|g&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# if filenames have spaces, blanks or new lines&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;grep -rl --null mangoes/ . &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; xargs -0 sed -i &lt;span class=&#34;s1&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;s/mangoes/oranges/g&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;why&#34;&gt;why?&lt;/h2&gt;&#xA;&lt;p&gt;Here&amp;rsquo;s the scenario, i exported some files for this blog from a software that used a different image folder structure. Lots of new files with different links. So i needed a way to&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;find all the files spanning multiple directories containing a specific string&lt;/li&gt;&#xA;&lt;li&gt;edit (in place) all them files found in multiple directories and replace it with new string&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Basically, what i needed to do was change the path for images directory from &lt;code&gt;resources/file.png&lt;/code&gt; to &lt;code&gt;/assets/img/file.png&lt;/code&gt;. But i didn&amp;rsquo;t know which files had the new link structure and which files had the old one. We&amp;rsquo;re talking about 500+ files, in 25+ directories, so i can&amp;rsquo;t just go open them one by one and find stuff..&lt;/p&gt;</description>
    </item>
    <item>
      <title>[grep] Find and Delete files based on string</title>
      <link>https://aamnah.com/notes/commands/grep-find-and-delete-files-based-on-string/</link>
      <pubDate>Tue, 08 Dec 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/commands/grep-find-and-delete-files-based-on-string/</guid>
      <description>&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;grep -lZrw xxx-hacker /home/theitali/ &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; xargs -0 rm -f --&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;where &lt;em&gt;xxx-hacker&lt;/em&gt; is your string and &lt;em&gt;/home/theitali/&lt;/em&gt; is your location.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;l&lt;/code&gt; lists the file name&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;Z&lt;/code&gt; is required for the &lt;code&gt;xargs -0&lt;/code&gt; part&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;r&lt;/code&gt; is for recursive, try &lt;code&gt;-R&lt;/code&gt; if small r doesnt work.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;w&lt;/code&gt; is for searching the whole word&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>[du] Disk Space Usage</title>
      <link>https://aamnah.com/notes/commands/du-disk-space-usage/</link>
      <pubDate>Sat, 21 Nov 2015 00:00:01 +0500</pubDate>
      <guid>https://aamnah.com/notes/commands/du-disk-space-usage/</guid>
      <description>&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;&#xA;&lt;h3 id=&#34;check-how-much-space-is-taken-by-files-of-a-certain-type&#34;&gt;check how much space is taken by files of a certain type&lt;/h3&gt;&#xA;&lt;p&gt;Say you want to find out how much space in total the &lt;code&gt;.tar.gz&lt;/code&gt; backup files are taking, you can do so with the following command. (note that it will not check subdirectories)&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;-h&lt;/code&gt;, &lt;code&gt;--human-readable&lt;/code&gt;  prints sizes in human readable format (e.g. 261M instead of 266692)&lt;/li&gt;&#xA;&lt;li&gt;The &lt;code&gt;-c&lt;/code&gt; or &lt;code&gt;--total&lt;/code&gt; size produces a grand total&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# find out space taken by tarballs in current dir&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;du -h *.tar.gz&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;23M     aamnah.tar.gz&#xA;54M     clients.aamnah.tar.gz&#xA;261M    clients.hostmarkaz.tar.gz&#xA;113M&#x9;clients.ravihost.tar.gz&#xA;2.9M&#x9;ravihost.tar.gz&#xA;36K &#x9;tldrdevnotes.tar.gz&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# find out TOTAL space taken by all tarballs in current dir&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;du -ch *.tar.gz&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;23M     aamnah.tar.gz&#xA;54M     clients.aamnah.tar.gz&#xA;261M    clients.hostmarkaz.tar.gz&#xA;113M&#x9;clients.ravihost.tar.gz&#xA;2.9M&#x9;ravihost.tar.gz&#xA;36K &#x9;tldrdevnotes.tar.gz&#xA;453M&#x9;total&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;check-space-consumed-and-sort-by-size&#34;&gt;check space consumed and sort by size&lt;/h3&gt;&#xA;&lt;p&gt;&lt;a href=&#34;http://explainshell.com/explain?cmd=++++du+--max-depth%3D1+%7C+sort+-n+%7C+awk+%27BEGIN+%7BOFMT+%3D+%22%25.0f%22%7D+%7Bprint+%241%2F1024%2C%22MB%22%2C+%242%7D%27&#34;&gt;explainshell&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>[df] Disk Free</title>
      <link>https://aamnah.com/notes/commands/df-disk-free/</link>
      <pubDate>Sat, 21 Nov 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/commands/df-disk-free/</guid>
      <description>&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;df -h&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;-h&lt;/code&gt; flag is for human readable output, show 30G instead of 30830588.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://aamnah.com/notes/commands/images/df-h.png&#34; alt=&#34;Screenshot df -h&#34; loading=&#34;lazy&#34;&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;summing-numbers-in-the-output-of-df&#34;&gt;Summing numbers in the output of &lt;code&gt;df&lt;/code&gt;&lt;/h3&gt;&#xA;&lt;p&gt;We can do that by pip the output of the df command to something like &lt;code&gt;awk&lt;/code&gt; and have &lt;code&gt;awk&lt;/code&gt; sum up the numbers, like so:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;df -lP &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; awk &lt;span class=&#34;s1&#34;&gt;&amp;#39;{}&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;df -lP &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; awk &lt;span class=&#34;s1&#34;&gt;&amp;#39;{do math} END {print result}&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If the device names are long, df splits the output on multiple line to fit it in the normal 80 character long terminal. &lt;code&gt;-P&lt;/code&gt; is for portability, use the POSIX output format (and not try to fit everything in by breaking lines) Get the foramt data in a consistent format, every device on one line.&lt;/p&gt;</description>
    </item>
    <item>
      <title>[chmod] Permissions</title>
      <link>https://aamnah.com/notes/commands/chmod/</link>
      <pubDate>Thu, 19 Nov 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/commands/chmod/</guid>
      <description>&lt;h2 id=&#34;change-permissions-on-all-dirs&#34;&gt;change permissions on all dirs&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;find . -type d -exec chmod &lt;span class=&#34;m&#34;&gt;700&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;change-permissions-on-all-files&#34;&gt;change permissions on all files&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;find . -type f -exec chmod &lt;span class=&#34;m&#34;&gt;600&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;change-permissions-recursively&#34;&gt;change permissions recursively&lt;/h2&gt;&#xA;&lt;p&gt;use the &lt;code&gt;-R&lt;/code&gt; flag&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;chmod &lt;span class=&#34;m&#34;&gt;755&lt;/span&gt; -R var/&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;make-executable&#34;&gt;make executable&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;chmod +x file&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;copy-permissions-from-another-file&#34;&gt;copy permissions from another file&lt;/h2&gt;&#xA;&lt;p&gt;On GNU/Linux &lt;code&gt;chown&lt;/code&gt; and &lt;code&gt;chmod&lt;/code&gt; have a &lt;code&gt;--reference&lt;/code&gt; option&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;chown --reference&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;otherfile thisfile&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;chmod --reference&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;otherfile thisfile&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;example-from-magento&#34;&gt;Example from Magento&lt;/h2&gt;&#xA;&lt;p&gt;Enter the following commands to set sensible permission defaults:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;find . -type f -exec chmod &lt;span class=&#34;m&#34;&gt;400&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;find . -type d -exec chmod &lt;span class=&#34;m&#34;&gt;500&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\;&lt;/span&gt; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;find var/ -type f -exec chmod &lt;span class=&#34;m&#34;&gt;600&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\;&lt;/span&gt; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;find media/ -type f -exec chmod &lt;span class=&#34;m&#34;&gt;600&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;find var/ -type d -exec chmod &lt;span class=&#34;m&#34;&gt;700&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\;&lt;/span&gt; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;find media/ -type d -exec chmod &lt;span class=&#34;m&#34;&gt;700&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;links&#34;&gt;Links&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;http://devdocs.magento.com/guides/m1x/install/installer-privileges_after.html&#34;&gt;After You Install Magento: Recommended File System Ownership and Privileges&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;http://unix.stackexchange.com/questions/20645/clone-ownership-and-permissions-from-another-file&#34;&gt;StackOverflow: Clone ownership and permissions from another file?&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>Devil&#39;s Commands</title>
      <link>https://aamnah.com/notes/commands/devils-commands/</link>
      <pubDate>Sat, 31 Oct 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/commands/devils-commands/</guid>
      <description>&lt;p&gt;&lt;img src=&#34;https://aamnah.com/notes/commands/images/doomsday-commands.jpg&#34; alt=&#34;Commands - Doomsday Commands&#34; loading=&#34;lazy&#34;&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;list-of-dangerous-shell-commands&#34;&gt;List of dangerous shell commands&lt;/h3&gt;&#xA;&lt;p&gt;It is not uncommon to see trolls tricking new Linux/Unix users run commands as a joke. These commands can destroy users data. Here are a few:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;rm -rf /&lt;/li&gt;&#xA;&lt;li&gt;:(){ :|: &amp;amp; };:&lt;/li&gt;&#xA;&lt;li&gt;mkfs /dev/sda1&lt;/li&gt;&#xA;&lt;li&gt;cat /dev/zero &amp;gt; /dev/sda1&lt;/li&gt;&#xA;&lt;li&gt;wget url -O - | sh &amp;ndash;&lt;/li&gt;&#xA;&lt;li&gt;curl url | sh&lt;/li&gt;&#xA;&lt;li&gt;dd if=/dev/zero of=/dev/sda2&lt;/li&gt;&#xA;&lt;li&gt;echo 726d202d7266202a | xxd -r -p&lt;/li&gt;&#xA;&lt;li&gt;dd if=/dev/random of=/dev/port&lt;/li&gt;&#xA;&lt;li&gt;echo 1 &amp;gt; /proc/sys/kernel/panic&lt;/li&gt;&#xA;&lt;li&gt;cat /dev/port or cat /dev/mem&lt;/li&gt;&#xA;&lt;li&gt;cat /dev/zero &amp;gt; /dev/mem&lt;/li&gt;&#xA;&lt;li&gt;sudo chmod -r 444 / or sudo chown -r nobody:nobody /&lt;/li&gt;&#xA;&lt;li&gt;last | reboot&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h4 id=&#34;explanations&#34;&gt;Explanations&lt;/h4&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;rm -rf /&#xA;Doesn&amp;rsquo;t work anymore. Don&amp;rsquo;t bother. Used to remove all files in the directory tree.&lt;/li&gt;&#xA;&lt;li&gt;:(){ :|: &amp;amp; };:&#xA;Fork bomb. Job control has partially mitigated this by now. It won&amp;rsquo;t fully bork up the system anymore.&lt;/li&gt;&#xA;&lt;li&gt;mkfs /dev/sda1&#xA;Formats first partition on sda disk.&lt;/li&gt;&#xA;&lt;li&gt;cat /dev/zero &amp;gt; /dev/sda1&#xA;Zeroes out the first partition (many systems host either / or /boot there). Using sda might&amp;rsquo;ve been better.&lt;/li&gt;&#xA;&lt;li&gt;wget url -O - | sh &amp;ndash;&#xA;Grab arbitrary shell script from online and execute it.&lt;/li&gt;&#xA;&lt;li&gt;curl url | sh&#xA;Deviation of 5.&lt;/li&gt;&#xA;&lt;li&gt;dd if=/dev/zero of=/dev/sda2&#xA;Zeroes out sda2. Just like 4 it kinda sucks. It assumes the existence of that partition.&lt;/li&gt;&#xA;&lt;li&gt;echo 726d202d7266202a | xxd -r -p&#xA;Doesn&amp;rsquo;t do jack shit unless put inside $( ). It just echoes &lt;code&gt;rm -rf *&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;dd if=/dev/random of=/dev/port&#xA;Write random stuff to memory. Better use urandom instead.&lt;/li&gt;&#xA;&lt;li&gt;echo 1 &amp;gt; /proc/sys/kernel/panic&#xA;Induce kernel panic.&lt;/li&gt;&#xA;&lt;li&gt;cat /dev/port or cat /dev/mem&#xA;View system memory.&lt;/li&gt;&#xA;&lt;li&gt;cat /dev/zero &amp;gt; /dev/mem&#xA;Write zero bits into system memory.&lt;/li&gt;&#xA;&lt;li&gt;sudo chmod -r 444 / or sudo chown -r nobody:nobody /&#xA;Make all files on system read-only and pass their ownership to nobody user.&lt;/li&gt;&#xA;&lt;li&gt;last | reboot&#xA;View last logged in users and send its output to reboot? What kinda bullshit is that?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;So, newb commands mostly. Learn from any source but not these shitty commands please &lt;code&gt;_/\_&lt;/code&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>[wget] How to store an entire website offline</title>
      <link>https://aamnah.com/notes/commands/wget-getwebsite-download-an-entire-website-offline/</link>
      <pubDate>Tue, 26 Aug 2014 00:00:01 +0500</pubDate>
      <guid>https://aamnah.com/notes/commands/wget-getwebsite-download-an-entire-website-offline/</guid>
      <description>&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;wget --random-wait -r -p -e &lt;span class=&#34;nv&#34;&gt;robots&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;off -U mozilla http://yoursite.com&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;OR, as a bash function added to &lt;code&gt;~/.bash_profile&lt;/code&gt; (MacOS) or &lt;code&gt;~/.bashrc&lt;/code&gt; (Linux)&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Download an entire website&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# -p --page-requisites: get all the elements that compose the page (images, CSS and so on)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# -e robots=off you don&amp;#39;t want wget to obey by the robots.txt file&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# -U mozilla as your browsers identity.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# --random-wait to let wget chose a random number of seconds to wait, avoid get into black list.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Other Useful wget Parameters:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 7&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# -k --convert-links: convert links so that they work locally, off-line.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 8&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# --limit-rate=20k limits the rate at which it downloads files.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 9&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# -b continues wget after logging out.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# -o $HOME/wget_log.txt logs the output&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;getwebsite&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;13&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    wget --random-wait -r -p -e &lt;span class=&#34;nv&#34;&gt;robots&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;off -U mozilla &lt;span class=&#34;nv&#34;&gt;$1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;14&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To use the bash function&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
