Deployed f05a42c
with MkDocs version: 1.1.2
|
@ -1223,14 +1223,14 @@ documentation, most commands will have a command-line argument -h or
|
|||
most popular documentation system in Linux is called man pages - short
|
||||
for manual pages.</p>
|
||||
<p>Using --help to show the documentation for ls command.</p>
|
||||
<p><img alt="" src="images/linux/commands/image19.png" /></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.
|
||||
These directories in turn can either store system files or application
|
||||
files or user related files.</p>
|
||||
<p><img alt="" src="images/linux/commands/image17.png" /></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<br />
|
||||
sbin | This directory contains programs used for system administration.
|
||||
home | This directory contains user related files and directories.
|
||||
|
@ -1262,25 +1262,25 @@ online bash shell.</p>
|
|||
<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>
|
||||
<p><img alt="" src="images/linux/commands/image2.png" /></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
|
||||
print the working directory.</p>
|
||||
<p><img alt="" src="images/linux/commands/image20.png" /></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
|
||||
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><img alt="" src="images/linux/commands/image3.png" /></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
|
||||
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
|
||||
directories present in the current directory.</p>
|
||||
<p><img alt="" src="images/linux/commands/image7.png" /></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
|
||||
will then list all the files and directories inside the given directory.</p>
|
||||
<p><img alt="" src="images/linux/commands/image4.png" /></p>
|
||||
<p><img alt="" src="../images/linux/commands/image4.png" /></p>
|
||||
<h2 id="commands-for-manipulating-files">Commands for Manipulating Files</h2>
|
||||
<p>There are four basic commands which are used frequently to manipulate
|
||||
files:</p>
|
||||
|
@ -1311,14 +1311,14 @@ the simplest use case of creating a new file.</p>
|
|||
<p>General syntax of using touch command</p>
|
||||
<pre><code>touch <file_name>
|
||||
</code></pre>
|
||||
<p><img alt="" src="images/linux/commands/image9.png" /></p>
|
||||
<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
|
||||
to verify that the new directory is created.</p>
|
||||
<p>General syntax of using mkdir command</p>
|
||||
<pre><code>mkdir <directory_name>
|
||||
</code></pre>
|
||||
<p><img alt="" src="images/linux/commands/image11.png" /></p>
|
||||
<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
|
||||
important to note that this command permanently deletes the files and
|
||||
|
@ -1331,7 +1331,7 @@ run this command with care.</p>
|
|||
<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
|
||||
respectively.</p>
|
||||
<p><img alt="" src="images/linux/commands/image18.png" /></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
|
||||
|
@ -1344,14 +1344,14 @@ their copy both co-exist after running cp command successfully.</p>
|
|||
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
|
||||
now.</p>
|
||||
<p><img alt="" src="images/linux/commands/image23.png" /></p>
|
||||
<p><img alt="" src="../images/linux/commands/image23.png" /></p>
|
||||
<p>Do note that nothing happened to the original "_test_runner.py" file.
|
||||
It's still there in the current directory. A new copy of it got created
|
||||
inside the "test_directory".</p>
|
||||
<p><img alt="" src="images/linux/commands/image14.png" /></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
|
||||
location to another. Let's try to understand this with an example.</p>
|
||||
<p><img alt="" src="images/linux/commands/image12.png" /></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>
|
||||
|
@ -1368,7 +1368,7 @@ move the files or directories, the original copy is lost.</p>
|
|||
already exists in "test_directory". The mv 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>
|
||||
<p><img alt="" src="images/linux/commands/image26.png" /></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
|
||||
|
@ -1377,7 +1377,7 @@ exist if we use mv command.</p>
|
|||
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><img alt="" src="images/linux/commands/image29.png" /></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 three basic commands which are used frequently to view the
|
||||
files:</p>
|
||||
|
@ -1397,7 +1397,7 @@ 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
|
||||
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><img alt="" src="../images/linux/commands/image21.png" /></p>
|
||||
<p>Do not worry about the above command now. It's an advanced command which
|
||||
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
|
||||
|
@ -1406,7 +1406,7 @@ later sections.</p>
|
|||
<p>The most simplest use of cat 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>
|
||||
<p><img alt="" src="../images/linux/commands/image1.png" /></p>
|
||||
<p>You can try to run the above command and you will see numbers being
|
||||
printed from 1 to 100 on your screen. You will need to scroll up to view
|
||||
all the numbers.</p>
|
||||
|
@ -1416,20 +1416,20 @@ 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>
|
||||
<p><img alt="" src="images/linux/commands/image15.png" /></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
|
||||
want to specify the number of lines we want to see from start, use the
|
||||
'-n' argument to provide the input.</p>
|
||||
<p><img alt="" src="images/linux/commands/image16.png" /></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
|
||||
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><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'
|
||||
argument to provide the input.</p>
|
||||
<p><img alt="" src="images/linux/commands/image10.png" /></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>
|
||||
<h2 id="echo-command-in-linux">Echo Command in Linux</h2>
|
||||
|
@ -1437,7 +1437,7 @@ when we use the tail command with explicit -n option.</p>
|
|||
shell. This command is equivalent to what we have <print> in other
|
||||
programming languages.</p>
|
||||
<p>The echo command prints the given input string on the screen.</p>
|
||||
<p><img alt="" src="images/linux/commands/image24.png" /></p>
|
||||
<p><img alt="" src="../images/linux/commands/image24.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.
|
||||
In many cases, we will be interested in performing the below operations:</p>
|
||||
|
@ -1470,7 +1470,7 @@ 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
|
||||
to 10 in this file. Each number will be in a separate line.</p>
|
||||
<p><img alt="" src="images/linux/commands/image8.png" /></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
|
||||
words in a text file. It will display all the lines in a file that
|
||||
|
@ -1481,7 +1481,7 @@ an input to the grep command.</p>
|
|||
</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>
|
||||
<p><img alt="" src="images/linux/commands/image5.png" /></p>
|
||||
<p><img alt="" src="../images/linux/commands/image5.png" /></p>
|
||||
<h3 id="sed">sed</h3>
|
||||
<p>The sed command in its simplest form can be used to replace a text in a
|
||||
file.</p>
|
||||
|
@ -1490,7 +1490,7 @@ file.</p>
|
|||
</code></pre>
|
||||
<p>Let's try to replace each occurrence of "1" in the file with "3" using
|
||||
sed command.</p>
|
||||
<p><img alt="" src="images/linux/commands/image31.png" /></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
|
||||
changes are reflected back in the file.</p>
|
||||
|
@ -1498,10 +1498,10 @@ changes are reflected back in the file.</p>
|
|||
<p>The sort 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><img alt="" src="../images/linux/commands/image27.png" /></p>
|
||||
<p>Now, we will try to sort the file using the sort command. The sort
|
||||
command sorts the content in lexicographical order.</p>
|
||||
<p><img alt="" src="images/linux/commands/image32.png" /></p>
|
||||
<p><img alt="" src="../images/linux/commands/image32.png" /></p>
|
||||
<p>The content of the file will not change in the above
|
||||
example.</p>
|
||||
<h2 id="io-redirection">I/O Redirection</h2>
|
||||
|
@ -1518,19 +1518,19 @@ 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><img alt="" src="images/linux/commands/image30.png" /></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
|
||||
a file.</p>
|
||||
<p><img alt="" src="images/linux/commands/image13.png" /></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><img alt="" src="images/linux/commands/image6.png" /></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
|
||||
prints the unique numbers from the input.</p>
|
||||
<p><img alt="" src="images/linux/commands/image28.png" /></p>
|
||||
<p><img alt="" src="../images/linux/commands/image28.png" /></p>
|
||||
<p>I/O redirection -
|
||||
<a href="https://tldp.org/LDP/abs/html/io-redirection.html">https://tldp.org/LDP/abs/html/io-redirection.html</a></p>
|
||||
<h2 id="applications-in-sre-role">Applications in SRE Role</h2>
|
||||
|
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 134 KiB After Width: | Height: | Size: 134 KiB |
Before Width: | Height: | Size: 251 KiB After Width: | Height: | Size: 251 KiB |
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 192 KiB |
Before Width: | Height: | Size: 161 KiB After Width: | Height: | Size: 161 KiB |
Before Width: | Height: | Size: 301 KiB After Width: | Height: | Size: 301 KiB |
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 178 KiB After Width: | Height: | Size: 178 KiB |
Before Width: | Height: | Size: 306 KiB After Width: | Height: | Size: 306 KiB |
Before Width: | Height: | Size: 375 KiB After Width: | Height: | Size: 375 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 332 KiB After Width: | Height: | Size: 332 KiB |
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 119 KiB |
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 88 KiB |
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 373 KiB After Width: | Height: | Size: 373 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 178 KiB After Width: | Height: | Size: 178 KiB |
Before Width: | Height: | Size: 295 KiB After Width: | Height: | Size: 295 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 192 KiB |
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 89 KiB |
Before Width: | Height: | Size: 242 KiB After Width: | Height: | Size: 242 KiB |
Before Width: | Height: | Size: 245 KiB After Width: | Height: | Size: 245 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 295 KiB After Width: | Height: | Size: 295 KiB |
Before Width: | Height: | Size: 171 KiB After Width: | Height: | Size: 171 KiB |
Before Width: | Height: | Size: 168 KiB After Width: | Height: | Size: 168 KiB |
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 243 KiB After Width: | Height: | Size: 243 KiB |
Before Width: | Height: | Size: 186 KiB After Width: | Height: | Size: 186 KiB |
Before Width: | Height: | Size: 217 KiB After Width: | Height: | Size: 217 KiB |
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 79 KiB |
Before Width: | Height: | Size: 179 KiB After Width: | Height: | Size: 179 KiB |
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 71 KiB |
Before Width: | Height: | Size: 268 KiB After Width: | Height: | Size: 268 KiB |
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |
Before Width: | Height: | Size: 141 KiB After Width: | Height: | Size: 141 KiB |
Before Width: | Height: | Size: 288 KiB After Width: | Height: | Size: 288 KiB |
Before Width: | Height: | Size: 302 KiB After Width: | Height: | Size: 302 KiB |
Before Width: | Height: | Size: 628 KiB After Width: | Height: | Size: 628 KiB |
Before Width: | Height: | Size: 233 KiB After Width: | Height: | Size: 233 KiB |
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 160 KiB |
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 164 KiB |
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 99 KiB |
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 131 KiB After Width: | Height: | Size: 131 KiB |
Before Width: | Height: | Size: 189 KiB After Width: | Height: | Size: 189 KiB |
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 189 KiB After Width: | Height: | Size: 189 KiB |
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 187 KiB After Width: | Height: | Size: 187 KiB |
Before Width: | Height: | Size: 246 KiB After Width: | Height: | Size: 246 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
Before Width: | Height: | Size: 148 KiB After Width: | Height: | Size: 148 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 353 KiB After Width: | Height: | Size: 353 KiB |
Before Width: | Height: | Size: 216 KiB After Width: | Height: | Size: 216 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 147 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 200 KiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 124 KiB |
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
Before Width: | Height: | Size: 141 KiB After Width: | Height: | Size: 141 KiB |
|
@ -1127,7 +1127,7 @@ system by a package manager.</p>
|
|||
</tbody>
|
||||
</table>
|
||||
<h2 id="linux-architecture">Linux Architecture</h2>
|
||||
<p><img alt="" src="images/linux/commands/image25.png" /></p>
|
||||
<p><img alt="" src="../images/linux/commands/image25.png" /></p>
|
||||
<ul>
|
||||
<li>
|
||||
<p>The Linux kernel is monolithic in nature.</p>
|
||||
|
|
|
@ -1454,7 +1454,7 @@ commands on your own.</p>
|
|||
<p>We will be running all the commands on Red Hat Enterprise Linux (RHEL) 8 system.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<p><img alt="" src="images/linux/admin/image19.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image19.png" /></p>
|
||||
<ul>
|
||||
<li>We will run most of the commands used in this module in the above docker container.</li>
|
||||
</ul>
|
||||
|
@ -1481,10 +1481,10 @@ commands on your own.</p>
|
|||
<p>id command can be used to find the uid and gid 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>
|
||||
<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
|
||||
command.</p>
|
||||
<p><img alt="" src="images/linux/admin/image35.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image35.png" /></p>
|
||||
<p><strong>"root" 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>
|
||||
|
@ -1506,9 +1506,9 @@ command.</p>
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<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><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
|
||||
through below links:</p>
|
||||
<ul>
|
||||
|
@ -1543,31 +1543,31 @@ has been created by tailing the /etc/passwd file. The uid and gid 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
|
||||
the user home directory and login shell can be modified later on.</p>
|
||||
<p><img alt="" src="images/linux/admin/image41.png" /></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
|
||||
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>
|
||||
<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>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
|
||||
been created, but not yet given a password.</p>
|
||||
<p><img alt="" src="images/linux/admin/image13.png" /></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><img alt="" src="images/linux/admin/image55.png" /></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>
|
||||
<p>Also, let's change the password for the root user now. When we switch
|
||||
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>
|
||||
<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
|
||||
home directory or the shell.</p>
|
||||
<p>Let's try to modify the login shell of user "amit" to "/bin/bash".</p>
|
||||
<p><img alt="" src="images/linux/admin/image17.png" /></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>
|
||||
<h3 id="userdel">userdel</h3>
|
||||
|
@ -1575,7 +1575,7 @@ Try 'usermod -h' for a list of attributes you can modify.</p>
|
|||
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><img alt="" src="images/linux/admin/image34.png" /></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>
|
||||
<table>
|
||||
|
@ -1600,18 +1600,18 @@ not find the entry for that user in "/etc/passwd" or "/etc/shadow" file.</p>
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><img alt="" src="images/linux/admin/image52.png" /></p>
|
||||
<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><img alt="" src="images/linux/admin/image33.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image33.png" /></p>
|
||||
<h2 id="becoming-a-superuser-in-linux">Becoming a Superuser in Linux</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
|
||||
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><img alt="" src="images/linux/admin/image37.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image37.png" /></p>
|
||||
<p>Let's now try to open the "/etc/shadow" file.</p>
|
||||
<p><img alt="" src="images/linux/admin/image29.png" /></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
|
||||
|
@ -1627,30 +1627,30 @@ need to be a part of the sudo 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
|
||||
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><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
|
||||
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>
|
||||
<p><img alt="" src="images/linux/admin/image3.png" /></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
|
||||
information. This file stores the rules that users must follow when
|
||||
running the sudo command. For example, root is allowed to run any
|
||||
commands from anywhere.</p>
|
||||
<p><img alt="" src="images/linux/admin/image8.png" /></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>
|
||||
<p><img alt="" src="images/linux/admin/image25.png" /></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
|
||||
privileges.</p>
|
||||
<p><img alt="" src="images/linux/admin/image48.png" /></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><img alt="" src="images/linux/admin/image56.png" /></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>
|
||||
|
@ -1661,11 +1661,11 @@ 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><img alt="" src="images/linux/admin/image40.png" /></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>
|
||||
<p><img alt="" src="../images/linux/admin/image31.jpg" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image57.png" /></p>
|
||||
<h3 id="chmod-command-in-linux">Chmod command in linux</h3>
|
||||
<p>The chmod command is used to modify files and directories permissions in
|
||||
linux.</p>
|
||||
|
@ -1733,30 +1733,30 @@ allowed and 0 representing False or not allowed.</p>
|
|||
</tbody>
|
||||
</table>
|
||||
<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><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
|
||||
command.</p>
|
||||
<p><img alt="" src="images/linux/admin/image26.png" /></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
|
||||
in the similar way.</p>
|
||||
<h3 id="chown-command-in-linux">Chown command in linux</h3>
|
||||
<p>The chown command is used to change the owner of files or
|
||||
directories in linux.</p>
|
||||
<p>Command syntax: chown \<new_owner> \<file_name></p>
|
||||
<p><img alt="" src="images/linux/admin/image6.png" /></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
|
||||
command.</p>
|
||||
<p><img alt="" src="images/linux/admin/image12.png" /></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-in-linux">Chgrp command in linux</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
|
||||
command.</p>
|
||||
<p><img alt="" src="images/linux/admin/image27.png" /></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
|
||||
similar way.</p>
|
||||
<h2 id="ssh-command">SSH Command</h2>
|
||||
|
@ -1778,30 +1778,30 @@ Lets not get into the details of how this authentication works. You can read mo
|
|||
<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><img alt="" src="images/linux/admin/image49.png" /></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
|
||||
default values for all prompts.</p>
|
||||
<p><img alt="" src="images/linux/admin/image47.png" /></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
|
||||
read and modified by you.</p>
|
||||
<p><img alt="" src="images/linux/admin/image7.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image7.png" /></p>
|
||||
</li>
|
||||
<li>
|
||||
<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-id-copy command.</p>
|
||||
<p><img alt="" src="images/linux/admin/image11.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image11.png" /></p>
|
||||
<p>Install the openssh-clients package to use ssh-id-copy command.</p>
|
||||
<p><img alt="" src="images/linux/admin/image46.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image46.png" /></p>
|
||||
<p>Use the ssh-id-copy command to copy your public key to the remote host.</p>
|
||||
<p><img alt="" src="images/linux/admin/image50.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image50.png" /></p>
|
||||
<p>Now, ssh into the remote host using the password authentication.</p>
|
||||
<p><img alt="" src="images/linux/admin/image51.png" /></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><img alt="" src="images/linux/admin/image4.png" /></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
|
||||
host.</p>
|
||||
|
@ -1809,10 +1809,10 @@ host.</p>
|
|||
</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><img alt="" src="images/linux/admin/image14.png" /></p>
|
||||
<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><img alt="" src="images/linux/admin/image32.png" /></p>
|
||||
<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
|
||||
the system. We can install the packages which we require from the linux
|
||||
|
@ -1867,38 +1867,38 @@ systems.</p>
|
|||
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
|
||||
linux distributions.</p>
|
||||
<p><img alt="" src="images/linux/admin/image20.png" /></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><img alt="" src="images/linux/admin/image28.png" /></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><img alt="" src="images/linux/admin/image43.png" /></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
|
||||
processes.</p>
|
||||
<p><img alt="" src="images/linux/admin/image24.png" /></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
|
||||
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><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><img alt="" src="images/linux/admin/image2.png" /></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
|
||||
processes.</p>
|
||||
<p><img alt="" src="images/linux/admin/image1.png" /></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
|
||||
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><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
|
||||
|
@ -1910,28 +1910,28 @@ used to view information about the system memory.</p>
|
|||
<p>The free 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><img alt="" src="../images/linux/admin/image22.png" /></p>
|
||||
<p>free 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>
|
||||
<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><img alt="" src="images/linux/admin/image38.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image38.png" /></p>
|
||||
<h2 id="checking-disk-space-in-linux">Checking Disk Space in Linux</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
|
||||
mounted file system.</p>
|
||||
<p><img alt="" src="images/linux/admin/image36.png" /></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
|
||||
the system.</p>
|
||||
<p><img alt="" src="images/linux/admin/image10.png" /></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>
|
||||
<p><img alt="" src="images/linux/admin/image18.png" /></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
|
||||
|
@ -1946,7 +1946,7 @@ represented by unit configuration files.</p>
|
|||
/usr/lib/systemd/system 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>
|
||||
<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>
|
||||
|
@ -1985,7 +1985,7 @@ used to start/stop/restart the services managed by systemd.</p>
|
|||
which can be very useful for viewing system logs and applications logs
|
||||
in linux. These logs can be very useful when you are troubleshooting on
|
||||
the system.</p>
|
||||
<p><img alt="" src="images/linux/admin/image58.png" /></p>
|
||||
<p><img alt="" src="../images/linux/admin/image58.png" /></p>
|
||||
<h2 id="applications-in-sre-role">Applications in SRE Role</h2>
|
||||
<ul>
|
||||
<li>
|
||||
|
|