Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented content revisions, installed locate package #211

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions helpful-commands/background.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@

echo "Just thinking about everything I have been through, and how huge it all feels." >> quote.txt
echo "The fact that it is just a small part of something larger" >> quote.txt

# install locate
yum install -y mlocate

# update locate db
updatedb
7 changes: 2 additions & 5 deletions helpful-commands/step2.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,5 @@ The message you just sent with `logger` is present in _messages_.
>_NOTE:_ If it took you a bit to switch back to Terminal 2, there may be additional
entries in the _messages_ log below your "Hello World".

Hit `ctrl+C` in Terminal 2 to close out of `tail -f`:

`^C`{{execute T2}}

The next step will walk you through locating files.
Leave this `tail -f` process running in Terminal 2, you will use it again in
an upcoming step. The next step will walk you through locating files.
69 changes: 54 additions & 15 deletions helpful-commands/step3.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,74 @@
# Locating files

Manipulating files is only useful if you can locate the file you need.
Manipulating files is only useful if you can locate the file you need. This step
will walk you through two commands that are useful for this, `locate` and `find`.

The `find` command is great for searching for files which
satisfy some specified criteria. This step will show an example using filename,
but you can also use it to look for files with ceratin permissions, empty files,
or much more.

`find / -name sudo.conf`{{execute T1}}
`find / -name messages`{{execute T1}}

<pre class=file>
/etc/dnf/protected.d/sudo.conf
/etc/sudo.conf
/usr/lib/tmpfiles.d/sudo.conf
/usr/share/doc/sudo/examples/sudo.conf
/var/log/messages
</pre>

Instead of having to search through countless directories, you can quickly
decide which of these _sudo.conf_
The output is the full path to the file. If there are multiple matches, then
this output would have multiple lines and it would be up to the user
to decide which is the appropriate file. Instead of having to search through
countless directories, you can quickly locate the file. However, `find` can be
input/output intensive, especially when running a search that will scan a
large amount of candidate files. This can sap system resources. In fact,
the search above is exactly that kind of search, since it is looking for
filenames recursively starting from the root directory. It will check every
single file on the entire system to see if it is a match.

>_Note:_ An in-depth explanation of using `find` to sort by file permissions
is included in the [File Permissions Basics lab](https://lab.redhat.com/file-permissions).

`find` is great if you are looking for criteria about a file, but if you instead
want to locate specific file contents, the `grep` command is what you need.
`find` can be input/output intensive, which can sap system resources, especially
if you run a search that will scan a large amount of candidate files. In fact,
the search above is exactly that kind of search, since it is looking for filenames
starting from the root directory. The `locate` command instead queries a
database to avoid being too I/O intensive.

`locate messages`{{exeute T1}}

// find can be i/o intensive, which can sap system resources and have unintended
effects
<pre class=file>
<< OUTPUT ABRIDGED >>
/usr/share/vim/vim80/syntax/messages.vim
/usr/share/vim/vim80/syntax/msmessages.vim
/var/log/messages
</pre>

This command finds a variety of files containing _messages_ in their name,
including the log file that you are looking for, `/var/log/messages`.
The database that `locate` uses to optimize the search process
is updated once per day by default, so that means if you are trying to
locate a newly created file it will not be present in the database.

Create a new file with `touch`:

`touch newFile`{{execute T1}}

Try to find this newly created file using `locate`:

`locate newFile`{{execute T1}}

// take a look at locate, run updatedb command in background
There will be no output, as _newFile_ is not in the `locate` database.
Update the `locate` database using the `updatedb` command:

`updatedb`{{execute T1}}

Re-run the `locate` command to look through the newly updated database:

`locate newFile`{{execute T1}}

<pre class=file>
/root/newFile
</pre>

// queries database, comes back super fast and is not I/O instensive
// if you dl'd file you will not locate
Now the file is present. This is important to keep in mind so that you do not
run into the frustrating situation where `locate` failed to find a file that
existed all along.
13 changes: 11 additions & 2 deletions helpful-commands/step4.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Searching for text within files and outputs

`grep`{{execute T1}}
`find` is great if you are looking for criteria about a file, but if you instead
want to locate specific file contents, the `grep` command is what you need.
To illustrate this, search for the words you added to the _messages_ log file:

// grep for logger entry that we made in previous step
`grep -r "Hello World" /var/log`{{execute T1}}

<pre class=file>
/var/log/messages:Jul 16 21:38:22 be3f7e9f7264 root[24468]: Hello World
</pre>

Later on in this lab you will see another example of how to combine `grep` with the
pipe operator (`|`) to search within the output of another command.
27 changes: 20 additions & 7 deletions helpful-commands/step5.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Using `df` to check disk usage

// box is having problems? we know that full filesystems cause problems
// quick health checking
A large part of a system administrator's job is to be able to diagnose what
is causing a system to misbehave. Disk space being full can lead to unexpected
behavior, so the `df` command is great to include in any troubleshooting session.

The `df` command, short for "disk free", shows a breakdown of disk usage.
The `-h` option will present the sizes in a human readable format:
Expand All @@ -19,10 +20,22 @@ tmpfs 909M 0 909M 0% /sys/fs/cgroup
tmpfs 182M 0 182M 0% /run/user/0
</pre>

// larger filesystems can be closer to full and still be okay
The usage percentage (_Use%_) column is a great place to start. If any filesystem
is close to capacity, then it may be unable to perform installations or other
operations that require data to be written. However, the absolute size of
the partition will determine what "close to capacity" means. In the case of this
system, the root partition is 35 GiB. Therefore, even if it is at 80% usage,
the filesystem will still have 7 GiB to work with. Probably something you
need to address eventually, but unless you are doing some storage-intensive
operation that is failing, likely not the cause of immediate issues.

// tmpfs is filesystems accessible by the machine that are stored in RAM and
ephemoral - don't have to care as much because they are in RAM. A reboot will
give you a fresh copy
The _boot_ partition is on the other end of the spectrum, with a size of
only 1014 MiB. Therefore, if this filesystem is at 80% usage, there will only
be 200 MiB available. That may not be enough for basic operations such as installing
system updates. Therefore, it is very concerning if you run `df` and discover
one of the smaller filesystems is at 80% usage.

// want to worry about logical partition for root the most
>_NOTE:_ The _tmpfs_ entries are filesystems accessible by the machine that are stored
in RAM. This means that you don't have to care as much about these filesystems
when troubleshooting using `df`. A reboot will give you a fresh copy of these
filesystems.
48 changes: 43 additions & 5 deletions helpful-commands/step6.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,44 @@
# Viewing processes

`ps`{{execute}}
Just as files organize how data is stored on Linux, processes organize all of the
programs that are running on the system. The `ps` command (short for Process
Status) will display information about the processes running in the current shell.
To see all of the processes running on the system and present them in a
user-readable format, it is common to add the `aux` options to `ps`.

>_NOTE:_ For more info on using `ps` (including how to end processes), check
`ps aux`{{execute}}

<pre class=file>
root 1 0.0 0.7 186400 14448 ? Ss 15:38 0:11 /usr/lib/systemd/systemd --switched-root --system --deserialize 17
root 2 0.0 0.0 0 0 ? S 15:38 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< 15:38 0:00 [rcu_gp]
root 4 0.0 0.0 0 0 ? I< 15:38 0:00 [rcu_par_gp]
root 6 0.0 0.0 0 0 ? I< 15:38 0:00 [kworker/0:0H-events_highpri]
root 9 0.0 0.0 0 0 ? I< 15:38 0:00 [mm_percpu_wq]
root 10 0.0 0.0 0 0 ? S 15:38 0:00 [ksoftirqd/0]
root 11 0.0 0.0 0 0 ? I 15:38 0:00 [rcu_sched]

<< OUTPUT ABRIDGED >>
</pre>

>_NOTE:_ There is another lab which goes into depth about `ps` and process
management. For more info on using `ps` (including how to end processes), check
out the [Service Administration Basics lab](https://lab.redhat.com/service-admin)

The output of this command is often very lengthy, so this is a great chance
to apply what you just learned a few steps ago. Using the pipe operator (`|`),
pipe the output of `ps aux` into the `grep` command to search for a specific
process:
process. Search for the `tail -f` process that you started in step 2:

`ps aux | grep `{{execute T1}}
`ps aux | grep tail`{{execute T1}}

<pre class=file>
root 10046 0.0 0.0 7344 928 pts/1 S+ 19:26 0:00 tail -f /var/log/messages
root 10051 0.0 0.0 12136 1136 pts/0 S+ 19:26 0:00 grep --color=auto tail
</pre>

Here the search finds the `tail -f` process, but the second line of this output
shows that the search also finds itself.

`ps` is great for showing a snapshot of the active processes and their
resource usage, but sometimes it is more useful to have a utility that keeps
Expand All @@ -19,7 +47,7 @@ updating this information in real time. `top` does just that.
// provide detail on the top preamble
// brief summary of each, combine similar entries (i.e. memory, etc)

`top`{{execute T2}}
`top`{{execute T3}}

<pre class=file>
top - 21:11:07 up 4:10, 2 users, load average: 0.45, 0.16, 0.06
Expand All @@ -36,6 +64,16 @@ MiB Swap: 4000.0 total, 4000.0 free, 0.0 used. 1482.2 avail Mem
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
</pre>

In addition to the process info, `top` includes some status information:
* The system uptime,
* Total number of user accounts
* 1 minute, 5 minute, and 15 minute load averages
* The total number of tasks and a breakdown of their status counts
* The kinds of tasks using the CPU
* A breakdown of memory and swap usage

>_NOTE:_ For more information on the `top` preamble, visit section 2 of the [top man page](https://man7.org/linux/man-pages/man1/top.1.html).

This output will continue updating until you quit `top`, making it particularly
useful for diagnosing issues that change over time. Leave `top` running in this
terminal for now, you will return to it later.