Cybersecurity Ops with bash - Chapter 5 Solutions

Updated: Mar 25, 2019

Below are selected solutions for the Chapter 5 workshop questions from Cybersecurity Ops with bash.

Question 1

Write the command to search the filesystem for any file named dog.png.


You can use the find command to search the file system:

Question 3

Write the command to search the file system for any file containing the text secret or confidential and copy the file to your current working directory.


You can combine the find command with the exec option to invoke the egrep command to search the content of each file, and then the cp command to copy any matching files to the current working directory:

Question 8

Modify to indicate its progress by printing the logfile name over the top of the previous logfile name. (Hint: Use a return character rather than a newline.)


The script contains the line below that prints the name of each log file to the screen.

The echo command automatically prints a newline after each iteration. To print everything on the same line you can replace echo with the printf command and the carriage return (\r) character.

Note that the carriage return only moves the cursor to the beginning of the line, it does not clear the line. If the next item to print is shorter than the previous item some of the previous item's text will remain on the line. We will discuss how to solve this in Chapter 12 with the tput command.


© 2019 by Paul Troncone and Carl Albing