You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
5.1 KiB
168 lines
5.1 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="generator" content="Asciidoctor 2.0.12">
|
|
<meta name="description" content="Intro and Install">
|
|
<meta name="keywords" content="Linux, apt">
|
|
<meta name="author" content="Apostolos rootApostolos@swarmlab.io">
|
|
<title>An Introduction to Linux !</title>
|
|
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/asciidoctor.js/1.5.9/css/asciidoctor.min.css">
|
|
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/styles/github.min.css">
|
|
</head>
|
|
<body class="article toc2 toc-right">
|
|
<div id="header">
|
|
<h1>An Introduction to Linux !</h1>
|
|
<div class="details">
|
|
<span id="author" class="author">Apostolos rootApostolos@swarmlab.io</span><br>
|
|
</div>
|
|
<div id="toc" class="toc2">
|
|
<div id="toctitle">Table of contents</div>
|
|
<ul class="sectlevel1">
|
|
<li><a href="#_find_and_grep">1. Find and grep</a>
|
|
<ul class="sectlevel2">
|
|
<li><a href="#_find">1.1. find</a></li>
|
|
<li><a href="#_grep">1.2. grep</a></li>
|
|
<li><a href="#_find_and_grep_command_together">1.3. find and grep command together</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div id="content">
|
|
<div class="sect1">
|
|
<h2 id="_find_and_grep">1. Find and grep</h2>
|
|
<div class="sectionbody">
|
|
<div class="sect2">
|
|
<h3 id="_find">1.1. find</h3>
|
|
<div class="paragraph">
|
|
<p>The find tool, known from UNIX, is very powerful. This command not only allows you to search file names, it can also accept file size, date of last change and other file properties as criteria for a search.</p>
|
|
</div>
|
|
<div class="paragraph">
|
|
<p>The most common use is for finding file names:</p>
|
|
</div>
|
|
<div class="admonitionblock note">
|
|
<table>
|
|
<tr>
|
|
<td class="icon">
|
|
<i class="fa icon-note" title="Note"></i>
|
|
</td>
|
|
<td class="content">
|
|
find <path> -name <searchstring>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="paragraph">
|
|
<p>This can be interpreted as "Look in all files and subdirectories contained in a given path, and print the names of the files containing the search string in their name" <strong>(not in their content).</strong></p>
|
|
</div>
|
|
<div class="listingblock">
|
|
<div class="content">
|
|
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash"> find /etc -name "*.conf"</code></pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sect2">
|
|
<h3 id="_grep">1.2. grep</h3>
|
|
<div class="paragraph">
|
|
<p>grep is used for filtering input lines and returning certain patterns to the output.</p>
|
|
</div>
|
|
<div class="admonitionblock note">
|
|
<table>
|
|
<tr>
|
|
<td class="icon">
|
|
<i class="fa icon-note" title="Note"></i>
|
|
</td>
|
|
<td class="content">
|
|
grep "string" path/to/file
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="listingblock">
|
|
<div class="content">
|
|
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash"> grep "root" /etc/passwd</code></pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sect2">
|
|
<h3 id="_find_and_grep_command_together">1.3. find and grep command together</h3>
|
|
<div class="paragraph">
|
|
<p>find /etc -name "*.conf" -exec grep -Hns "conf" {} \;</p>
|
|
</div>
|
|
<div class="listingblock">
|
|
<div class="title">Explanation</div>
|
|
<div class="content">
|
|
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">-H, --with-filename
|
|
Print the filename for each match
|
|
-n, --line-number
|
|
Prefix each line of output with the 1-based line number within its input file
|
|
-s, --no-messages
|
|
Suppress error messages about nonexistent or unreadable files.</code></pre>
|
|
</div>
|
|
</div>
|
|
<div class="admonitionblock note">
|
|
<table>
|
|
<tr>
|
|
<td class="icon">
|
|
<i class="fa icon-note" title="Note"></i>
|
|
</td>
|
|
<td class="content">
|
|
This can be interpreted as<br>
|
|
- "Look for *.conf files and subdirectories contained in /etc, and <strong>if true</strong> exec <strong>grep -Hns conf</strong> in the given file"
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="admonitionblock tip">
|
|
<table>
|
|
<tr>
|
|
<td class="icon">
|
|
<i class="fa icon-tip" title="Tip"></i>
|
|
</td>
|
|
<td class="content">
|
|
Very powerful in bash scripts
|
|
create a file test.sh
|
|
.bash script
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="listingblock">
|
|
<div class="content">
|
|
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">#!/bin/bash
|
|
STRING=$(find /etc -name "*.conf" -exec grep -Hns "conf" {} \;)
|
|
echo $STRING</code></pre>
|
|
</div>
|
|
</div>
|
|
<div class="paragraph">
|
|
<p>exec it
|
|
.bash script</p>
|
|
</div>
|
|
<div class="listingblock">
|
|
<div class="content">
|
|
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">chmod 700 test.sh
|
|
./test.sh</code></pre>
|
|
</div>
|
|
</div>
|
|
<div class="paragraph">
|
|
<p><br>
|
|
<br>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/highlight.min.js"></script>
|
|
<script>
|
|
if (!hljs.initHighlighting.called) {
|
|
hljs.initHighlighting.called = true
|
|
;[].slice.call(document.querySelectorAll('pre.highlight > code')).forEach(function (el) { hljs.highlightBlock(el) })
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|