committed by
hoschi-it
24 changed files with 818 additions and 19 deletions
-
18build
-
240distribution/2021/03/09/exec-a-command-for-each-specific-file/index.html
-
25distribution/gemfeed/2021-03-17-goals.html
-
27distribution/gemfeed/atom.xml
-
1distribution/gemfeed/index.html
-
49distribution/history.html
-
2distribution/index.html
-
11gemtext/gemfeed/2021-03-17-goals.gmi
-
27gemtext/gemfeed/atom.xml
-
1gemtext/gemfeed/index.gmi
-
34gemtext/history.gmi
-
2gemtext/index.gmi
-
25html/gemfeed/2021-03-17-goals.html
-
27html/gemfeed/atom.xml
-
1html/gemfeed/index.html
-
49html/history.html
-
2html/index.html
-
240html_2021_jekyll-website_latest/2021/03/09/exec-a-command-for-each-specific-file/index.html
-
11md/gemfeed/2021-03-17-goals.md
-
1md/gemfeed/index.md
-
34md/history.md
-
2md/index.md
-
5meta/gemfeed/2021-03-17-goals.meta
-
3redirect.csv
@ -1,17 +1,241 @@ |
|||
|
|||
<!DOCTYPE html> <html lang="en"><head> <link href="http://gmpg.org/xfn/11" rel="profile" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <!-- Enable responsiveness on mobile devices--> <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=5" /> <!-- yandex search site submission code --> <meta name="yandex-verification" content="d9bed1f6e7422836" /> <!-- google search site submission code --> <meta name="google-site-verification" content="YQ5G_6dkyNio3G1OmGZV19NxdDLJU3fiqc7nzpn5J38" /> <title> Exec A Command For Each Specific File · Hoschi-IT </title> <!-- CSS --> <link rel="stylesheet" href="/assets/css/main.css"/> <!-- Icons --> <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/assets/apple-touch-icon-144-precomposed.png" /> <link rel="shortcut icon" href="/assets/favicon.ico" /> <!-- RSS --> <link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml" /> <link rel="authorization_endpoint" href="" /> <link rel="token_endpoint" href="" /> <link rel="microsub" href="" /><link rel="pgpkey authn" href='/key.pub' /> </head> <body class="theme-base-0d"><header> <section> <h1> <a href="/"> Hoschi-IT </a> </h1> <p class="lead"> Personal note book - feel free to explore! </p> <p class="lead"> </p> </section><nav> <ul><li> <a class="" href="/index.html">All posts</a> </li><li> <a class="" href="/about/">About</a> </li><li> <a class="" href="/tags/">Tags</a> </li></ul> </nav> <section class="social h-card"> <p style="display:none"> <a class="u-url u-uid p-nickname" rel="me" href="https://hoschi-it.de/">hoschi-it</a><img class="u-photo" alt="a kingfischer (bird)" src="/assets/photos/kingfisher.jpeg" height="100" width="100" /> </p> <ul> <li><a href="/key.pub" target="_blank" class="icon" rel="pgpkey authn" > <img src="/assets/icons/keys.svg" title="keys" alt="Keys" width="32" height="32" loading="lazy"/> </a> </li> <li><a href="https://mastodontech.de/@hoschi" target="_blank" class="icon" rel="me"> <img src="/assets/icons/mastodon.svg" title="mastodon" alt="Mastodon" width="32" height="32" loading="lazy"/> </a> </li> <li><a href="https://gitlab.com/hoschi-it" target="_blank" class="icon" rel="me"> <img src="/assets/icons/gitlab.svg" title="gitlab" alt="Gitlab" width="32" height="32" loading="lazy"/> </a> </li> <li><a href="https://stackoverflow.com/users/5129897/hoschi-it" target="_blank" class="icon" rel="me"> <img src="/assets/icons/stackoverflow.svg" title="stackoverflow" alt="Stackoverflow" width="32" height="32" loading="lazy"/> </a> </li> <li><a href="https://github.com/hoschi-it" target="_blank" class="icon" rel="me"> <img src="/assets/icons/github.svg" title="github" alt="Github" width="32" height="32" loading="lazy"/> </a> </li> </ul> </section> </header> <main class="content container"><article lang="en" class="post h-entry reply" > <a href="/2021/03/09/exec-a-command-for-each-specific-file/"> <time class="post-date dt-published" datetime="2021-03-09 21:27:30+0100">09 Mar 2021</time> </a><blockquote class="h-cite cite webmentions u-in-reply-to"><h4 class="p-name">Bash: Execute a command in each directory with file my_suites.cfg?</h4><section> "I want to create a script which executes a command (similar to make command) in every directory which contains a..." </section><p class="metadata"><span class="author p-author h-card">Phi-Long Vu </span>on <a class="u-url" href="https://unix.stackexchange.com/questions/638389/bash-execute-a-command-in-each-directory-with-file-my-suites-cfg" rel="nofollow" target="_blank">unix.stackexchange.com</a> at <time class="dt-published" datetime="2021-03-09 14:38:18+0000">09 Mar 2021</time></p> </blockquote> <div class="e-content p-name"><p>So to summarize the question: You want to run a bash command on each folder that contains a file that has a specific name, one at a time.</p> <p>Assuming, that you are willing to use existing tools and not write everything from scratch by yourself, here are some ideas:</p> <h2 id="tldr-too-long-didnt-read">TL;DR <em>(Too long, didn’t read)</em></h2> <p>If it doesn’t matter whether the newest files are not recognized yet:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ mlocate --basename --regex "^my_suites.cfg$" \ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
|||
<!-- Enable responsiveness on mobile devices--> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=5" /> |
|||
<title>Exec A Command For Each Specific File · Hoschi-IT</title> |
|||
<!-- RSS --> |
|||
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml" /> |
|||
</head> |
|||
<body class="theme-base-0d"> |
|||
<main class="content container"> |
|||
<article lang="en" class="post h-entry reply" > |
|||
<a href="/2021/03/09/exec-a-command-for-each-specific-file/"> |
|||
<time class="post-date dt-published" datetime="2021-03-09 21:27:30+0100">09 Mar 2021 |
|||
</time> |
|||
</a> |
|||
<blockquote class="h-cite cite webmentions u-in-reply-to"> |
|||
<h4 class="p-name">Bash: Execute a command in each directory with file my_suites.cfg? |
|||
</h4> |
|||
<section> "I want to create a script which executes a command (similar to make command) in every directory which contains a..." |
|||
</section> |
|||
<p class="metadata"> |
|||
<span class="author p-author h-card">Phi-Long Vu |
|||
</span>on |
|||
<a class="u-url" href="https://unix.stackexchange.com/questions/638389/bash-execute-a-command-in-each-directory-with-file-my-suites-cfg" rel="nofollow" target="_blank">unix.stackexchange.com |
|||
</a> at |
|||
<time class="dt-published" datetime="2021-03-09 14:38:18+0000">09 Mar 2021 |
|||
</time> |
|||
</p> |
|||
</blockquote> |
|||
<div class="e-content p-name"> |
|||
<p>So to summarize the question: You want to run a bash command on each folder that contains a file that has a specific name, one at a time. |
|||
</p> |
|||
<p>Assuming, that you are willing to use existing tools and not write everything from scratch by yourself, here are some ideas: |
|||
</p> |
|||
<h2 id="tldr-too-long-didnt-read">TL;DR |
|||
<em>(Too long, didn’t read) |
|||
</em> |
|||
</h2> |
|||
<p>If it doesn’t matter whether the newest files are not recognized yet: |
|||
</p> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ mlocate --basename --regex "^my_suites.cfg$" \ |
|||
| xargs dirname \ |
|||
| xargs -d '\n' <command-to-run-on-the-file> |
|||
</code></pre></div></div> <p>Else if efficiency is not so important (assuming, that we are searching recursively in the home directory (<code class="language-plaintext highlighter-rouge">~</code>) only:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ find ~ -name "my_suites.cfg" -type f \ |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<p>Else if efficiency is not so important (assuming, that we are searching recursively in the home directory ( |
|||
<code class="language-plaintext highlighter-rouge">~ |
|||
</code>) only: |
|||
</p> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ find ~ -name "my_suites.cfg" -type f \ |
|||
| xargs dirname \ |
|||
| xargs -d '\n' <command-to-run-on-the-file> |
|||
</code></pre></div></div> <hr /> <h2 id="full-version">Full Version</h2> <h3 id="finding-the-files">Finding the files</h3> <p>If the files you are looking for are scattered all over the system, you should care about effectiveness.</p> <h4 id="the-faster-way">The fast(er) way</h4> <p>With some downsides</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ mlocate --basename --regex "^my_suites.cfg$" |
|||
</code></pre></div></div> <ul> <li><code class="language-plaintext highlighter-rouge">mlocate</code> looks up file paths in a database that is updated once a day for most distributions. So it may not recognize recently created or recently moved files. But because it looks into the database instead of going through the file system itself, it’s search is very efficient.</li> <li>The <code class="language-plaintext highlighter-rouge">--basename</code> option specifies that we are looking for the direct name of the file, not including the path/directories of it.</li> <li>The <code class="language-plaintext highlighter-rouge">--regex</code> option enables regular expressions being allowed in the search pattern. (The <code class="language-plaintext highlighter-rouge">^</code> expects the string to start there and the <code class="language-plaintext highlighter-rouge">$</code> expects the string to end there.)</li> </ul> <h4 id="the-always-up-to-date-way">The “always up-to-date” way</h4> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ find / -name "my_suites.cfg" -type f |
|||
</code></pre></div></div> <ul> <li><code class="language-plaintext highlighter-rouge">find</code> goes through basically every folder it can find and lists every file which is named my_suites.cfg. Because of that many reading-operations that it has to do, the more folders it searches the slower it gets.</li> <li>The <code class="language-plaintext highlighter-rouge">-name</code> option specifies, that my_suites.cfg is the <strong>name</strong> of the file, instead of i.e. a folder that contains the file that we are looking for.</li> <li>The <code class="language-plaintext highlighter-rouge">-type</code> option specifies, that we are looking for a <strong>file</strong>, not for a directory, symlink, socket or something.</li> </ul> <h3 id="running-a-custom-command-on-each-of-the-files">Running a custom command on each of the files</h3> <p>… that’s what <code class="language-plaintext highlighter-rouge">xargs</code> is for</p> <h4 id="a-simple-example">A simple example</h4> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ echo "some simple example" | xargs mkdir |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<hr /> |
|||
<h2 id="full-version">Full Version |
|||
</h2> |
|||
<h3 id="finding-the-files">Finding the files |
|||
</h3> |
|||
<p>If the files you are looking for are scattered all over the system, you should care about effectiveness. |
|||
</p> |
|||
<h4 id="the-faster-way">The fast(er) way |
|||
</h4> |
|||
<p>With some downsides |
|||
</p> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ mlocate --basename --regex "^my_suites.cfg$" |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<ul> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">mlocate |
|||
</code> looks up file paths in a database that is updated once a day for most distributions. So it may not recognize recently created or recently moved files. But because it looks into the database instead of going through the file system itself, it’s search is very efficient. |
|||
</li> |
|||
<li>The |
|||
<code class="language-plaintext highlighter-rouge">--basename |
|||
</code> option specifies that we are looking for the direct name of the file, not including the path/directories of it. |
|||
</li> |
|||
<li>The |
|||
<code class="language-plaintext highlighter-rouge">--regex |
|||
</code> option enables regular expressions being allowed in the search pattern. (The |
|||
<code class="language-plaintext highlighter-rouge">^ |
|||
</code> expects the string to start there and the |
|||
<code class="language-plaintext highlighter-rouge">$ |
|||
</code> expects the string to end there.) |
|||
</li> |
|||
</ul> |
|||
<h4 id="the-always-up-to-date-way">The “always up-to-date” way |
|||
</h4> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ find / -name "my_suites.cfg" -type f |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<ul> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">find |
|||
</code> goes through basically every folder it can find and lists every file which is named my_suites.cfg. Because of that many reading-operations that it has to do, the more folders it searches the slower it gets. |
|||
</li> |
|||
<li>The |
|||
<code class="language-plaintext highlighter-rouge">-name |
|||
</code> option specifies, that my_suites.cfg is the |
|||
<strong>name |
|||
</strong> of the file, instead of i.e. a folder that contains the file that we are looking for. |
|||
</li> |
|||
<li>The |
|||
<code class="language-plaintext highlighter-rouge">-type |
|||
</code> option specifies, that we are looking for a |
|||
<strong>file |
|||
</strong>, not for a directory, symlink, socket or something. |
|||
</li> |
|||
</ul> |
|||
<h3 id="running-a-custom-command-on-each-of-the-files">Running a custom command on each of the files |
|||
</h3> |
|||
<p>… that’s what |
|||
<code class="language-plaintext highlighter-rouge">xargs |
|||
</code> is for |
|||
</p> |
|||
<h4 id="a-simple-example">A simple example |
|||
</h4> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ echo "some simple example" | xargs mkdir |
|||
$ # now there are three directories, named by the echoed words |
|||
$ ls |
|||
example simple some |
|||
</code></pre></div></div> <h4 id="something-more-complex">Something more complex:</h4> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ echo "hello world" | xargs -d ' ' -I % echo 'Print a word: %' |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<h4 id="something-more-complex">Something more complex: |
|||
</h4> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ echo "hello world" | xargs -d ' ' -I % echo 'Print a word: %' |
|||
Print a word: hello |
|||
Print a word: world |
|||
</code></pre></div></div> <ul> <li><code class="language-plaintext highlighter-rouge">-d</code> option: specifies, which character delimits the arguments from each other (here: a space).</li> <li><code class="language-plaintext highlighter-rouge">-I</code> option: All occurences of the given character (<code class="language-plaintext highlighter-rouge">%</code> in this example) will be replaced by the argument that came from the pipe (before <code class="language-plaintext highlighter-rouge">|</code>)</li> </ul> <p>This is what happens in the above example:</p> <ol> <li><code class="language-plaintext highlighter-rouge">echo</code> prints “hello world” to the standard output (<code class="language-plaintext highlighter-rouge">stdout</code>).</li> <li>The pipe (<code class="language-plaintext highlighter-rouge">|</code>) gives this value (“hello world”) to the following command, which happens to be <code class="language-plaintext highlighter-rouge">xargs</code>.</li> <li><code class="language-plaintext highlighter-rouge">xargs</code> searches for occurences of the delimiter in the argument and splits the argument where it finds the delimiter.</li> <li><code class="language-plaintext highlighter-rouge">xargs</code> loops through the newly created arguments and runs the command with the argument value instead of <code class="language-plaintext highlighter-rouge">%</code></li> </ol> <h3 id="further-readings">Further readings</h3> <ul> <li><a href="https://shapeshed.com/unix-xargs/">Unix xargs</a></li> <li><a href="https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285">Regular Expressions: Tutorial</a></li> <li><a href="https://linux.die.net/man/1/locate">locate man page</a></li> <li>this answer also lives on <a href="https://unix.stackexchange.com/a/638453/459894">unix.stackexchange.com</a></li> </ul> </div> <p><a class="p-category u-tag-of" href="/tags/#stackexchange" > #stackexchange</a> <a class="p-category u-tag-of" href="/tags/#bash" > #bash</a> <a class="p-category u-tag-of" href="/tags/#gnu/linux" > #gnu/linux</a> </p><details> <summary>Meta data</summary><ul class="microformats2"><li> Tags: <ul><li class="p-category"> <a href="https://hoschi-it.de/tags/#stackexchange">stackexchange</a> </li><li class="p-category"> <a href="https://hoschi-it.de/tags/#bash">bash</a> </li><li class="p-category"> <a href="https://hoschi-it.de/tags/#gnu/linux">gnu/linux</a> </li></ul> </li><li> <a class="u-url" href="https://hoschi-it.de/2021/03/09/exec-a-command-for-each-specific-file/"> Permanent post link </a> </li> <li class="p-author h-card" rel="author"> Author <ul> <li>Nickname: <span class="p-name">hoschi-it</span> </li> <li> <a class="u-url p-name" rel="author" href="https://hoschi-it.de/"> Website </a> </li> <li>Profile picture:<img class="u-photo" alt="a kingfischer (bird)" src="/assets/photos/kingfisher.jpeg" width="100" height="100" loading="lazy" /> </li> </ul> </li><li>Also published on <ul><li> <a rel="syndication" class="u-syndication" href="https://unix.stackexchange.com/a/638453/459894">unix.stackexchange.com</a> </li></ul> </li></ul> </details> </article> </main><footer><nav> <ul><li> <a class="" href="/impressum/">Impressum</a> </li><li> <a class="" href="/privacy/">Privacy</a> </li></ul> </nav> <p>© 2021. All rights reserved.</p> </footer> </body> </html> |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<ul> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">-d |
|||
</code> option: specifies, which character delimits the arguments from each other (here: a space). |
|||
</li> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">-I |
|||
</code> option: All occurences of the given character ( |
|||
<code class="language-plaintext highlighter-rouge">% |
|||
</code> in this example) will be replaced by the argument that came from the pipe (before |
|||
<code class="language-plaintext highlighter-rouge">| |
|||
</code>) |
|||
</li> |
|||
</ul> |
|||
<p>This is what happens in the above example: |
|||
</p> |
|||
<ol> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">echo |
|||
</code> prints “hello world” to the standard output ( |
|||
<code class="language-plaintext highlighter-rouge">stdout |
|||
</code>). |
|||
</li> |
|||
<li>The pipe ( |
|||
<code class="language-plaintext highlighter-rouge">| |
|||
</code>) gives this value (“hello world”) to the following command, which happens to be |
|||
<code class="language-plaintext highlighter-rouge">xargs |
|||
</code>. |
|||
</li> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">xargs |
|||
</code> searches for occurences of the delimiter in the argument and splits the argument where it finds the delimiter. |
|||
</li> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">xargs |
|||
</code> loops through the newly created arguments and runs the command with the argument value instead of |
|||
<code class="language-plaintext highlighter-rouge">% |
|||
</code> |
|||
</li> |
|||
</ol> |
|||
<h3 id="further-readings">Further readings |
|||
</h3> |
|||
<ul> |
|||
<li> |
|||
<a href="https://shapeshed.com/unix-xargs/">Unix xargs |
|||
</a> |
|||
</li> |
|||
<li> |
|||
<a href="https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285">Regular Expressions: Tutorial |
|||
</a> |
|||
</li> |
|||
<li> |
|||
<a href="https://linux.die.net/man/1/locate">locate man page |
|||
</a> |
|||
</li> |
|||
<li>this answer also lives on |
|||
<a href="https://unix.stackexchange.com/a/638453/459894">unix.stackexchange.com |
|||
</a> |
|||
</li> |
|||
</ul> |
|||
</div> |
|||
<p> |
|||
<a class="p-category u-tag-of" href="/tags/#stackexchange" > #stackexchange |
|||
</a> |
|||
<a class="p-category u-tag-of" href="/tags/#bash" > #bash |
|||
</a> |
|||
<a class="p-category u-tag-of" href="/tags/#gnu/linux" > #gnu/linux |
|||
</a> |
|||
</p> |
|||
</article> |
|||
</main> |
|||
</body> |
|||
</html> |
@ -0,0 +1,25 @@ |
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
|||
<head> |
|||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1"/> |
|||
<title>Goals</title> |
|||
<link rel="shortcut icon" type="image/gif" href="/favicon.ico" /> |
|||
<link rel="stylesheet" type="text/css" href="/assets/style.css" /> |
|||
</head> |
|||
<body> |
|||
<h1>Goals</h1> |
|||
<p>Here are some things about the webpage (or my tech stack in general) that I want to accomplish:</p> |
|||
<ul> |
|||
<li>☐ Fix: Jekyll plugin does not find outgoing webmentions</li> |
|||
<li>☐ Wikify myself @indiewebcamp.org</li> |
|||
<li>☑ Relax</li> |
|||
<li>☐ Implement check lists (for real, not just via some specially formatted note post).</li> |
|||
<li>☐ put it on the IPFS, just for fun :D</li> |
|||
<li>☐ make publishing from mobile possible (via micropub)</li> |
|||
<li>☐ generate seperate h-feed and link to it</li> |
|||
<footer> |
|||
<a class="textlink" href="/">Go back home</a> |
|||
</footer> |
|||
</body> |
|||
</html> |
@ -0,0 +1,49 @@ |
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
|||
<head> |
|||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1"/> |
|||
<title>History</title> |
|||
<link rel="shortcut icon" type="image/gif" href="/favicon.ico" /> |
|||
<link rel="stylesheet" type="text/css" href="/assets/style.css" /> |
|||
</head> |
|||
<body> |
|||
<h1>History</h1> |
|||
<a class="textlink" href="/projects/ducks-landing-page/index.html">/projects/ducks-landing-page/index.html</a><br /> |
|||
<a class="textlink" href="/404.html">/404.html</a><br /> |
|||
<a class="textlink" href="/privacy/index.html">/privacy/index.html</a><br /> |
|||
<a class="textlink" href="/2021/01/02/danke/index.html">/2021/01/02/danke/index.html</a><br /> |
|||
<a class="textlink" href="/2021/01/05/cli-anwendungen/index.html">/2021/01/05/cli-anwendungen/index.html</a><br /> |
|||
<a class="textlink" href="/2021/01/05/covid19-musical-vaccine/index.html">/2021/01/05/covid19-musical-vaccine/index.html</a><br /> |
|||
<a class="textlink" href="/2021/01/06/kein-parser-im-hirn/index.html">/2021/01/06/kein-parser-im-hirn/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/17/goals/index.html">/2021/03/17/goals/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/17/reply-1/index.html">/2021/03/17/reply-1/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/07/bookmark-12-factor-app/index.html">/2021/03/07/bookmark-12-factor-app/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/07/indieweb-internetarchive-channel/index.html">/2021/03/07/indieweb-internetarchive-channel/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/07/bookmark-resilient-web-design/index.html">/2021/03/07/bookmark-resilient-web-design/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/10/rsvp-hwc-europe/index.html">/2021/03/10/rsvp-hwc-europe/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/10/bookmark-markdown-syntax-documentation/index.html">/2021/03/10/bookmark-markdown-syntax-documentation/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/15/completed-tutorials/index.html">/2021/03/15/completed-tutorials/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/09/exec-a-command-for-each-specific-file/index.html">/2021/03/09/exec-a-command-for-each-specific-file/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/14/note-test/index.html">/2021/03/14/note-test/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/14/plain-note-post-type/index.html">/2021/03/14/plain-note-post-type/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/16/like-one-year-in-the-indieweb/index.html">/2021/03/16/like-one-year-in-the-indieweb/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/16/bookmark-man-gnu-coreutils/index.html">/2021/03/16/bookmark-man-gnu-coreutils/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/12/bookmark-indiewebxyz/index.html">/2021/03/12/bookmark-indiewebxyz/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/12/like-non-technical-indieweb/index.html">/2021/03/12/like-non-technical-indieweb/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/11/repost-messenger-ausweispflicht/index.html">/2021/03/11/repost-messenger-ausweispflicht/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/11/like-what-matters/index.html">/2021/03/11/like-what-matters/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/20/note-ipfs-publish/index.html">/2021/03/20/note-ipfs-publish/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/13/bookmark-fedbridgy/index.html">/2021/03/13/bookmark-fedbridgy/index.html</a><br /> |
|||
<a class="textlink" href="/a/deleted/post.html">/a/deleted/post.html</a><br /> |
|||
<a class="textlink" href="/about/index.html">/about/index.html</a><br /> |
|||
<a class="textlink" href="/tags/index.html">/tags/index.html</a><br /> |
|||
<a class="textlink" href="/410.html">/410.html</a><br /> |
|||
<a class="textlink" href="/replies/2020/2020-12-28-sending-your-first-webmention/index.html">/replies/2020/2020-12-28-sending-your-first-webmention/index.html</a><br /> |
|||
<a class="textlink" href="/s/1/index.html">/s/1/index.html</a><br /> |
|||
<a class="textlink" href="/2020/01/01/lets-start/index.html">/2020/01/01/lets-start/index.html</a><br /> |
|||
<footer> |
|||
<a class="textlink" href="/">Go back home</a> |
|||
</footer> |
|||
</body> |
|||
</html> |
@ -0,0 +1,11 @@ |
|||
# Goals |
|||
|
|||
Here are some things about the webpage (or my tech stack in general) that I want to accomplish: |
|||
|
|||
* ☐ Fix: Jekyll plugin does not find outgoing webmentions |
|||
* ☐ Wikify myself @indiewebcamp.org |
|||
* ☑ Relax |
|||
* ☐ Implement check lists (for real, not just via some specially formatted note post). |
|||
* ☐ put it on the IPFS, just for fun :D |
|||
* ☐ make publishing from mobile possible (via micropub) |
|||
* ☐ generate seperate h-feed and link to it |
@ -0,0 +1,34 @@ |
|||
# History |
|||
=> /projects/ducks-landing-page/index.html |
|||
=> /404.html |
|||
=> /privacy/index.html |
|||
=> /2021/01/02/danke/index.html |
|||
=> /2021/01/05/cli-anwendungen/index.html |
|||
=> /2021/01/05/covid19-musical-vaccine/index.html |
|||
=> /2021/01/06/kein-parser-im-hirn/index.html |
|||
=> /2021/03/17/goals/index.html |
|||
=> /2021/03/17/reply-1/index.html |
|||
=> /2021/03/07/bookmark-12-factor-app/index.html |
|||
=> /2021/03/07/indieweb-internetarchive-channel/index.html |
|||
=> /2021/03/07/bookmark-resilient-web-design/index.html |
|||
=> /2021/03/10/rsvp-hwc-europe/index.html |
|||
=> /2021/03/10/bookmark-markdown-syntax-documentation/index.html |
|||
=> /2021/03/15/completed-tutorials/index.html |
|||
=> /2021/03/09/exec-a-command-for-each-specific-file/index.html |
|||
=> /2021/03/14/note-test/index.html |
|||
=> /2021/03/14/plain-note-post-type/index.html |
|||
=> /2021/03/16/like-one-year-in-the-indieweb/index.html |
|||
=> /2021/03/16/bookmark-man-gnu-coreutils/index.html |
|||
=> /2021/03/12/bookmark-indiewebxyz/index.html |
|||
=> /2021/03/12/like-non-technical-indieweb/index.html |
|||
=> /2021/03/11/repost-messenger-ausweispflicht/index.html |
|||
=> /2021/03/11/like-what-matters/index.html |
|||
=> /2021/03/20/note-ipfs-publish/index.html |
|||
=> /2021/03/13/bookmark-fedbridgy/index.html |
|||
=> /a/deleted/post.html |
|||
=> /about/index.html |
|||
=> /tags/index.html |
|||
=> /410.html |
|||
=> /replies/2020/2020-12-28-sending-your-first-webmention/index.html |
|||
=> /s/1/index.html |
|||
=> /2020/01/01/lets-start/index.html |
@ -0,0 +1,25 @@ |
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
|||
<head> |
|||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1"/> |
|||
<title>Goals</title> |
|||
<link rel="shortcut icon" type="image/gif" href="/favicon.ico" /> |
|||
<link rel="stylesheet" type="text/css" href="/assets/style.css" /> |
|||
</head> |
|||
<body> |
|||
<h1>Goals</h1> |
|||
<p>Here are some things about the webpage (or my tech stack in general) that I want to accomplish:</p> |
|||
<ul> |
|||
<li>☐ Fix: Jekyll plugin does not find outgoing webmentions</li> |
|||
<li>☐ Wikify myself @indiewebcamp.org</li> |
|||
<li>☑ Relax</li> |
|||
<li>☐ Implement check lists (for real, not just via some specially formatted note post).</li> |
|||
<li>☐ put it on the IPFS, just for fun :D</li> |
|||
<li>☐ make publishing from mobile possible (via micropub)</li> |
|||
<li>☐ generate seperate h-feed and link to it</li> |
|||
<footer> |
|||
<a class="textlink" href="/">Go back home</a> |
|||
</footer> |
|||
</body> |
|||
</html> |
@ -0,0 +1,49 @@ |
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
|||
<head> |
|||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1"/> |
|||
<title>History</title> |
|||
<link rel="shortcut icon" type="image/gif" href="/favicon.ico" /> |
|||
<link rel="stylesheet" type="text/css" href="/assets/style.css" /> |
|||
</head> |
|||
<body> |
|||
<h1>History</h1> |
|||
<a class="textlink" href="/projects/ducks-landing-page/index.html">/projects/ducks-landing-page/index.html</a><br /> |
|||
<a class="textlink" href="/404.html">/404.html</a><br /> |
|||
<a class="textlink" href="/privacy/index.html">/privacy/index.html</a><br /> |
|||
<a class="textlink" href="/2021/01/02/danke/index.html">/2021/01/02/danke/index.html</a><br /> |
|||
<a class="textlink" href="/2021/01/05/cli-anwendungen/index.html">/2021/01/05/cli-anwendungen/index.html</a><br /> |
|||
<a class="textlink" href="/2021/01/05/covid19-musical-vaccine/index.html">/2021/01/05/covid19-musical-vaccine/index.html</a><br /> |
|||
<a class="textlink" href="/2021/01/06/kein-parser-im-hirn/index.html">/2021/01/06/kein-parser-im-hirn/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/17/goals/index.html">/2021/03/17/goals/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/17/reply-1/index.html">/2021/03/17/reply-1/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/07/bookmark-12-factor-app/index.html">/2021/03/07/bookmark-12-factor-app/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/07/indieweb-internetarchive-channel/index.html">/2021/03/07/indieweb-internetarchive-channel/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/07/bookmark-resilient-web-design/index.html">/2021/03/07/bookmark-resilient-web-design/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/10/rsvp-hwc-europe/index.html">/2021/03/10/rsvp-hwc-europe/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/10/bookmark-markdown-syntax-documentation/index.html">/2021/03/10/bookmark-markdown-syntax-documentation/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/15/completed-tutorials/index.html">/2021/03/15/completed-tutorials/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/09/exec-a-command-for-each-specific-file/index.html">/2021/03/09/exec-a-command-for-each-specific-file/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/14/note-test/index.html">/2021/03/14/note-test/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/14/plain-note-post-type/index.html">/2021/03/14/plain-note-post-type/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/16/like-one-year-in-the-indieweb/index.html">/2021/03/16/like-one-year-in-the-indieweb/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/16/bookmark-man-gnu-coreutils/index.html">/2021/03/16/bookmark-man-gnu-coreutils/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/12/bookmark-indiewebxyz/index.html">/2021/03/12/bookmark-indiewebxyz/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/12/like-non-technical-indieweb/index.html">/2021/03/12/like-non-technical-indieweb/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/11/repost-messenger-ausweispflicht/index.html">/2021/03/11/repost-messenger-ausweispflicht/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/11/like-what-matters/index.html">/2021/03/11/like-what-matters/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/20/note-ipfs-publish/index.html">/2021/03/20/note-ipfs-publish/index.html</a><br /> |
|||
<a class="textlink" href="/2021/03/13/bookmark-fedbridgy/index.html">/2021/03/13/bookmark-fedbridgy/index.html</a><br /> |
|||
<a class="textlink" href="/a/deleted/post.html">/a/deleted/post.html</a><br /> |
|||
<a class="textlink" href="/about/index.html">/about/index.html</a><br /> |
|||
<a class="textlink" href="/tags/index.html">/tags/index.html</a><br /> |
|||
<a class="textlink" href="/410.html">/410.html</a><br /> |
|||
<a class="textlink" href="/replies/2020/2020-12-28-sending-your-first-webmention/index.html">/replies/2020/2020-12-28-sending-your-first-webmention/index.html</a><br /> |
|||
<a class="textlink" href="/s/1/index.html">/s/1/index.html</a><br /> |
|||
<a class="textlink" href="/2020/01/01/lets-start/index.html">/2020/01/01/lets-start/index.html</a><br /> |
|||
<footer> |
|||
<a class="textlink" href="/">Go back home</a> |
|||
</footer> |
|||
</body> |
|||
</html> |
@ -1,17 +1,241 @@ |
|||
|
|||
<!DOCTYPE html> <html lang="en"><head> <link href="http://gmpg.org/xfn/11" rel="profile" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <!-- Enable responsiveness on mobile devices--> <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=5" /> <!-- yandex search site submission code --> <meta name="yandex-verification" content="d9bed1f6e7422836" /> <!-- google search site submission code --> <meta name="google-site-verification" content="YQ5G_6dkyNio3G1OmGZV19NxdDLJU3fiqc7nzpn5J38" /> <title> Exec A Command For Each Specific File · Hoschi-IT </title> <!-- CSS --> <link rel="stylesheet" href="/assets/css/main.css"/> <!-- Icons --> <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/assets/apple-touch-icon-144-precomposed.png" /> <link rel="shortcut icon" href="/assets/favicon.ico" /> <!-- RSS --> <link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml" /> <link rel="authorization_endpoint" href="" /> <link rel="token_endpoint" href="" /> <link rel="microsub" href="" /><link rel="pgpkey authn" href='/key.pub' /> </head> <body class="theme-base-0d"><header> <section> <h1> <a href="/"> Hoschi-IT </a> </h1> <p class="lead"> Personal note book - feel free to explore! </p> <p class="lead"> </p> </section><nav> <ul><li> <a class="" href="/index.html">All posts</a> </li><li> <a class="" href="/about/">About</a> </li><li> <a class="" href="/tags/">Tags</a> </li></ul> </nav> <section class="social h-card"> <p style="display:none"> <a class="u-url u-uid p-nickname" rel="me" href="https://hoschi-it.de/">hoschi-it</a><img class="u-photo" alt="a kingfischer (bird)" src="/assets/photos/kingfisher.jpeg" height="100" width="100" /> </p> <ul> <li><a href="/key.pub" target="_blank" class="icon" rel="pgpkey authn" > <img src="/assets/icons/keys.svg" title="keys" alt="Keys" width="32" height="32" loading="lazy"/> </a> </li> <li><a href="https://mastodontech.de/@hoschi" target="_blank" class="icon" rel="me"> <img src="/assets/icons/mastodon.svg" title="mastodon" alt="Mastodon" width="32" height="32" loading="lazy"/> </a> </li> <li><a href="https://gitlab.com/hoschi-it" target="_blank" class="icon" rel="me"> <img src="/assets/icons/gitlab.svg" title="gitlab" alt="Gitlab" width="32" height="32" loading="lazy"/> </a> </li> <li><a href="https://stackoverflow.com/users/5129897/hoschi-it" target="_blank" class="icon" rel="me"> <img src="/assets/icons/stackoverflow.svg" title="stackoverflow" alt="Stackoverflow" width="32" height="32" loading="lazy"/> </a> </li> <li><a href="https://github.com/hoschi-it" target="_blank" class="icon" rel="me"> <img src="/assets/icons/github.svg" title="github" alt="Github" width="32" height="32" loading="lazy"/> </a> </li> </ul> </section> </header> <main class="content container"><article lang="en" class="post h-entry reply" > <a href="/2021/03/09/exec-a-command-for-each-specific-file/"> <time class="post-date dt-published" datetime="2021-03-09 21:27:30+0100">09 Mar 2021</time> </a><blockquote class="h-cite cite webmentions u-in-reply-to"><h4 class="p-name">Bash: Execute a command in each directory with file my_suites.cfg?</h4><section> "I want to create a script which executes a command (similar to make command) in every directory which contains a..." </section><p class="metadata"><span class="author p-author h-card">Phi-Long Vu </span>on <a class="u-url" href="https://unix.stackexchange.com/questions/638389/bash-execute-a-command-in-each-directory-with-file-my-suites-cfg" rel="nofollow" target="_blank">unix.stackexchange.com</a> at <time class="dt-published" datetime="2021-03-09 14:38:18+0000">09 Mar 2021</time></p> </blockquote> <div class="e-content p-name"><p>So to summarize the question: You want to run a bash command on each folder that contains a file that has a specific name, one at a time.</p> <p>Assuming, that you are willing to use existing tools and not write everything from scratch by yourself, here are some ideas:</p> <h2 id="tldr-too-long-didnt-read">TL;DR <em>(Too long, didn’t read)</em></h2> <p>If it doesn’t matter whether the newest files are not recognized yet:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ mlocate --basename --regex "^my_suites.cfg$" \ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
|||
<!-- Enable responsiveness on mobile devices--> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=5" /> |
|||
<title>Exec A Command For Each Specific File · Hoschi-IT</title> |
|||
<!-- RSS --> |
|||
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml" /> |
|||
</head> |
|||
<body class="theme-base-0d"> |
|||
<main class="content container"> |
|||
<article lang="en" class="post h-entry reply" > |
|||
<a href="/2021/03/09/exec-a-command-for-each-specific-file/"> |
|||
<time class="post-date dt-published" datetime="2021-03-09 21:27:30+0100">09 Mar 2021 |
|||
</time> |
|||
</a> |
|||
<blockquote class="h-cite cite webmentions u-in-reply-to"> |
|||
<h4 class="p-name">Bash: Execute a command in each directory with file my_suites.cfg? |
|||
</h4> |
|||
<section> "I want to create a script which executes a command (similar to make command) in every directory which contains a..." |
|||
</section> |
|||
<p class="metadata"> |
|||
<span class="author p-author h-card">Phi-Long Vu |
|||
</span>on |
|||
<a class="u-url" href="https://unix.stackexchange.com/questions/638389/bash-execute-a-command-in-each-directory-with-file-my-suites-cfg" rel="nofollow" target="_blank">unix.stackexchange.com |
|||
</a> at |
|||
<time class="dt-published" datetime="2021-03-09 14:38:18+0000">09 Mar 2021 |
|||
</time> |
|||
</p> |
|||
</blockquote> |
|||
<div class="e-content p-name"> |
|||
<p>So to summarize the question: You want to run a bash command on each folder that contains a file that has a specific name, one at a time. |
|||
</p> |
|||
<p>Assuming, that you are willing to use existing tools and not write everything from scratch by yourself, here are some ideas: |
|||
</p> |
|||
<h2 id="tldr-too-long-didnt-read">TL;DR |
|||
<em>(Too long, didn’t read) |
|||
</em> |
|||
</h2> |
|||
<p>If it doesn’t matter whether the newest files are not recognized yet: |
|||
</p> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ mlocate --basename --regex "^my_suites.cfg$" \ |
|||
| xargs dirname \ |
|||
| xargs -d '\n' <command-to-run-on-the-file> |
|||
</code></pre></div></div> <p>Else if efficiency is not so important (assuming, that we are searching recursively in the home directory (<code class="language-plaintext highlighter-rouge">~</code>) only:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ find ~ -name "my_suites.cfg" -type f \ |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<p>Else if efficiency is not so important (assuming, that we are searching recursively in the home directory ( |
|||
<code class="language-plaintext highlighter-rouge">~ |
|||
</code>) only: |
|||
</p> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ find ~ -name "my_suites.cfg" -type f \ |
|||
| xargs dirname \ |
|||
| xargs -d '\n' <command-to-run-on-the-file> |
|||
</code></pre></div></div> <hr /> <h2 id="full-version">Full Version</h2> <h3 id="finding-the-files">Finding the files</h3> <p>If the files you are looking for are scattered all over the system, you should care about effectiveness.</p> <h4 id="the-faster-way">The fast(er) way</h4> <p>With some downsides</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ mlocate --basename --regex "^my_suites.cfg$" |
|||
</code></pre></div></div> <ul> <li><code class="language-plaintext highlighter-rouge">mlocate</code> looks up file paths in a database that is updated once a day for most distributions. So it may not recognize recently created or recently moved files. But because it looks into the database instead of going through the file system itself, it’s search is very efficient.</li> <li>The <code class="language-plaintext highlighter-rouge">--basename</code> option specifies that we are looking for the direct name of the file, not including the path/directories of it.</li> <li>The <code class="language-plaintext highlighter-rouge">--regex</code> option enables regular expressions being allowed in the search pattern. (The <code class="language-plaintext highlighter-rouge">^</code> expects the string to start there and the <code class="language-plaintext highlighter-rouge">$</code> expects the string to end there.)</li> </ul> <h4 id="the-always-up-to-date-way">The “always up-to-date” way</h4> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ find / -name "my_suites.cfg" -type f |
|||
</code></pre></div></div> <ul> <li><code class="language-plaintext highlighter-rouge">find</code> goes through basically every folder it can find and lists every file which is named my_suites.cfg. Because of that many reading-operations that it has to do, the more folders it searches the slower it gets.</li> <li>The <code class="language-plaintext highlighter-rouge">-name</code> option specifies, that my_suites.cfg is the <strong>name</strong> of the file, instead of i.e. a folder that contains the file that we are looking for.</li> <li>The <code class="language-plaintext highlighter-rouge">-type</code> option specifies, that we are looking for a <strong>file</strong>, not for a directory, symlink, socket or something.</li> </ul> <h3 id="running-a-custom-command-on-each-of-the-files">Running a custom command on each of the files</h3> <p>… that’s what <code class="language-plaintext highlighter-rouge">xargs</code> is for</p> <h4 id="a-simple-example">A simple example</h4> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ echo "some simple example" | xargs mkdir |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<hr /> |
|||
<h2 id="full-version">Full Version |
|||
</h2> |
|||
<h3 id="finding-the-files">Finding the files |
|||
</h3> |
|||
<p>If the files you are looking for are scattered all over the system, you should care about effectiveness. |
|||
</p> |
|||
<h4 id="the-faster-way">The fast(er) way |
|||
</h4> |
|||
<p>With some downsides |
|||
</p> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ mlocate --basename --regex "^my_suites.cfg$" |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<ul> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">mlocate |
|||
</code> looks up file paths in a database that is updated once a day for most distributions. So it may not recognize recently created or recently moved files. But because it looks into the database instead of going through the file system itself, it’s search is very efficient. |
|||
</li> |
|||
<li>The |
|||
<code class="language-plaintext highlighter-rouge">--basename |
|||
</code> option specifies that we are looking for the direct name of the file, not including the path/directories of it. |
|||
</li> |
|||
<li>The |
|||
<code class="language-plaintext highlighter-rouge">--regex |
|||
</code> option enables regular expressions being allowed in the search pattern. (The |
|||
<code class="language-plaintext highlighter-rouge">^ |
|||
</code> expects the string to start there and the |
|||
<code class="language-plaintext highlighter-rouge">$ |
|||
</code> expects the string to end there.) |
|||
</li> |
|||
</ul> |
|||
<h4 id="the-always-up-to-date-way">The “always up-to-date” way |
|||
</h4> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ find / -name "my_suites.cfg" -type f |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<ul> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">find |
|||
</code> goes through basically every folder it can find and lists every file which is named my_suites.cfg. Because of that many reading-operations that it has to do, the more folders it searches the slower it gets. |
|||
</li> |
|||
<li>The |
|||
<code class="language-plaintext highlighter-rouge">-name |
|||
</code> option specifies, that my_suites.cfg is the |
|||
<strong>name |
|||
</strong> of the file, instead of i.e. a folder that contains the file that we are looking for. |
|||
</li> |
|||
<li>The |
|||
<code class="language-plaintext highlighter-rouge">-type |
|||
</code> option specifies, that we are looking for a |
|||
<strong>file |
|||
</strong>, not for a directory, symlink, socket or something. |
|||
</li> |
|||
</ul> |
|||
<h3 id="running-a-custom-command-on-each-of-the-files">Running a custom command on each of the files |
|||
</h3> |
|||
<p>… that’s what |
|||
<code class="language-plaintext highlighter-rouge">xargs |
|||
</code> is for |
|||
</p> |
|||
<h4 id="a-simple-example">A simple example |
|||
</h4> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ echo "some simple example" | xargs mkdir |
|||
$ # now there are three directories, named by the echoed words |
|||
$ ls |
|||
example simple some |
|||
</code></pre></div></div> <h4 id="something-more-complex">Something more complex:</h4> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ echo "hello world" | xargs -d ' ' -I % echo 'Print a word: %' |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<h4 id="something-more-complex">Something more complex: |
|||
</h4> |
|||
<div class="language-plaintext highlighter-rouge"> |
|||
<div class="highlight"> |
|||
<pre class="highlight"> |
|||
<code>$ echo "hello world" | xargs -d ' ' -I % echo 'Print a word: %' |
|||
Print a word: hello |
|||
Print a word: world |
|||
</code></pre></div></div> <ul> <li><code class="language-plaintext highlighter-rouge">-d</code> option: specifies, which character delimits the arguments from each other (here: a space).</li> <li><code class="language-plaintext highlighter-rouge">-I</code> option: All occurences of the given character (<code class="language-plaintext highlighter-rouge">%</code> in this example) will be replaced by the argument that came from the pipe (before <code class="language-plaintext highlighter-rouge">|</code>)</li> </ul> <p>This is what happens in the above example:</p> <ol> <li><code class="language-plaintext highlighter-rouge">echo</code> prints “hello world” to the standard output (<code class="language-plaintext highlighter-rouge">stdout</code>).</li> <li>The pipe (<code class="language-plaintext highlighter-rouge">|</code>) gives this value (“hello world”) to the following command, which happens to be <code class="language-plaintext highlighter-rouge">xargs</code>.</li> <li><code class="language-plaintext highlighter-rouge">xargs</code> searches for occurences of the delimiter in the argument and splits the argument where it finds the delimiter.</li> <li><code class="language-plaintext highlighter-rouge">xargs</code> loops through the newly created arguments and runs the command with the argument value instead of <code class="language-plaintext highlighter-rouge">%</code></li> </ol> <h3 id="further-readings">Further readings</h3> <ul> <li><a href="https://shapeshed.com/unix-xargs/">Unix xargs</a></li> <li><a href="https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285">Regular Expressions: Tutorial</a></li> <li><a href="https://linux.die.net/man/1/locate">locate man page</a></li> <li>this answer also lives on <a href="https://unix.stackexchange.com/a/638453/459894">unix.stackexchange.com</a></li> </ul> </div> <p><a class="p-category u-tag-of" href="/tags/#stackexchange" > #stackexchange</a> <a class="p-category u-tag-of" href="/tags/#bash" > #bash</a> <a class="p-category u-tag-of" href="/tags/#gnu/linux" > #gnu/linux</a> </p><details> <summary>Meta data</summary><ul class="microformats2"><li> Tags: <ul><li class="p-category"> <a href="https://hoschi-it.de/tags/#stackexchange">stackexchange</a> </li><li class="p-category"> <a href="https://hoschi-it.de/tags/#bash">bash</a> </li><li class="p-category"> <a href="https://hoschi-it.de/tags/#gnu/linux">gnu/linux</a> </li></ul> </li><li> <a class="u-url" href="https://hoschi-it.de/2021/03/09/exec-a-command-for-each-specific-file/"> Permanent post link </a> </li> <li class="p-author h-card" rel="author"> Author <ul> <li>Nickname: <span class="p-name">hoschi-it</span> </li> <li> <a class="u-url p-name" rel="author" href="https://hoschi-it.de/"> Website </a> </li> <li>Profile picture:<img class="u-photo" alt="a kingfischer (bird)" src="/assets/photos/kingfisher.jpeg" width="100" height="100" loading="lazy" /> </li> </ul> </li><li>Also published on <ul><li> <a rel="syndication" class="u-syndication" href="https://unix.stackexchange.com/a/638453/459894">unix.stackexchange.com</a> </li></ul> </li></ul> </details> </article> </main><footer><nav> <ul><li> <a class="" href="/impressum/">Impressum</a> </li><li> <a class="" href="/privacy/">Privacy</a> </li></ul> </nav> <p>© 2021. All rights reserved.</p> </footer> </body> </html> |
|||
|
|||
</code> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
<ul> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">-d |
|||
</code> option: specifies, which character delimits the arguments from each other (here: a space). |
|||
</li> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">-I |
|||
</code> option: All occurences of the given character ( |
|||
<code class="language-plaintext highlighter-rouge">% |
|||
</code> in this example) will be replaced by the argument that came from the pipe (before |
|||
<code class="language-plaintext highlighter-rouge">| |
|||
</code>) |
|||
</li> |
|||
</ul> |
|||
<p>This is what happens in the above example: |
|||
</p> |
|||
<ol> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">echo |
|||
</code> prints “hello world” to the standard output ( |
|||
<code class="language-plaintext highlighter-rouge">stdout |
|||
</code>). |
|||
</li> |
|||
<li>The pipe ( |
|||
<code class="language-plaintext highlighter-rouge">| |
|||
</code>) gives this value (“hello world”) to the following command, which happens to be |
|||
<code class="language-plaintext highlighter-rouge">xargs |
|||
</code>. |
|||
</li> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">xargs |
|||
</code> searches for occurences of the delimiter in the argument and splits the argument where it finds the delimiter. |
|||
</li> |
|||
<li> |
|||
<code class="language-plaintext highlighter-rouge">xargs |
|||
</code> loops through the newly created arguments and runs the command with the argument value instead of |
|||
<code class="language-plaintext highlighter-rouge">% |
|||
</code> |
|||
</li> |
|||
</ol> |
|||
<h3 id="further-readings">Further readings |
|||
</h3> |
|||
<ul> |
|||
<li> |
|||
<a href="https://shapeshed.com/unix-xargs/">Unix xargs |
|||
</a> |
|||
</li> |
|||
<li> |
|||
<a href="https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285">Regular Expressions: Tutorial |
|||
</a> |
|||
</li> |
|||
<li> |
|||
<a href="https://linux.die.net/man/1/locate">locate man page |
|||
</a> |
|||
</li> |
|||
<li>this answer also lives on |
|||
<a href="https://unix.stackexchange.com/a/638453/459894">unix.stackexchange.com |
|||
</a> |
|||
</li> |
|||
</ul> |
|||
</div> |
|||
<p> |
|||
<a class="p-category u-tag-of" href="/tags/#stackexchange" > #stackexchange |
|||
</a> |
|||
<a class="p-category u-tag-of" href="/tags/#bash" > #bash |
|||
</a> |
|||
<a class="p-category u-tag-of" href="/tags/#gnu/linux" > #gnu/linux |
|||
</a> |
|||
</p> |
|||
</article> |
|||
</main> |
|||
</body> |
|||
</html> |
@ -0,0 +1,11 @@ |
|||
# Goals |
|||
|
|||
Here are some things about the webpage (or my tech stack in general) that I want to accomplish: |
|||
|
|||
* ☐ Fix: Jekyll plugin does not find outgoing webmentions |
|||
* ☐ Wikify myself @indiewebcamp.org |
|||
* ☑ Relax |
|||
* ☐ Implement check lists (for real, not just via some specially formatted note post). |
|||
* ☐ put it on the IPFS, just for fun :D |
|||
* ☐ make publishing from mobile possible (via micropub) |
|||
* ☐ generate seperate h-feed and link to it |
@ -0,0 +1,34 @@ |
|||
# History |
|||
[/projects/ducks-landing-page/index.html](/projects/ducks-landing-page/index.html) |
|||
[/404.html](/404.html) |
|||
[/privacy/index.html](/privacy/index.html) |
|||
[/2021/01/02/danke/index.html](/2021/01/02/danke/index.html) |
|||
[/2021/01/05/cli-anwendungen/index.html](/2021/01/05/cli-anwendungen/index.html) |
|||
[/2021/01/05/covid19-musical-vaccine/index.html](/2021/01/05/covid19-musical-vaccine/index.html) |
|||
[/2021/01/06/kein-parser-im-hirn/index.html](/2021/01/06/kein-parser-im-hirn/index.html) |
|||
[/2021/03/17/goals/index.html](/2021/03/17/goals/index.html) |
|||
[/2021/03/17/reply-1/index.html](/2021/03/17/reply-1/index.html) |
|||
[/2021/03/07/bookmark-12-factor-app/index.html](/2021/03/07/bookmark-12-factor-app/index.html) |
|||
[/2021/03/07/indieweb-internetarchive-channel/index.html](/2021/03/07/indieweb-internetarchive-channel/index.html) |
|||
[/2021/03/07/bookmark-resilient-web-design/index.html](/2021/03/07/bookmark-resilient-web-design/index.html) |
|||
[/2021/03/10/rsvp-hwc-europe/index.html](/2021/03/10/rsvp-hwc-europe/index.html) |
|||
[/2021/03/10/bookmark-markdown-syntax-documentation/index.html](/2021/03/10/bookmark-markdown-syntax-documentation/index.html) |
|||
[/2021/03/15/completed-tutorials/index.html](/2021/03/15/completed-tutorials/index.html) |
|||
[/2021/03/09/exec-a-command-for-each-specific-file/index.html](/2021/03/09/exec-a-command-for-each-specific-file/index.html) |
|||
[/2021/03/14/note-test/index.html](/2021/03/14/note-test/index.html) |
|||
[/2021/03/14/plain-note-post-type/index.html](/2021/03/14/plain-note-post-type/index.html) |
|||
[/2021/03/16/like-one-year-in-the-indieweb/index.html](/2021/03/16/like-one-year-in-the-indieweb/index.html) |
|||
[/2021/03/16/bookmark-man-gnu-coreutils/index.html](/2021/03/16/bookmark-man-gnu-coreutils/index.html) |
|||
[/2021/03/12/bookmark-indiewebxyz/index.html](/2021/03/12/bookmark-indiewebxyz/index.html) |
|||
[/2021/03/12/like-non-technical-indieweb/index.html](/2021/03/12/like-non-technical-indieweb/index.html) |
|||
[/2021/03/11/repost-messenger-ausweispflicht/index.html](/2021/03/11/repost-messenger-ausweispflicht/index.html) |
|||
[/2021/03/11/like-what-matters/index.html](/2021/03/11/like-what-matters/index.html) |
|||
[/2021/03/20/note-ipfs-publish/index.html](/2021/03/20/note-ipfs-publish/index.html) |
|||
[/2021/03/13/bookmark-fedbridgy/index.html](/2021/03/13/bookmark-fedbridgy/index.html) |
|||
[/a/deleted/post.html](/a/deleted/post.html) |
|||
[/about/index.html](/about/index.html) |
|||
[/tags/index.html](/tags/index.html) |
|||
[/410.html](/410.html) |
|||
[/replies/2020/2020-12-28-sending-your-first-webmention/index.html](/replies/2020/2020-12-28-sending-your-first-webmention/index.html) |
|||
[/s/1/index.html](/s/1/index.html) |
|||
[/2020/01/01/lets-start/index.html](/2020/01/01/lets-start/index.html) |
@ -0,0 +1,5 @@ |
|||
local meta_date="2021-03-17T18:39:11+01:00" |
|||
local meta_author="hoschi-it" |
|||
local meta_email="me@hoschi-it.de" |
|||
local meta_title="Goals" |
|||
local meta_summary=". .....to read on please visit my site." |
@ -0,0 +1,3 @@ |
|||
Source;Target |
|||
/2021/03/17/goals/index.html;/gemfeed/2021-03-17-goals.html |
|||
/2020/01/01/lets-start/index.html;/gemfeed/2020-01-01-lets-start.html |
Write
Preview
Loading…
Cancel
Save
Reference in new issue