Professional Documents
Culture Documents
Exercise - Search Text Files Using Regular Expressions (Using Grep, Egrep, Fgrep and Regular Expressions)
Exercise - Search Text Files Using Regular Expressions (Using Grep, Egrep, Fgrep and Regular Expressions)
(/cp) & 12 % Latest Updates (https://linuxacademy.com/blog)$ Refer A Friend (/cp/referFriend) # Support " ! summit "
' ( ) * +
Home (/cp) Courses Cloud Servers Quick Training (/cp/library/catalog/view/QuickTraining) Hands-on Labs (/cp/library/catalog/view/LiveLabs)
, - .
Learning Paths (/cp/learningpaths) Community
/
Return to Syllabus
(/cp/modules/view/id/125)
Exercise: Search Text Files Using Regular Expressions (Using grep, egrep, fgrep
and Regular Expressions)
1. Logged in as user, obtain a full listing of all processes running on the system and filter the results so that only processes that contain the keyword 'ssh' are included in the output
results.
user 2452 0.0 0.0 52836 576 ? Ss 09:56 0:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash
-c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
user 3190 0.0 0.0 112640 960 pts/0 R+ 10:08 0:00 grep --color=auto ssh
2. Noticing that the actual command run to display those processes is one of the results, rerun the command from Step #1, but pipe it to another command to filter out the grep
command itself.
user 2452 0.0 0.0 52836 576 ? Ss 09:56 0:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash
-c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
3. Run a command to list all processes, piping the results in order to display only processes that have a '[' (open square bracket character). You want to save cpu cycles so make sure
you are not using a regular expression.
kthreadd]
https://linuxacademy.com/cp/exercises/view/id/450/module/125 Page 1 of 4
Linux Academy 7/22/17, 2'15 PM
ksoftirqd/0]
kworker/0:0H]
kworker/u30:0]
migration/0]
rcu_bh]
rcuob/0]
rcuob/1]
rcuob/2]
https://linuxacademy.com/cp/exercises/view/id/450/module/125 Page 2 of 4
Linux Academy 7/22/17, 2'15 PM
rcuob/3]
...
4. Once again, run a command listing all processes, but use a command that allows extended regular expressions to display all processes running that contain two consecutive 's'
characters in them.
dbus 492 0.0 0.0 29764 2840 ? Ss 09:56 0:00 /bin/dbus-daemon --system --address=systemd: --
nofork --nopidfile --systemd-activation
root 2259 0.0 0.1 373980 5468 ? Sl 09:56 0:00 gdm-session-worker [pam/gdm-password]
user 2267 0.0 0.3 860364 13240 ? Ssl 09:56 0:00 gnome-session --session gnome-classic
user 2275 0.0 0.0 13944 608 ? S 09:56 0:00 dbus-launch --sh-syntax --exit-with-session
user 2276 0.0 0.0 29732 1788 ? Ss 09:56 0:00 /bin/dbus-daemon --fork --print-pid 4 --print-
address 6 --session
user 2436 0.0 0.0 143760 284 ? S 09:56 0:00 /usr/bin/VBoxClient --seamless
user 2437 0.0 0.0 209960 1036 ? Sl 09:56 0:00 /usr/bin/VBoxClient --seamless
user 2452 0.0 0.0 52836 576 ? Ss 09:56 0:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash
-c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
user 2471 0.0 0.0 28644 1568 ? S 09:56 0:00 /bin/dbus-daemon --config-file=/etc/at-
spi2/accessibility.conf --nofork --print-address 3
user 2475 0.0 0.0 129656 3340 ? Sl 09:56 0:00 /usr/libexec/at-spi2-registryd --use-gnome-
session
user 3248 0.0 0.0 112640 960 pts/0 R+ 10:11 0:00 grep -E --color=auto ss
5. Try the other two methods of obtaining the same results in Step #3.
https://linuxacademy.com/cp/exercises/view/id/450/module/125 Page 3 of 4
Linux Academy 7/22/17, 2'15 PM
dbus 492 0.0 0.0 29764 2840 ? Ss 09:56 0:00 /bin/dbus-daemon --system --address=systemd: --
nofork --nopidfile --systemd-activation
root 2259 0.0 0.1 373980 5468 ? Sl 09:56 0:00 gdm-session-worker [pam/gdm-password]
user 2267 0.0 0.3 860364 13240 ? Ssl 09:56 0:00 gnome-session --session gnome-classic
user 2275 0.0 0.0 13944 608 ? S 09:56 0:00 dbus-launch --sh-syntax --exit-with-session
user 2276 0.0 0.0 29732 1788 ? Ss 09:56 0:00 /bin/dbus-daemon --fork --print-pid 4 --print-
address 6 --session
user 2436 0.0 0.0 143760 284 ? S 09:56 0:00 /usr/bin/VBoxClient --seamless
user 2437 0.0 0.0 209960 1036 ? Sl 09:56 0:00 /usr/bin/VBoxClient --seamless
user 2452 0.0 0.0 52836 576 ? Ss 09:56 0:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash
-c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
user 2471 0.0 0.0 28644 1568 ? S 09:56 0:00 /bin/dbus-daemon --config-file=/etc/at-
spi2/accessibility.conf --nofork --print-address 3
user 2475 0.0 0.0 129656 3340 ? Sl 09:56 0:00 /usr/libexec/at-spi2-registryd --use-gnome-
session
user 3248 0.0 0.0 112640 960 pts/0 R+ 10:11 0:00 grep -E --color=auto ss
dbus 492 0.0 0.0 29764 2840 ? Ss 09:56 0:00 /bin/dbus-daemon --system --address=systemd: --
nofork --nopidfile --systemd-activation
root 2259 0.0 0.1 373980 5468 ? Sl 09:56 0:00 gdm-session-worker [pam/gdm-password]
user 2267 0.0 0.3 860364 13240 ? Ssl 09:56 0:00 gnome-session --session gnome-classic
user 2275 0.0 0.0 13944 608 ? S 09:56 0:00 dbus-launch --sh-syntax --exit-with-session
user 2276 0.0 0.0 29732 1788 ? Ss 09:56 0:00 /bin/dbus-daemon --fork --print-pid 4 --print-
address 6 --session
user 2436 0.0 0.0 143760 284 ? S 09:56 0:00 /usr/bin/VBoxClient --seamless
user 2437 0.0 0.0 209960 1036 ? Sl 09:56 0:00 /usr/bin/VBoxClient --seamless
user 2452 0.0 0.0 52836 576 ? Ss 09:56 0:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash
-c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
user 2471 0.0 0.0 28644 1568 ? S 09:56 0:00 /bin/dbus-daemon --config-file=/etc/at-
spi2/accessibility.conf --nofork --print-address 3
user 2475 0.0 0.0 129656 3340 ? Sl 09:56 0:00 /usr/libexec/at-spi2-registryd --use-gnome-
session
user 3248 0.0 0.0 112640 960 pts/0 R+ 10:11 0:00 grep -E --color=auto ss
https://linuxacademy.com/cp/exercises/view/id/450/module/125 Page 4 of 4