mirror of
https://github.com/linkedin/school-of-sre
synced 2026-01-20 07:28:03 +00:00
Deployed 4239ecf with MkDocs version: 1.2.3
This commit is contained in:
@@ -2522,40 +2522,83 @@
|
||||
|
||||
<h1 id="command-line-basics">Command Line Basics</h1>
|
||||
<h2 id="lab-environment-setup">Lab Environment Setup</h2>
|
||||
<p>One can use an online bash interpreter to run all the commands that are provided as examples in this course. This will also help you in getting a hands-on experience of various linux commands.</p>
|
||||
<p><a href="https://repl.it/languages/bash">REPL</a> is one of the popular online bash interpreters for running linux commands. We will be using it for running all the commands mentioned in this course.</p>
|
||||
<p>One can use an online Bash interpreter to run all the commands that are provided as examples in this course. This will also help you in getting a hands-on experience of various Linux commands.</p>
|
||||
<p><a href="https://repl.it/languages/bash">REPL</a> is one of the popular online Bash interpreters for running Linux commands. We will be using it for running all the commands mentioned in this course.</p>
|
||||
<h2 id="what-is-a-command">What is a Command</h2>
|
||||
<p>A command is a program that tells the operating system to perform
|
||||
specific work. Programs are stored as files in linux. Therefore, a
|
||||
specific work. Programs are stored as files in Linux. Therefore, a
|
||||
command is also a file which is stored somewhere on the disk.</p>
|
||||
<p>Commands may also take additional arguments as input from the user.
|
||||
These arguments are called command line arguments. Knowing how to use
|
||||
the commands is important and there are many ways to get help in Linux,
|
||||
especially for commands. Almost every command will have some form of
|
||||
documentation, most commands will have a command-line argument -h or
|
||||
--help that will display a reasonable amount of documentation. But the
|
||||
most popular documentation system in Linux is called man pages - short
|
||||
documentation, most commands will have a command-line argument <code>-h</code> or
|
||||
<code>--help</code> that will display a reasonable amount of documentation. But the
|
||||
most popular documentation system in Linux is called <code>man</code> pages—short
|
||||
for manual pages.</p>
|
||||
<p>Using --help to show the documentation for ls command.</p>
|
||||
<p>Using <code>--help</code> to show the documentation for <code>ls</code> command.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image19.png" /></p>
|
||||
<h2 id="file-system-organization">File System Organization</h2>
|
||||
<p>The linux file system has a hierarchical (or tree-like) structure with
|
||||
its highest level directory called root ( denoted by / ). Directories
|
||||
present inside the root directory stores file related to the system.
|
||||
<p>The Linux file system has a hierarchical (or tree-like) structure with
|
||||
its highest-level directory called <code>root</code> (denoted by <code>/</code>). Directories
|
||||
present inside the root directory stores files related to the system.
|
||||
These directories in turn can either store system files or application
|
||||
files or user related files.</p>
|
||||
files or user-related files.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image17.png" /></p>
|
||||
<p>bin | The executable program of most commonly used commands reside in bin directory</p>
|
||||
<p>dev | This directory contains files related to devices on the system </p>
|
||||
<p>etc | This directory contains all the system configuration files</p>
|
||||
<p>home | This directory contains user related files and directories.</p>
|
||||
<p>lib | This directory contains all the library files</p>
|
||||
<p>mnt | This directory contains files related to mounted devices on the system</p>
|
||||
<p>proc | This directory contains files related to the running processes on the system</p>
|
||||
<p>root | This directory contains root user related files and directories.</p>
|
||||
<p>sbin | This directory contains programs used for system administration.</p>
|
||||
<p>tmp | This directory is used to store temporary files on the system</p>
|
||||
<p>usr | This directory is used to store application programs on the system</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Directory</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>bin</td>
|
||||
<td>The executable program of most commonly used commands reside in <code>bin</code> directory</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>dev</td>
|
||||
<td>This directory contains files related to devices on the system</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>etc</td>
|
||||
<td>This directory contains all the system configuration files</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>home</td>
|
||||
<td>This directory contains user-related files and directories</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>lib</td>
|
||||
<td>This directory contains all the library files</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>mnt</td>
|
||||
<td>This directory contains files related to mounted devices on the system</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>proc</td>
|
||||
<td>This directory contains files related to the running processes on the system</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>root</td>
|
||||
<td>This directory contains root user-related files and directories</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>sbin</td>
|
||||
<td>This directory contains programs used for system administration</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>tmp</td>
|
||||
<td>This directory is used to store temporary files on the system</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>usr</td>
|
||||
<td>This directory is used to store application programs on the system</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2 id="commands-for-navigating-the-file-system">Commands for Navigating the File System</h2>
|
||||
<p>There are three basic commands which are used frequently to navigate the
|
||||
file system:</p>
|
||||
@@ -2572,28 +2615,28 @@ file system:</p>
|
||||
</ul>
|
||||
<p>We will now try to understand what each command does and how to use
|
||||
these commands. You should also practice the given examples on the
|
||||
online bash shell.</p>
|
||||
online Bash shell.</p>
|
||||
<h3 id="pwd-print-working-directory">pwd (print working directory)</h3>
|
||||
<p>At any given moment of time, we will be standing in a certain directory.
|
||||
To get the name of the directory in which we are standing, we can use
|
||||
the pwd command in linux.</p>
|
||||
the <code>pwd</code> command in Linux.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image2.png" /></p>
|
||||
<p>We will now use the cd command to move to a different directory and then
|
||||
<p>We will now use the <code>cd</code> command to move to a different directory and then
|
||||
print the working directory.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image20.png" /></p>
|
||||
<h3 id="cd-change-directory">cd (change directory)</h3>
|
||||
<p>The cd command can be used to change the working directory. Using the
|
||||
<p>The <code>cd</code> command can be used to change the working directory. Using the
|
||||
command, you can move from one directory to another.</p>
|
||||
<p>In the below example, we are initially in the root directory. we have
|
||||
then used the cd command to change the directory.</p>
|
||||
<p>In the below example, we are initially in the <code>root</code> directory. We have
|
||||
then used the <code>cd</code> command to change the directory.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image3.png" /></p>
|
||||
<h3 id="ls-list-files-and-directories">ls (list files and directories)**</h3>
|
||||
<p>The ls command is used to list the contents of a directory. It will list
|
||||
<p>The <code>ls</code> command is used to list the contents of a directory. It will list
|
||||
down all the files and folders present in the given directory.</p>
|
||||
<p>If we just type ls in the shell, it will list all the files and
|
||||
<p>If we just type <code>ls</code> in the shell, it will list all the files and
|
||||
directories present in the current directory.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image7.png" /></p>
|
||||
<p>We can also provide the directory name as argument to ls command. It
|
||||
<p>We can also provide the directory name as argument to <code>ls</code> command. It
|
||||
will then list all the files and directories inside the given directory.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image4.png" /></p>
|
||||
<h2 id="commands-for-manipulating-files">Commands for Manipulating Files</h2>
|
||||
@@ -2618,80 +2661,80 @@ files:</p>
|
||||
</ul>
|
||||
<p>We will now try to understand what each command does and how to use
|
||||
these commands. You should also practice the given examples on the
|
||||
online bash shell.</p>
|
||||
online Bash shell.</p>
|
||||
<h3 id="touch-create-new-file">touch (create new file)</h3>
|
||||
<p>The touch command can be used to create an empty new file.
|
||||
This command is very useful for many other purposes but we will discuss
|
||||
<p>The <code>touch</code> command can be used to create an empty new file.
|
||||
This command is very useful for many other purposes, but we will discuss
|
||||
the simplest use case of creating a new file.</p>
|
||||
<p>General syntax of using touch command</p>
|
||||
<pre><code>touch <file_name>
|
||||
<p>General syntax of using <code>touch</code> command:</p>
|
||||
<pre><code class="language-shell">touch <file_name>
|
||||
</code></pre>
|
||||
<p><img alt="" src="../images/linux/commands/image9.png" /></p>
|
||||
<h3 id="mkdir-create-new-directories">mkdir (create new directories)</h3>
|
||||
<p>The mkdir command is used to create directories.You can use ls command
|
||||
<p>The <code>mkdir</code> command is used to create directories. You can use <code>ls</code> command
|
||||
to verify that the new directory is created.</p>
|
||||
<p>General syntax of using mkdir command</p>
|
||||
<pre><code>mkdir <directory_name>
|
||||
<p>General syntax of using <code>mkdir</code> command:</p>
|
||||
<pre><code class="language-shell">mkdir <directory_name>
|
||||
</code></pre>
|
||||
<p><img alt="" src="../images/linux/commands/image11.png" /></p>
|
||||
<h3 id="rm-delete-files-and-directories">rm (delete files and directories)</h3>
|
||||
<p>The rm command can be used to delete files and directories. It is very
|
||||
<p>The <code>rm</code> command can be used to delete files and directories. It is very
|
||||
important to note that this command permanently deletes the files and
|
||||
directories. It's almost impossible to recover these files and
|
||||
directories once you have executed rm command on them successfully. Do
|
||||
directories once you have executed <code>rm</code> command on them successfully. Do
|
||||
run this command with care.</p>
|
||||
<p>General syntax of using rm command:</p>
|
||||
<pre><code>rm <file_name>
|
||||
<p>General syntax of using <code>rm</code> command:</p>
|
||||
<pre><code class="language-shell">rm <file_name>
|
||||
</code></pre>
|
||||
<p>Let's try to understand the rm command with an example. We will try to
|
||||
delete the file and directory we created using touch and mkdir command
|
||||
<p>Let's try to understand the <code>rm</code> command with an example. We will try to
|
||||
delete the file and directory we created using <code>touch</code> and <code>mkdir</code> command
|
||||
respectively.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image18.png" /></p>
|
||||
<h3 id="cp-copy-files-and-directories">cp (copy files and directories)</h3>
|
||||
<p>The cp command is used to copy files and directories from one location
|
||||
to another. Do note that the cp command doesn't do any change to the
|
||||
<p>The <code>cp</code> command is used to copy files and directories from one location
|
||||
to another. Do note that the <code>cp</code> command doesn't do any change to the
|
||||
original files or directories. The original files or directories and
|
||||
their copy both co-exist after running cp command successfully.</p>
|
||||
<p>General syntax of using cp command:</p>
|
||||
<pre><code>cp <source_path> <destination_path>
|
||||
their copy both co-exist after running <code>cp</code> command successfully.</p>
|
||||
<p>General syntax of using <code>cp</code> command:</p>
|
||||
<pre><code class="language-shell">cp <source_path> <destination_path>
|
||||
</code></pre>
|
||||
<p>We are currently in the '/home/runner' directory. We will use the mkdir
|
||||
command to create a new directory named "test_directory". We will now
|
||||
try to copy the "_test_runner.py" file to the directory we created just
|
||||
<p>We are currently in the <code>/home/runner</code> directory. We will use the <code>mkdir</code>
|
||||
command to create a new directory named <code>test_directory</code>. We will now
|
||||
try to copy the <code>_test_runner.py</code> file to the directory we created just
|
||||
now.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image23.png" /></p>
|
||||
<p>Do note that nothing happened to the original "_test_runner.py" file.
|
||||
<p>Do note that nothing happened to the original <code>_test_runner.py</code> file.
|
||||
It's still there in the current directory. A new copy of it got created
|
||||
inside the "test_directory".</p>
|
||||
inside the <code>test_directory</code>.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image14.png" /></p>
|
||||
<p>We can also use the cp command to copy the whole directory from one
|
||||
<p>We can also use the <code>cp</code> command to copy the whole directory from one
|
||||
location to another. Let's try to understand this with an example.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image12.png" /></p>
|
||||
<p>We again used the mkdir command to create a new directory called
|
||||
"another_directory". We then used the cp command along with an
|
||||
additional argument '-r' to copy the "test_directory".</p>
|
||||
<p>We again used the <code>mkdir</code> command to create a new directory called
|
||||
<code>another_directory</code>. We then used the <code>cp</code> command along with an
|
||||
additional argument <code>-r</code> to copy the <code>test_directory</code>.</p>
|
||||
<p><strong>mv (move files and directories)</strong></p>
|
||||
<p>The mv command can either be used to move files or directories from one
|
||||
<p>The <code>mv</code> command can either be used to move files or directories from one
|
||||
location to another or it can be used to rename files or directories. Do
|
||||
note that moving files and copying them are very different. When you
|
||||
move the files or directories, the original copy is lost.</p>
|
||||
<p>General syntax of using mv command:</p>
|
||||
<pre><code>mv <source_path> <destination_path>
|
||||
<p>General syntax of using <code>mv</code> command:</p>
|
||||
<pre><code class="language-shell">mv <source_path> <destination_path>
|
||||
</code></pre>
|
||||
<p>In this example, we will use the mv command to move the
|
||||
"_test_runner.py" file to "test_directory". In this case, this file
|
||||
already exists in "test_directory". The mv command will just replace it.
|
||||
<p>In this example, we will use the <code>mv</code> command to move the
|
||||
<code>_test_runner.py</code> file to <code>test_directory</code>. In this case, this file
|
||||
already exists in <code>test_directory</code>. The <code>mv</code> command will just replace it.
|
||||
<strong>Do note that the original file doesn't exist in the current directory
|
||||
after mv command ran successfully.</strong></p>
|
||||
after <code>mv</code> command ran successfully.</strong></p>
|
||||
<p><img alt="" src="../images/linux/commands/image26.png" /></p>
|
||||
<p>We can also use the mv command to move a directory from one location to
|
||||
another. In this case, we do not need to use the '-r' flag that we did
|
||||
while using the cp command. Do note that the original directory will not
|
||||
exist if we use mv command.</p>
|
||||
<p>One of the important uses of the mv command is to rename files and
|
||||
<p>We can also use the <code>mv</code> command to move a directory from one location to
|
||||
another. In this case, we do not need to use the <code>-r</code> flag that we did
|
||||
while using the <code>cp</code> command. Do note that the original directory will not
|
||||
exist if we use <code>mv</code> command.</p>
|
||||
<p>One of the important uses of the <code>mv</code> command is to rename files and
|
||||
directories. Let's see how we can use this command for renaming.</p>
|
||||
<p>We have first changed our location to "test_directory". We then use the
|
||||
mv command to rename the ""_test_runner.py" file to "test.py".</p>
|
||||
<p>We have first changed our location to <code>test_directory</code>. We then use the
|
||||
<code>mv</code> command to rename the <code>_test_runner.py</code> file to <code>test.py</code>.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image29.png" /></p>
|
||||
<h2 id="commands-for-viewing-files">Commands for Viewing Files</h2>
|
||||
<p>There are five basic commands which are used frequently to view the
|
||||
@@ -2715,8 +2758,8 @@ files:</p>
|
||||
</ul>
|
||||
<p>We will now try to understand what each command does and how to use
|
||||
these commands. You should also practice the given examples on the
|
||||
online bash shell.</p>
|
||||
<p>We will create a new file called "numbers.txt" and insert numbers from 1
|
||||
online Bash shell.</p>
|
||||
<p>We will create a new file called <code>numbers.txt</code> and insert numbers from 1
|
||||
to 100 in this file. Each number will be in a separate line.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image21.png" /></p>
|
||||
<p>Do not worry about the above command now. It's an advanced command which
|
||||
@@ -2724,7 +2767,7 @@ is used to generate numbers. We have then used a redirection operator to
|
||||
push these numbers to the file. We will be discussing I/O redirection in the
|
||||
later sections.</p>
|
||||
<h3 id="cat">cat</h3>
|
||||
<p>The most simplest use of cat command is to print the contents of the file on
|
||||
<p>The most simplest use of <code>cat</code> command is to print the contents of the file on
|
||||
your output screen. This command is very useful and can be used for many
|
||||
other purposes. We will study about other use cases later.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image1.png" /></p>
|
||||
@@ -2732,42 +2775,42 @@ other purposes. We will study about other use cases later.</p>
|
||||
printed from 1 to 100 on your screen. You will need to scroll up to view
|
||||
all the numbers.</p>
|
||||
<h3 id="head">head</h3>
|
||||
<p>The head command displays the first 10 lines of the file by default. We
|
||||
<p>The <code>head</code> command displays the first 10 lines of the file by default. We
|
||||
can include additional arguments to display as many lines as we want
|
||||
from the top.</p>
|
||||
<p>In this example, we are only able to see the first 10 lines from the
|
||||
file when we use the head command.</p>
|
||||
file when we use the <code>head</code> command.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image15.png" /></p>
|
||||
<p>By default, head command will only display the first 10 lines. If we
|
||||
<p>By default, <code>head</code> command will only display the first 10 lines. If we
|
||||
want to specify the number of lines we want to see from start, use the
|
||||
'-n' argument to provide the input.</p>
|
||||
<code>-n</code> argument to provide the input.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image16.png" /></p>
|
||||
<h3 id="tail">tail</h3>
|
||||
<p>The tail command displays the last 10 lines of the file by default. We
|
||||
<p>The <code>tail</code> command displays the last 10 lines of the file by default. We
|
||||
can include additional arguments to display as many lines as we want
|
||||
from the end of the file.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image22.png" /></p>
|
||||
<p>By default, the tail command will only display the last 10 lines. If we
|
||||
want to specify the number of lines we want to see from the end, use '-n'
|
||||
<p>By default, the <code>tail</code> command will only display the last 10 lines. If we
|
||||
want to specify the number of lines we want to see from the end, use <code>-n</code>
|
||||
argument to provide the input.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image10.png" /></p>
|
||||
<p>In this example, we are only able to see the last 5 lines from the file
|
||||
when we use the tail command with explicit -n option.</p>
|
||||
when we use the <code>tail</code> command with explicit <code>-n</code> option.</p>
|
||||
<h3 id="more">more</h3>
|
||||
<p>More command displays the contents of a file or a command output,
|
||||
<p>The <code>more</code> command displays the contents of a file or a command output,
|
||||
displaying one screen at a time in case the file is large (Eg: log files).
|
||||
It also allows forward navigation and limited backward navigation in the file.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image33.png" /></p>
|
||||
<p>More command displays as much as can fit on the current screen and waits for user input to advance. Forward navigation can be done by pressing Enter, which advances the output by one line and Space, which advances the output by one screen.</p>
|
||||
<p>The <code>more</code> command displays as much as can fit on the current screen and waits for user input to advance. Forward navigation can be done by pressing <code>Enter</code>, which advances the output by one line and <code>Space</code>, which advances the output by one screen.</p>
|
||||
<h3 id="less">less</h3>
|
||||
<p>Less command is an improved version of more. It displays the contents of a file or a command output, one page at a time.
|
||||
It allows backward navigation as well as forward navigation in the file and also has search options. We can use arrow keys for advancing backward or forward by one line. For moving forward by one page, press Space and for moving backward by one page, press b on your keyboard.
|
||||
<p>The <code>less</code> command is an improved version of <code>more</code>. It displays the contents of a file or a command output, one page at a time.
|
||||
It allows backward navigation as well as forward navigation in the file and also has search options. We can use <code>arrow keys</code> for advancing backward or forward by one line. For moving forward by one page, press <code>Space</code> and for moving backward by one page, press <code>b</code> on your keyboard.
|
||||
You can go to the beginning and the end of a file instantly.</p>
|
||||
<h2 id="echo-command-in-linux">Echo Command in Linux</h2>
|
||||
<p>The echo command is one of the simplest commands that is used in the
|
||||
shell. This command is equivalent to what we have <print> in other
|
||||
<p>The <code>echo</code> command is one of the simplest commands that is used in the
|
||||
shell. This command is equivalent to <code>print</code> in other
|
||||
programming languages.</p>
|
||||
<p>The echo command prints the given input string on the screen.</p>
|
||||
<p>The <code>echo</code> command prints the given input string on the screen.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image34.png" /></p>
|
||||
<h2 id="text-processing-commands">Text Processing Commands</h2>
|
||||
<p>In the previous section, we learned how to view the content of a file.
|
||||
@@ -2798,39 +2841,39 @@ texts:</p>
|
||||
</ul>
|
||||
<p>We will now try to understand what each command does and how to use
|
||||
these commands. You should also practice the given examples on the
|
||||
online bash shell.</p>
|
||||
<p>We will create a new file called "numbers.txt" and insert numbers from 1
|
||||
online Bash shell.</p>
|
||||
<p>We will create a new file called <code>numbers.txt</code> and insert numbers from 1
|
||||
to 10 in this file. Each number will be in a separate line.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image8.png" /></p>
|
||||
<h3 id="grep">grep</h3>
|
||||
<p>The grep command in its simplest form can be used to search particular
|
||||
<p>The <code>grep</code> command in its simplest form can be used to search particular
|
||||
words in a text file. It will display all the lines in a file that
|
||||
contains a particular input. The word we want to search is provided as
|
||||
an input to the grep command.</p>
|
||||
<p>General syntax of using grep command:</p>
|
||||
<pre><code>grep <word_to_search> <file_name>
|
||||
an input to the <code>grep</code> command.</p>
|
||||
<p>General syntax of using <code>grep</code> command:</p>
|
||||
<pre><code class="language-shell">grep <word_to_search> <file_name>
|
||||
</code></pre>
|
||||
<p>In this example, we are trying to search for a string "1" in this file.
|
||||
The grep command outputs the lines where it found this string.</p>
|
||||
The <code>grep</code> command outputs the lines where it found this string.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image36.png" /></p>
|
||||
<h3 id="sed">sed</h3>
|
||||
<p>The sed command in its simplest form can be used to replace a text in a
|
||||
<p>The <code>sed</code> command in its simplest form can be used to replace a text in a
|
||||
file.</p>
|
||||
<p>General syntax of using the sed command for replacement:</p>
|
||||
<pre><code>sed 's/<text_to_replace>/<replacement_text>/' <file_name>
|
||||
<p>General syntax of using the <code>sed</code> command for replacement:</p>
|
||||
<pre><code class="language-shell">sed 's/<text_to_replace>/<replacement_text>/' <file_name>
|
||||
</code></pre>
|
||||
<p>Let's try to replace each occurrence of "1" in the file with "3" using
|
||||
sed command.</p>
|
||||
<code>sed</code> command.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image31.png" /></p>
|
||||
<p>The content of the file will not change in the above
|
||||
example. To do so, we have to use an extra argument '-i' so that the
|
||||
example. To do so, we have to use an extra argument <code>-i</code> so that the
|
||||
changes are reflected back in the file.</p>
|
||||
<h3 id="sort">sort</h3>
|
||||
<p>The sort command can be used to sort the input provided to it as an
|
||||
<p>The <code>sort</code> command can be used to sort the input provided to it as an
|
||||
argument. By default, it will sort in increasing order.</p>
|
||||
<p>Let's first see the content of the file before trying to sort it.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image27.png" /></p>
|
||||
<p>Now, we will try to sort the file using the sort command. The sort
|
||||
<p>Now, we will try to sort the file using the <code>sort</code> command. The <code>sort</code>
|
||||
command sorts the content in lexicographical order.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image32.png" /></p>
|
||||
<p>The content of the file will not change in the above
|
||||
@@ -2838,28 +2881,28 @@ example.</p>
|
||||
<h2 id="io-redirection">I/O Redirection</h2>
|
||||
<p>Each open file gets assigned a file descriptor. A file descriptor is an
|
||||
unique identifier for open files in the system. There are always three
|
||||
default files open, stdin (the keyboard), stdout (the screen), and
|
||||
stderr (error messages output to the screen). These files can be
|
||||
default files open, <code>stdin</code> (the keyboard), <code>stdout</code> (the screen), and
|
||||
<code>stderr</code> (error messages output to the screen). These files can be
|
||||
redirected.</p>
|
||||
<p>Everything is a file in linux -
|
||||
<p>Everything is a file in Linux -
|
||||
<a href="https://unix.stackexchange.com/questions/225537/everything-is-a-file">https://unix.stackexchange.com/questions/225537/everything-is-a-file</a></p>
|
||||
<p>Till now, we have displayed all the output on the screen which is the
|
||||
standard output. We can use some special operators to redirect the
|
||||
output of the command to files or even to the input of other commands.
|
||||
I/O redirection is a very powerful feature.</p>
|
||||
<p>In the below example, we have used the '>' operator to redirect the
|
||||
output of ls command to output.txt file.</p>
|
||||
<p>In the below example, we have used the <code>></code> operator to redirect the
|
||||
output of <code>ls</code> command to <code>output.txt</code> file.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image30.png" /></p>
|
||||
<p>In the below example, we have redirected the output from echo command to
|
||||
<p>In the below example, we have redirected the output from <code>echo</code> command to
|
||||
a file.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image13.png" /></p>
|
||||
<p>We can also redirect the output of a command as an input to another
|
||||
command. This is possible with the help of pipes.</p>
|
||||
<p>In the below example, we have passed the output of cat command as an
|
||||
input to grep command using pipe(|) operator.</p>
|
||||
<p>In the below example, we have passed the output of <code>cat</code> command as an
|
||||
input to <code>grep</code> command using pipe (<code>|</code>) operator.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image6.png" /></p>
|
||||
<p>In the below example, we have passed the output of sort command as an
|
||||
input to uniq command using pipe(|) operator. The uniq command only
|
||||
<p>In the below example, we have passed the output of <code>sort</code> command as an
|
||||
input to <code>uniq</code> command using pipe (<code>|</code>) operator. The <code>uniq</code> command only
|
||||
prints the unique numbers from the input.</p>
|
||||
<p><img alt="" src="../images/linux/commands/image28.png" /></p>
|
||||
<p>I/O redirection -
|
||||
|
||||
@@ -334,7 +334,7 @@
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#useful-courses-and-tutorials" class="md-nav__link">
|
||||
Useful Courses and tutorials
|
||||
Useful Courses and Tutorials
|
||||
</a>
|
||||
|
||||
</li>
|
||||
@@ -2146,7 +2146,7 @@
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#useful-courses-and-tutorials" class="md-nav__link">
|
||||
Useful Courses and tutorials
|
||||
Useful Courses and Tutorials
|
||||
</a>
|
||||
|
||||
</li>
|
||||
@@ -2165,7 +2165,7 @@
|
||||
|
||||
|
||||
<h1 id="conclusion">Conclusion</h1>
|
||||
<p>We have covered the basics of Linux operating systems and basic commands used in linux.
|
||||
<p>We have covered the basics of Linux operating systems and basic commands used in Linux.
|
||||
We have also covered the Linux server administration commands.</p>
|
||||
<p>We hope that this course will make it easier for you to operate on the command line.</p>
|
||||
<h2 id="applications-in-sre-role">Applications in SRE Role</h2>
|
||||
@@ -2176,12 +2176,12 @@ We have also covered the Linux server administration commands.</p>
|
||||
<li><code>tail</code> command is very useful to view the latest data in the log file.</li>
|
||||
<li>Different users will have different permissions depending on their roles. We will also not want everyone in the company to access our servers for security reasons. Users permissions can be restricted with <code>chown</code>, <code>chmod</code> and <code>chgrp</code> commands.</li>
|
||||
<li><code>ssh</code> is one of the most frequently used commands for a SRE. Logging into servers and troubleshooting along with performing basic administration tasks will only be possible if we are able to login into the server.</li>
|
||||
<li>What if we want to run an apache server or nginx on a server? We will first install it using the package manager. Package management commands become important here.</li>
|
||||
<li>Managing services on servers is another critical responsibility of a SRE. Systemd related commands can help in troubleshooting issues. If a service goes down, we can start it using <code>systemctl start</code> command. We can also stop a service in case it is not needed.</li>
|
||||
<li>Monitoring is another core responsibility of a SRE. Memory and CPU are two important system level metrics which should be monitored. Commands like <code>top</code> and <code>free</code> are quite helpful here.</li>
|
||||
<li>If a service is throwing an error, how do we find out the root cause of the error ? We will certainly need to check logs to find out the whole stack trace of the error. The log file will also tell us the number of times the error has occurred along with time when it started.</li>
|
||||
<li>What if we want to run an Apache server or NGINX on a server? We will first install it using the package manager. Package management commands become important here.</li>
|
||||
<li>Managing services on servers is another critical responsibility of a SRE. <code>systemd</code>-related commands can help in troubleshooting issues. If a service goes down, we can start it using <code>systemctl start</code> command. We can also stop a service in case it is not needed.</li>
|
||||
<li>Monitoring is another core responsibility of a SRE. Memory and CPU are two important system-level metrics which should be monitored. Commands like <code>top</code> and <code>free</code> are quite helpful here.</li>
|
||||
<li>If a service throws an error, how do we find out the root cause of the error? We will certainly need to check logs to find out the whole stack trace of the error. The log file will also tell us the number of times the error has occurred along with time when it started.</li>
|
||||
</ol>
|
||||
<h2 id="useful-courses-and-tutorials">Useful Courses and tutorials</h2>
|
||||
<h2 id="useful-courses-and-tutorials">Useful Courses and Tutorials</h2>
|
||||
<ul>
|
||||
<li><a href="https://courses.edx.org/courses/course-v1:LinuxFoundationX+LFS101x+1T2020/course/">Edx basic linux commands course</a></li>
|
||||
<li><a href="https://courses.edx.org/courses/course-v1:RedHat+RH066x+2T2017/course/">Edx Red Hat Enterprise Linux Course</a></li>
|
||||
|
||||
@@ -2306,7 +2306,7 @@
|
||||
<h2 id="introduction">Introduction</h2>
|
||||
<h3 id="prerequisites">Prerequisites</h3>
|
||||
<ul>
|
||||
<li>Should be comfortable in using any operating systems like Windows, Linux or Mac</li>
|
||||
<li>Should be comfortable in using any operating systems like Windows, Linux or</li>
|
||||
<li>Expected to have fundamental knowledge of operating systems</li>
|
||||
</ul>
|
||||
<h2 id="what-to-expect-from-this-course">What to expect from this course</h2>
|
||||
@@ -2316,13 +2316,13 @@ Linux distributions and uses of Linux operating systems. We will also talk about
|
||||
difference between GUI and CLI.</p>
|
||||
<p>In the second part, we cover some basic commands used in Linux.
|
||||
We will focus on commands used for navigating the file system, viewing and manipulating files,
|
||||
I/O redirection etc.</p>
|
||||
<p>In the third part, we cover Linux system administration. This includes day to day tasks
|
||||
I/O redirection, etc.</p>
|
||||
<p>In the third part, we cover Linux system administration. This includes day-to-day tasks
|
||||
performed by Linux admins, like managing users/groups, managing file permissions,
|
||||
monitoring system performance, log files etc.</p>
|
||||
<p>In the second and third part, we will be taking examples to understand the concepts.</p>
|
||||
<p>In the second and third part, we will be showing examples to understand the concepts.</p>
|
||||
<h2 id="what-is-not-covered-under-this-course">What is not covered under this course</h2>
|
||||
<p>We are not covering advanced Linux commands and bash scripting in this
|
||||
<p>We are not covering advanced Linux commands and Bash scripting in this
|
||||
course. We will also not be covering Linux internals. </p>
|
||||
<h2 id="course-contents">Course Contents</h2>
|
||||
<p>The following topics has been covered in this course:</p>
|
||||
@@ -2370,26 +2370,26 @@ course. We will also not be covering Linux internals. </p>
|
||||
<p>Most of us are familiar with the Windows operating system used in more than
|
||||
75% of the personal computers. The Windows operating systems
|
||||
are based on Windows NT kernel. </p>
|
||||
<p>A kernel is the most important part of
|
||||
an operating system - it performs important functions like process
|
||||
management, memory management, filesystem management etc.</p>
|
||||
<p>Linux operating systems are based on the Linux kernel. A Linux based
|
||||
<p>A <em>kernel</em> is the most important part of
|
||||
an operating system—it performs important functions like process
|
||||
management, memory management, filesystem management, etc.</p>
|
||||
<p>Linux operating systems are based on the Linux kernel. A Linux-based
|
||||
operating system will consist of Linux kernel, GUI/CLI, system libraries
|
||||
and system utilities. The Linux kernel was independently developed and
|
||||
released by Linus Torvalds. The Linux kernel is free and open-source -
|
||||
<a href="https://github.com/torvalds/linux">https://github.com/torvalds/linux</a></p>
|
||||
<p>Linux is a kernel and not a complete operating system. Linux kernel is combined with GNU system to make a complete operating system. Therefore, linux based operating systems are also called as GNU/Linux systems. GNU is an extensive collection of free softwares like compiler, debugger, C library etc.
|
||||
<a href="https://www.gnu.org/gnu/linux-and-gnu.en.html">Linux and the GNU System</a></p>
|
||||
released by Linus Torvalds. The Linux kernel is free and open-source (See
|
||||
<a href="https://github.com/torvalds/linux">https://github.com/torvalds/linux</a>).</p>
|
||||
<p>Linux is a kernel and not a complete operating system. Linux kernel is combined with GNU system to make a complete operating system. Therefore, Linux-based operating systems are also called as GNU/Linux systems. GNU is an extensive collection of free softwares like compiler, debugger, C library etc. (See
|
||||
<a href="https://www.gnu.org/gnu/linux-and-gnu.en.html">Linux and the GNU System</a>)</p>
|
||||
<p>History of Linux -
|
||||
<a href="https://en.wikipedia.org/wiki/History_of_Linux">https://en.wikipedia.org/wiki/History_of_Linux</a></p>
|
||||
<h2 id="what-are-popular-linux-distributions">What are popular Linux distributions</h2>
|
||||
<p>A Linux distribution(distro) is an operating system based on
|
||||
<p>A Linux distribution (<em>distro</em>) is an operating system based on
|
||||
the Linux kernel and a package management system. A package management
|
||||
system consists of tools that help in installing, upgrading,
|
||||
configuring and removing softwares on the operating system.</p>
|
||||
<p>Software are usually adopted to a distribution and are packaged in a
|
||||
distro specific format. These packages are available through a distro
|
||||
specific repository. Packages are installed and managed in the operating
|
||||
distro-specific format. These packages are available through a distro-specific
|
||||
repository. Packages are installed and managed in the operating
|
||||
system by a package manager.</p>
|
||||
<p><strong>List of popular Linux distributions:</strong></p>
|
||||
<ul>
|
||||
@@ -2425,12 +2425,12 @@ system by a package manager.</p>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Debian style (.deb)</td>
|
||||
<td>Debian style (<code>.deb</code>)</td>
|
||||
<td>Debian, Ubuntu</td>
|
||||
<td>APT</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Red Hat style (.rpm)</td>
|
||||
<td>Red Hat style (<code>.rpm</code>)</td>
|
||||
<td>Fedora, CentOS, Red Hat Enterprise Linux</td>
|
||||
<td>YUM</td>
|
||||
</tr>
|
||||
@@ -2465,13 +2465,13 @@ system by a package manager.</p>
|
||||
<p>Mobile phones - Android is based on Linux operating system</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Embedded devices - watches, televisions, traffic lights etc</p>
|
||||
<p>Embedded devices - watches, televisions, traffic lights, etc.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Satellites</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Network devices - routers, switches etc.</p>
|
||||
<p>Network devices - routers, switches, etc.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<h2 id="graphical-user-interface-gui-vs-command-line-interface-cli">Graphical user interface (GUI) vs Command line interface (CLI)</h2>
|
||||
@@ -2493,9 +2493,9 @@ example of a CLI (command line interface). Bash is one of the most popular shell
|
||||
programs available on Linux servers. Other popular shell programs are
|
||||
zsh, ksh and tcsh.</p>
|
||||
<p>Terminal is a program that opens a window and lets you interact with the
|
||||
shell. Some popular examples of terminals are gnome-terminal, xterm,
|
||||
konsole etc.</p>
|
||||
<p>Linux users do use the terms shell, terminal, prompt, console etc.
|
||||
shell. Some popular examples of terminals are GNOME-terminal, xterm,
|
||||
Konsole, etc.</p>
|
||||
<p>Linux users do use the terms shell, terminal, prompt, console, etc.
|
||||
interchangeably. In simple terms, these all refer to a way of taking
|
||||
commands from the user.</p>
|
||||
|
||||
|
||||
@@ -2709,7 +2709,7 @@
|
||||
|
||||
|
||||
<h1 id="linux-server-administration">Linux Server Administration</h1>
|
||||
<p>In this course will try to cover some of the common tasks that a linux
|
||||
<p>In this course, will try to cover some of the common tasks that a Linux
|
||||
server administrator performs. We will first try to understand what a
|
||||
particular command does and then try to understand the commands using
|
||||
examples. Do keep in mind that it's very important to practice the Linux
|
||||
@@ -2717,7 +2717,7 @@ commands on your own.</p>
|
||||
<h2 id="lab-environment-setup">Lab Environment Setup</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<p>Install docker on your system - <a href="https://docs.docker.com/engine/install/">https://docs.docker.com/engine/install/</a> OR you can used online <a href="https://labs.play-with-docker.com/">Docker playground</a></p>
|
||||
<p>Install docker on your system - <a href="https://docs.docker.com/engine/install/">https://docs.docker.com/engine/install/</a> OR you can use online <a href="https://labs.play-with-docker.com/">Docker playground</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p>We will be running all the commands on Red Hat Enterprise Linux (RHEL) 8 system.</p>
|
||||
@@ -2728,7 +2728,7 @@ commands on your own.</p>
|
||||
<li>We will run most of the commands used in this module in the above Docker container.</li>
|
||||
</ul>
|
||||
<h2 id="multi-user-operating-systems">Multi-User Operating Systems</h2>
|
||||
<p>An operating system is considered as multi-user if it allows multiple people/users to use a computer and not affect each other's files and preferences. Linux based operating systems are multi-user in nature as it allows multiple users to access the system at the same time. A typical computer will only have one keyboard and monitor but multiple users can log in via SSH if the computer is connected to the network. We will cover more about SSH later.</p>
|
||||
<p>An operating system is considered as multi-user if it allows multiple people/users to use a computer and not affect each other's files and preferences. Linux-based operating systems are multi-user in nature as it allows multiple users to access the system at the same time. A typical computer will only have one keyboard and monitor but multiple users can log in via SSH if the computer is connected to the network. We will cover more about SSH later.</p>
|
||||
<p>As a server administrator, we are mostly concerned with the Linux servers which are physically present at a very large distance from us. We can connect to these servers with the help of remote login methods like SSH.</p>
|
||||
<p>Since Linux supports multiple users, we need to have a method which can protect the users from each other. One user should not be able to access and modify files of other users</p>
|
||||
<h2 id="usergroup-management">User/Group Management</h2>
|
||||
@@ -2747,25 +2747,29 @@ commands on your own.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<h3 id="id-command">id command</h3>
|
||||
<p><code>id</code> command can be used to find the uid and gid associated with an user.
|
||||
<p><code>id</code> command can be used to find the <code>uid</code> and <code>gid</code> associated with an user.
|
||||
It also lists down the groups to which the user belongs to.</p>
|
||||
<p>The uid and gid associated with the root user is 0.
|
||||
<img alt="" src="../images/linux/admin/image30.png" /></p>
|
||||
<p>A good way to find out the current user in Linux is to use the whoami
|
||||
<p>The <code>uid</code> and <code>gid</code> associated with the root user is 0.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image30.png" /></p>
|
||||
<p>A good way to find out the current user in Linux is to use the <code>whoami</code>
|
||||
command.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image35.png" /></p>
|
||||
<p><strong>"root" user or superuser is the most privileged user with</strong>
|
||||
<p><strong><code>root</code> user or superuser is the most privileged user with</strong>
|
||||
<strong>unrestricted access to all the resources on the system. It has UID 0</strong></p>
|
||||
<h3 id="important-files-associated-with-usersgroups">Important files associated with users/groups</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>/etc/passwd</th>
|
||||
<th>Stores the user name, the uid, the gid, the home directory, the login shell etc</th>
|
||||
<th>Files</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>/etc/passwd</td>
|
||||
<td>Stores the user name, the <code>uid</code>, the <code>gid</code>, the home directory, the login shell etc</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/etc/shadow</td>
|
||||
<td>Stores the password associated with the users</td>
|
||||
</tr>
|
||||
@@ -2778,7 +2782,7 @@ command.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image23.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image21.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image9.png" /></p>
|
||||
<p>If you want to understand each filed discussed in the above outputs, you can go
|
||||
<p>If you want to understand each field discussed in the above outputs, you can go
|
||||
through below links:</p>
|
||||
<ul>
|
||||
<li>
|
||||
@@ -2792,25 +2796,17 @@ through below links:</p>
|
||||
<p>Some of the commands which are used frequently to manage users/groups
|
||||
on Linux are following:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>useradd</code> - Creates a new user</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>passwd</code> - Adds or modifies passwords for a user</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>usermod</code> - Modifies attributes of an user</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>userdel</code> - Deletes an user</p>
|
||||
</li>
|
||||
<li><code>useradd</code> - Creates a new user</li>
|
||||
<li><code>passwd</code> - Adds or modifies passwords for a user</li>
|
||||
<li><code>usermod</code> - Modifies attributes of an user</li>
|
||||
<li><code>userdel</code> - Deletes an user</li>
|
||||
</ul>
|
||||
<h3 id="useradd">useradd</h3>
|
||||
<p>The useradd command adds a new user in Linux.</p>
|
||||
<p>We will create a new user 'shivam'. We will also verify that the user
|
||||
has been created by tailing the /etc/passwd file. The uid and gid are
|
||||
<p>The <code>useradd</code> command adds a new user in Linux.</p>
|
||||
<p>We will create a new user <code>shivam</code>. We will also verify that the user
|
||||
has been created by tailing the <code>/etc/passwd</code> file. The <code>uid</code> and <code>gid</code> are
|
||||
1000 for the newly created user. The home directory assigned to the user
|
||||
is /home/shivam and the login shell assigned is /bin/bash. Do note that
|
||||
is <code>/home/shivam</code> and the login shell assigned is <code>/bin/bash</code>. Do note that
|
||||
the user home directory and login shell can be modified later on.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image41.png" /></p>
|
||||
<p>If we do not specify any value for attributes like home directory or
|
||||
@@ -2818,13 +2814,13 @@ login shell, default values will be assigned to the user. We can also
|
||||
override these default values when creating a new user.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image54.png" /></p>
|
||||
<h3 id="passwd">passwd</h3>
|
||||
<p>The passwd command is used to create or modify passwords for a user.</p>
|
||||
<p>The <code>passwd</code> command is used to create or modify passwords for a user.</p>
|
||||
<p>In the above examples, we have not assigned any password for users
|
||||
'shivam' or 'amit' while creating them.</p>
|
||||
<p>"!!" in an account entry in shadow means the account of an user has
|
||||
<code>shivam</code> or <code>amit</code> while creating them.</p>
|
||||
<p><code>!!</code> in an account entry in shadow means the account of an user has
|
||||
been created, but not yet given a password.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image13.png" /></p>
|
||||
<p>Let's now try to create a password for user "shivam".</p>
|
||||
<p>Let's now try to create a password for user <code>shivam</code>.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image55.png" /></p>
|
||||
<p>Do remember the password as we will be later using examples
|
||||
where it will be useful.</p>
|
||||
@@ -2833,112 +2829,116 @@ from a normal user to root user, it will request you for a password.
|
||||
Also, when you login using root user, the password will be asked.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image39.png" /></p>
|
||||
<h3 id="usermod">usermod</h3>
|
||||
<p>The usermod command is used to modify the attributes of an user like the
|
||||
<p>The <code>usermod</code> command is used to modify the attributes of an user like the
|
||||
home directory or the shell.</p>
|
||||
<p>Let's try to modify the login shell of user "amit" to "/bin/bash".</p>
|
||||
<p>Let's try to modify the login shell of user <code>amit</code> to <code>/bin/bash</code>.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image17.png" /></p>
|
||||
<p>In a similar way, you can also modify many other attributes for a user.
|
||||
Try 'usermod -h' for a list of attributes you can modify.</p>
|
||||
Try <code>usermod -h</code> for a list of attributes you can modify.</p>
|
||||
<h3 id="userdel">userdel</h3>
|
||||
<p>The userdel command is used to remove a user on Linux. Once we remove a
|
||||
<p>The <code>userdel</code> command is used to remove a user on Linux. Once we remove a
|
||||
user, all the information related to that user will be removed.</p>
|
||||
<p>Let's try to delete the user "amit". After deleting the user, you will
|
||||
not find the entry for that user in "/etc/passwd" or "/etc/shadow" file.</p>
|
||||
<p>Let's try to delete the user <code>amit</code>. After deleting the user, you will
|
||||
not find the entry for that user in <code>/etc/passwd</code> or <code>/etc/shadow</code> file.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image34.png" /></p>
|
||||
<h2 id="important-commands-for-managing-groups">Important commands for managing groups</h2>
|
||||
<p>Commands for managing groups are quite similar to the commands used for managing users. Each command is not explained in detail here as they are quite similar. You can try running these commands on your system.</p>
|
||||
<p>Commands for managing groups are quite similar to the commands used for managing users. Each command is not explained in detail here as they are quite similar. You can try running these commands on your system.</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>groupadd \<group_name></th>
|
||||
<th>Creates a new group</th>
|
||||
<th>Command</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>groupmod \<group_name></td>
|
||||
<td>groupadd <group_name></td>
|
||||
<td>Creates a new group</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>groupmod <group_name></td>
|
||||
<td>Modifies attributes of a group</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>groupdel \<group_name></td>
|
||||
<td>groupdel <group_name></td>
|
||||
<td>Deletes a group</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>gpasswd \<group_name></td>
|
||||
<td>gpasswd <group_name></td>
|
||||
<td>Modifies password for group</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><img alt="" src="../images/linux/admin/image52.png" /></p>
|
||||
<p>We will now try to add user "shivam" to the group we have created above.</p>
|
||||
<p>We will now try to add user <code>shivam</code> to the group we have created above.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image33.png" /></p>
|
||||
<h2 id="becoming-a-superuser">Becoming a Superuser</h2>
|
||||
<p><strong>Before running the below commands, do make sure that you have set up a
|
||||
password for user "shivam" and user "root" using the passwd command
|
||||
password for user <code>shivam</code> and user <code>root</code> using the <code>passwd</code> command
|
||||
described in the above section.</strong></p>
|
||||
<p>The su command can be used to switch users in Linux. Let's now try to
|
||||
switch to user "shivam".</p>
|
||||
<p>The <code>su</code> command can be used to switch users in Linux. Let's now try to
|
||||
switch to user <code>shivam</code>.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image37.png" /></p>
|
||||
<p>Let's now try to open the "/etc/shadow" file.</p>
|
||||
<p>Let's now try to open the <code>/etc/shadow</code> file.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image29.png" /></p>
|
||||
<p>The operating system didn't allow the user "shivam" to read the content
|
||||
of the "/etc/shadow" file. This is an important file in Linux which
|
||||
stores the passwords of users. This file can only be accessed by root or
|
||||
users who have the superuser privileges.</p>
|
||||
<p><strong>The sudo command allows a</strong> <strong>user to run commands with the security
|
||||
<p>The operating system didn't allow the user <code>shivam</code> to read the content
|
||||
of the <code>/etc/shadow</code> file. This is an important file in Linux which
|
||||
stores the passwords of users. This file can only be accessed by <code>root</code> or
|
||||
users who have the <code>superuser</code> privileges.</p>
|
||||
<p><strong>The <code>sudo</code> command allows a</strong> <strong>user to run commands with the security
|
||||
privileges of the root user.</strong> Do remember that the root user has all
|
||||
the privileges on a system. We can also use su command to switch to the
|
||||
the privileges on a system. We can also use <code>su</code> command to switch to the
|
||||
root user and open the above file but doing that will require the
|
||||
password of the root user. An alternative way which is preferred on most
|
||||
modern operating systems is to use sudo command for becoming a
|
||||
modern operating systems is to use <code>sudo</code> command for becoming a
|
||||
superuser. Using this way, a user has to enter his/her password and they
|
||||
need to be a part of the sudo group.</p>
|
||||
need to be a part of the <code>sudo</code> group.</p>
|
||||
<p><strong>How to provide superpriveleges to other users ?</strong></p>
|
||||
<p>Let's first switch to the root user using su command. Do note that using
|
||||
<p>Let's first switch to the root user using <code>su</code> command. Do note that using
|
||||
the below command will need you to enter the password for the root user.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image44.png" /></p>
|
||||
<p>In case, you forgot to set a password for the root user, type "exit" and
|
||||
<p>In case, you forgot to set a password for the root user, type <code>exit</code> and
|
||||
you will be back as the root user. Now, set up a password using the
|
||||
passwd command.</p>
|
||||
<p><strong>The file /etc/sudoers holds the names of users permitted to invoke
|
||||
sudo</strong>. In redhat operating systems, this file is not present by
|
||||
default. We will need to install sudo.</p>
|
||||
<code>passwd</code> command.</p>
|
||||
<p><strong>The file <code>/etc/sudoers</code> holds the names of users permitted to invoke
|
||||
<code>sudo</code></strong>. In Red Hat operating systems, this file is not present by
|
||||
default. We will need to install <code>sudo</code>.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image3.png" /></p>
|
||||
<p>We will discuss the yum command in detail in later sections.</p>
|
||||
<p>Try to open the "/etc/sudoers" file on the system. The file has a lot of
|
||||
<p>We will discuss the <code>yum</code> command in detail in later sections.</p>
|
||||
<p>Try to open the <code>/etc/sudoers</code> file on the system. The file has a lot of
|
||||
information. This file stores the rules that users must follow when
|
||||
running the sudo command. For example, root is allowed to run any
|
||||
running the <code>sudo</code> command. For example, <code>root</code> is allowed to run any
|
||||
commands from anywhere.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image8.png" /></p>
|
||||
<p>One easy way of providing root access to users is to add them to a group
|
||||
which has permissions to run all the commands. "wheel" is a group in
|
||||
redhat Linux with such privileges.</p>
|
||||
which has permissions to run all the commands. <code>wheel</code> is a group in
|
||||
Red Hat Linux with such privileges.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image25.png" /></p>
|
||||
<p>Let's add the user "shivam" to this group so that it also has sudo
|
||||
<p>Let's add the user <code>shivam</code> to this group so that it also has <code>sudo</code>
|
||||
privileges.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image48.png" /></p>
|
||||
<p>Let's now switch back to user "shivam" and try to access the
|
||||
"/etc/shadow" file.</p>
|
||||
<p>Let's now switch back to user <code>shivam</code> and try to access the
|
||||
<code>/etc/shadow</code> file.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image56.png" /></p>
|
||||
<p>We need to use sudo before running the command since it can only be
|
||||
accessed with the sudo privileges. We have already given sudo privileges
|
||||
to user “shivam” by adding him to the group “wheel”.</p>
|
||||
<p>We need to use <code>sudo</code> before running the command since it can only be
|
||||
accessed with the <code>sudo</code> privileges. We have already given <code>sudo</code> privileges
|
||||
to user <code>shivam</code> by adding him to the group <code>wheel</code>.</p>
|
||||
<h2 id="file-permissions">File Permissions</h2>
|
||||
<p>On a Linux operating system, each file and directory is assigned access
|
||||
permissions for the owner of the file, the members of a group of related
|
||||
users and everybody else. This is to make sure that one user is not
|
||||
allowed to access the files and resources of another user.</p>
|
||||
<p>To see the permissions of a file, we can use the ls command. Let's look
|
||||
at the permissions of /etc/passwd file.</p>
|
||||
<p>To see the permissions of a file, we can use the <code>ls</code> command. Let's look
|
||||
at the permissions of <code>/etc/passwd</code> file.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image40.png" /></p>
|
||||
<p>Let's go over some of the important fields in the output that are
|
||||
related to file permissions.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image31.jpg" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image57.png" /></p>
|
||||
<h3 id="chmod-command">Chmod command</h3>
|
||||
<p>The chmod command is used to modify files and directories permissions in
|
||||
<p>The <code>chmod</code> command is used to modify files and directories permissions in
|
||||
Linux.</p>
|
||||
<p>The chmod command accepts permissions in as a numerical argument. We can
|
||||
<p>The <code>chmod</code> command accepts permissions in as a numerical argument. We can
|
||||
think of permission as a series of bits with 1 representing True or
|
||||
allowed and 0 representing False or not allowed.</p>
|
||||
<table>
|
||||
@@ -3004,56 +3004,56 @@ allowed and 0 representing False or not allowed.</p>
|
||||
<p>We will now create a new file and check the permission of the file.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image15.png" /></p>
|
||||
<p>The group owner doesn't have the permission to write to this file. Let's
|
||||
give the group owner or root the permission to write to it using chmod
|
||||
give the group owner or root the permission to write to it using <code>chmod</code>
|
||||
command.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image26.png" /></p>
|
||||
<p>Chmod command can be also used to change the permissions of a directory
|
||||
<p><code>chmod</code> command can be also used to change the permissions of a directory
|
||||
in the similar way.</p>
|
||||
<h3 id="chown-command">Chown command</h3>
|
||||
<p>The chown command is used to change the owner of files or
|
||||
<p>The <code>chown</code> command is used to change the owner of files or
|
||||
directories in Linux.</p>
|
||||
<p>Command syntax: chown \<new_owner> \<file_name></p>
|
||||
<p>Command syntax: <code>chown \<new_owner\> \<file_name\></code></p>
|
||||
<p><img alt="" src="../images/linux/admin/image6.png" /></p>
|
||||
<p><strong>In case, we do not have sudo privileges, we need to use sudo
|
||||
command</strong>. Let's switch to user 'shivam' and try changing the owner. We
|
||||
have also changed the owner of the file to root before running the below
|
||||
<p><strong>In case, we do not have <code>sudo</code> privileges, we need to use <code>sudo</code>
|
||||
command</strong>. Let's switch to user <code>shivam</code> and try changing the owner. We
|
||||
have also changed the owner of the file to <code>root</code> before running the below
|
||||
command.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image12.png" /></p>
|
||||
<p>Chown command can also be used to change the owner of a directory in the
|
||||
similar way.</p>
|
||||
<h3 id="chgrp-command">Chgrp command</h3>
|
||||
<p>The chgrp command can be used to change the group ownership of files or
|
||||
directories in Linux. The syntax is very similar to that of chown
|
||||
<p>The <code>chgrp</code> command can be used to change the group ownership of files or
|
||||
directories in Linux. The syntax is very similar to that of <code>chown</code>
|
||||
command.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image27.png" /></p>
|
||||
<p>Chgrp command can also be used to change the owner of a directory in the
|
||||
<p><code>chgrp</code> command can also be used to change the owner of a directory in the
|
||||
similar way.</p>
|
||||
<h2 id="ssh-command">SSH Command</h2>
|
||||
<p>The ssh command is used for logging into the remote systems, transfer files between systems and for executing commands on a remote machine. SSH stands for secure shell and is used to provide an encrypted secured connection between two hosts over an insecure network like the internet.</p>
|
||||
<p>The <code>ssh</code> command is used for logging into the remote systems, transfer files between systems and for executing commands on a remote machine. <code>SSH</code> stands for secure shell and is used to provide an encrypted secured connection between two hosts over an insecure network like the internet.</p>
|
||||
<p>Reference:
|
||||
<a href="https://www.ssh.com/ssh/command/">https://www.ssh.com/ssh/command/</a></p>
|
||||
<p>We will now discuss passwordless authentication which is secure and most
|
||||
commonly used for ssh authentication.</p>
|
||||
commonly used for <code>ssh</code> authentication.</p>
|
||||
<h3 id="passwordless-authentication-using-ssh">Passwordless Authentication Using SSH</h3>
|
||||
<p>Using this method, we can ssh into hosts without entering the password.
|
||||
<p>Using this method, we can <code>ssh</code> into hosts without entering the password.
|
||||
This method is also useful when we want some scripts to perform
|
||||
ssh-related tasks.</p>
|
||||
<p>Passwordless authentication requires the use of a public and private key pair. As the name implies, the public key can be shared with anyone but the private key should be kept private.
|
||||
Lets not get into the details of how this authentication works. You can read more about it
|
||||
Let's not get into the details of how this authentication works. You can read more about it
|
||||
<a href="https://www.digitalocean.com/community/tutorials/understanding-the-ssh-encryption-and-connection-process">here</a></p>
|
||||
<p>Steps for setting up a passwordless authentication with a remote host:</p>
|
||||
<ol>
|
||||
<li>
|
||||
<p>Generating public-private key pair </p>
|
||||
<p><strong>If we already have a key pair stored in \~/.ssh directory, we will not need to generate keys again.</strong></p>
|
||||
<p>Install openssh package which contains all the commands related to ssh.</p>
|
||||
<p><strong>If we already have a key pair stored in <code>~/.ssh</code> directory, we will not need to generate keys again.</strong></p>
|
||||
<p>Install <code>openssh</code> package which contains all the commands related to <code>ssh</code>.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image49.png" /></p>
|
||||
<p>Generate a key pair using the ssh-keygen command. One can choose the
|
||||
<p>Generate a key pair using the <code>ssh-keygen</code> command. One can choose the
|
||||
default values for all prompts.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image47.png" /></p>
|
||||
<p>After running the ssh-keygen command successfully, we should see two
|
||||
keys present in the \~/.ssh directory. Id_rsa is the private key and
|
||||
id_rsa.pub is the public key. Do note that the private key can only be
|
||||
<p>After running the <code>ssh-keygen</code> command successfully, we should see two
|
||||
keys present in the <code>~/.ssh</code> directory. <code>id_rsa</code> is the private key and
|
||||
<code>id_rsa.pub</code> is the public key. Do note that the private key can only be
|
||||
read and modified by you.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image7.png" /></p>
|
||||
</li>
|
||||
@@ -3061,26 +3061,30 @@ read and modified by you.</p>
|
||||
<p>Transferring the public key to the remote host</p>
|
||||
<p>There are multiple ways to transfer the public key to the remote server.
|
||||
We will look at one of the most common ways of doing it using the
|
||||
ssh-copy-id command.</p>
|
||||
<code>ssh-copy-id</code> command.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image11.png" /></p>
|
||||
<p>Install the openssh-clients package to use ssh-copy-id command.</p>
|
||||
<p>Install the <code>openssh-clients</code> package to use <code>ssh-copy-id</code> command.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image46.png" /></p>
|
||||
<p>Use the ssh-copy-id command to copy your public key to the remote host.</p>
|
||||
<p>Use the <code>ssh-copy-id</code> command to copy your public key to the remote host.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image50.png" /></p>
|
||||
<p>Now, ssh into the remote host using the password authentication.</p>
|
||||
<p>Now, <code>ssh</code> into the remote host using the password authentication.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image51.png" /></p>
|
||||
<p>Our public key should be there in \~/.ssh/authorized_keys now.</p>
|
||||
<p>Our public key should be there in <code>~/.ssh/authorized_keys</code> now.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image4.png" /></p>
|
||||
<p>\~/.ssh/authorized_key contains a list of public keys. The users
|
||||
associated with these public keys have the ssh access into the remote
|
||||
<p><code>~/.ssh/authorized_key</code> contains a list of public keys. The users
|
||||
associated with these public keys have the <code>ssh</code> access into the remote
|
||||
host.</p>
|
||||
</li>
|
||||
</ol>
|
||||
<h3 id="how-to-run-commands-on-a-remote-host">How to run commands on a remote host ?</h3>
|
||||
<p>General syntax: ssh \<user>@\<hostname/hostip> \<command></p>
|
||||
<p>General syntax: </p>
|
||||
<pre><code class="language-shell">ssh \<user\>@\<hostname/hostip\> \<command\>
|
||||
</code></pre>
|
||||
<p><img alt="" src="../images/linux/admin/image14.png" /></p>
|
||||
<h3 id="how-to-transfer-files-from-one-host-to-another-host">How to transfer files from one host to another host ?</h3>
|
||||
<p>General syntax: scp \<source> \<destination></p>
|
||||
<p>General syntax:</p>
|
||||
<pre><code class="language-shell">scp \<source\> \<destination\>
|
||||
</code></pre>
|
||||
<p><img alt="" src="../images/linux/admin/image32.png" /></p>
|
||||
<h2 id="package-management">Package Management</h2>
|
||||
<p>Package management is the process of installing and managing software on
|
||||
@@ -3096,11 +3100,11 @@ systems.</p>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Debian style (.deb)</td>
|
||||
<td>Debian style (<code>.deb</code>)</td>
|
||||
<td>Debian, Ubuntu</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Red Hat style (.rpm)</td>
|
||||
<td>Red Hat style (<code>.rpm</code>)</td>
|
||||
<td>Fedora, CentOS, Red Hat Enterprise Linux</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -3115,110 +3119,110 @@ systems.</p>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>yum install \<package_name></td>
|
||||
<td>yum install <package_name></td>
|
||||
<td>Installs a package on your system</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>yum update \<package_name></td>
|
||||
<td>Updates a package to it's latest available version</td>
|
||||
<td>yum update <package_name></td>
|
||||
<td>Updates a package to its latest available version</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>yum remove \<package_name></td>
|
||||
<td>yum remove <package_name></td>
|
||||
<td>Removes a package from your system</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>yum search \<keyword></td>
|
||||
<td>yum search <keyword></td>
|
||||
<td>Searches for a particular keyword</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><a href="https://docs.fedoraproject.org/en-US/quick-docs/dnf/">DNF</a> is
|
||||
the successor to YUM which is now used in Fedora for installing and
|
||||
managing packages. DNF may replace YUM in the future on all RPM based
|
||||
managing packages. DNF may replace YUM in the future on all RPM-based
|
||||
Linux distributions.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image20.png" /></p>
|
||||
<p>We did find an exact match for the keyword httpd when we searched using
|
||||
yum search command. Let's now install the httpd package.</p>
|
||||
<p>We did find an exact match for the keyword <code>httpd</code> when we searched using
|
||||
<code>yum search</code> command. Let's now install the <code>httpd</code> package.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image28.png" /></p>
|
||||
<p>After httpd is installed, we will use the yum remove command to remove
|
||||
httpd package.</p>
|
||||
<p>After <code>httpd</code> is installed, we will use the <code>yum remove</code> command to remove
|
||||
<code>httpd</code> package.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image43.png" /></p>
|
||||
<h2 id="process-management">Process Management</h2>
|
||||
<p>In this section, we will study about some useful commands that can be
|
||||
used to monitor the processes on Linux systems.</p>
|
||||
<h3 id="ps-process-status">ps (process status)</h3>
|
||||
<p>The ps command is used to know the information of a process or list of
|
||||
<p>The <code>ps</code> command is used to know the information of a process or list of
|
||||
processes.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image24.png" /></p>
|
||||
<p>If you get an error "ps command not found" while running ps command, do
|
||||
install <strong>procps</strong> package.</p>
|
||||
<p>ps without any arguments is not very useful. Let's try to list all the
|
||||
<p>If you get an error "ps command not found" while running <code>ps</code> command, do
|
||||
install <code>procps</code> package.</p>
|
||||
<p><code>ps</code> without any arguments is not very useful. Let's try to list all the
|
||||
processes on the system by using the below command.</p>
|
||||
<p>Reference:
|
||||
<a href="https://unix.stackexchange.com/questions/106847/what-does-aux-mean-in-ps-aux">https://unix.stackexchange.com/questions/106847/what-does-aux-mean-in-ps-aux</a></p>
|
||||
<p><img alt="" src="../images/linux/admin/image42.png" /></p>
|
||||
<p>We can use an additional argument with ps command to list the
|
||||
information about the process with a specific process ID.</p>
|
||||
<p>We can use an additional argument with <code>ps</code> command to list the
|
||||
information about the process with a specific process ID (PID).</p>
|
||||
<p><img alt="" src="../images/linux/admin/image2.png" /></p>
|
||||
<p>We can use grep in combination with ps command to list only specific
|
||||
<p>We can use <code>grep</code> in combination with <code>ps</code> command to list only specific
|
||||
processes.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image1.png" /></p>
|
||||
<h3 id="top">top</h3>
|
||||
<p>The top command is used to show information about Linux processes
|
||||
<p>The <code>top</code> command is used to show information about Linux processes
|
||||
running on the system in real time. It also shows a summary of the
|
||||
system information.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image53.png" /></p>
|
||||
<p>For each process, top lists down the process ID, owner, priority, state,
|
||||
cpu utilization, memory utilization and much more information. It also
|
||||
lists down the memory utilization and cpu utilization of the system as a
|
||||
whole along with system uptime and cpu load average.</p>
|
||||
<p>For each process, <code>top</code> lists down the process ID, owner, priority, state,
|
||||
CPU utilization, memory utilization and much more information. It also
|
||||
lists down the memory utilization and CPU utilization of the system as a
|
||||
whole along with system uptime and CPU load average.</p>
|
||||
<h2 id="memory-management">Memory Management</h2>
|
||||
<p>In this section, we will study about some useful commands that can be
|
||||
used to view information about the system memory.</p>
|
||||
<h3 id="free">free</h3>
|
||||
<p>The free command is used to display the memory usage of the system. The
|
||||
<p>The <code>free</code> command is used to display the memory usage of the system. The
|
||||
command displays the total free and used space available in the RAM
|
||||
along with space occupied by the caches/buffers.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image22.png" /></p>
|
||||
<p>free command by default shows the memory usage in kilobytes. We can use
|
||||
<p><code>free</code> command by default shows the memory usage in kilobytes. We can use
|
||||
an additional argument to get the data in human-readable format.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image5.png" /></p>
|
||||
<h3 id="vmstat">vmstat</h3>
|
||||
<p>The vmstat command can be used to display the memory usage along with
|
||||
additional information about io and cpu usage.</p>
|
||||
<p>The <code>vmstat</code> command can be used to display the memory usage along with
|
||||
additional information about IO and CPU usage.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image38.png" /></p>
|
||||
<h2 id="checking-disk-space">Checking Disk Space</h2>
|
||||
<p>In this section, we will study about some useful commands that can be
|
||||
used to view disk space on Linux.</p>
|
||||
<h3 id="df-disk-free">df (disk free)</h3>
|
||||
<p>The df command is used to display the free and available space for each
|
||||
<p>The <code>df</code> command is used to display the free and available space for each
|
||||
mounted file system.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image36.png" /></p>
|
||||
<h3 id="du-disk-usage">du (disk usage)</h3>
|
||||
<p>The du command is used to display disk usage of files and directories on
|
||||
<p>The <code>du</code> command is used to display disk usage of files and directories on
|
||||
the system.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image10.png" /></p>
|
||||
<p>The below command can be used to display the top 5 largest directories
|
||||
in the root directory.</p>
|
||||
in the <code>root</code> directory.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image18.png" /></p>
|
||||
<h2 id="daemons">Daemons</h2>
|
||||
<p>A computer program that runs as a background process is called a daemon.
|
||||
Traditionally, the name of daemon processes ended with d - sshd, httpd
|
||||
<p>A computer program that runs as a background process is called a <em>daemon</em>.
|
||||
Traditionally, the name of daemon processes ends with <code>d</code> - <code>sshd</code>, <code>httpd</code>,
|
||||
etc. We cannot interact with a daemon process as they run in the
|
||||
background.</p>
|
||||
<p>Services and daemons are used interchangeably most of the time.</p>
|
||||
<h2 id="systemd">Systemd</h2>
|
||||
<p>Systemd is a system and service manager for Linux operating systems.
|
||||
Systemd units are the building blocks of systemd. These units are
|
||||
<p><code>systemd</code> is a system and service manager for Linux operating systems.
|
||||
<code>systemd</code> units are the building blocks of <code>systemd</code>. These units are
|
||||
represented by unit configuration files.</p>
|
||||
<p>The below examples shows the unit configuration files available at
|
||||
/usr/lib/systemd/system which are distributed by installed RPM packages.
|
||||
<code>/usr/lib/systemd/system</code> which are distributed by installed RPM packages.
|
||||
We are more interested in the configuration file that ends with service
|
||||
as these are service units.</p>
|
||||
<p><img alt="" src="../images/linux/admin/image16.png" /></p>
|
||||
<h3 id="managing-system-services">Managing System Services</h3>
|
||||
<p>Service units end with .service file extension. Systemctl command can be
|
||||
used to start/stop/restart the services managed by systemd.</p>
|
||||
<p>Service units end with <code>.service</code> file extension. <code>systemctl</code> command can be
|
||||
used to start/stop/restart the services managed by <code>systemd</code>.</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
Reference in New Issue
Block a user