Computer Science 491
Senior Seminar

Dickinson College
Fall Semester 2018
Grant Braught

Unix Tools Challenges
Introduction

In the tutorials below you will learn/review many of the basics of the unix command line, file paths and some basic unix utilities. This activity then poses some challenges for you to try to solve using the unix command line and utilities.

Prerequisites

Before starting the challenges complete Tutorial Sections 1-12 on the site below.

Challenges

Complete each of the following challenges and append the commands that you use to the Live-log used for the Linux Tutorials homework. These are best completed using your Ubuntu install in VirtualBox. You can click the "Solution" button below each question to check your solution. Note that there are multiple possible ways to accomplish each of these challenges. If yours is different, try running mine and see if it gives the same results as yours.

  1. Give a command line using the ps command that display all processes that are running on the system (should be more than a hundred).
      ps -aux
  2. Give a command line using the ps, tail and wc commands, with pipes to display just the number of processes that are running in the current terminal session (use ps alone to check your results).
      ps | tail -n +2 | wc -l
  3. Give a command line using grep with your solution to the previous challenges to display the number of processes that are running whose programs live in the /usr/bin directory.
      ps -aux | tail -n +2 | grep "/usr/bin" | wc -l
  4. Open a new terminal window and run the xeyes command. Give a command line that will terminate (i.e. kill) the xeyes process when executed in a separate terminal window.
      ps -aux | grep "xeyes" (to find the process id (PID) for xeyes)
      kill -KILL <PID>
  5. Learn about the find command using its man page.
  6. Give a command line using find that displays the location of all files named passwd that reside within a depth of 5 sub-directories of the machine's root directory.
      find . -maxdepth 5 -name "passwd" -print
  7. In the last challenge, there are many permission denied error messages written to standard error (similar to standard output and appears on the console). Give a command line that redirects standard error to the file '/dev/null' so that these error messages are discarded and the results can be seen more easily. Note: /dev/null is a pseudo file on unix systems that simply discards all data written into it.
      find . -maxdepth 5 -name "passwd" -print 2> /dev/null
  8. Consider the passwd file in the /etc directory from the previous exercise. This file contains one line for each valid user in the system (use cat to look at it). Each line has a number of fields delimited by ':' characters. The next to the last field gives the path to the user's home directory (e.g. /home/braught). Give a command line that will write the path to the home directory for the "root" user into a file named "userhome.txt" in the /var/tmp directory. Hint: man cut. Note: /var/tmp is a directory on unix machines that all users can write to and is usually used for temporary files.
      grep -a "root" /etc/passwd | cut -f6 -d':' > /var/tmp/userhome.txt
  9. Give a command line that will append the home directory of your user to the "userhome.txt" file.
      grep -a "myuser" /etc/passwd | cut -f6 -d':' >> /var/tmp/userhome.txt
  10. If there is more time remaining, try some of the following Hacker Rank challenges (you may need to learn about some additional unix commands as you go):
    1. The Middle of a Text File
    2. tr Command #1
    3. sort Command #7
    4. uniq Command #3
    5. paste Command #2
    6. grep Command #5
    7. sed Command #3
    8. awk Command #1
    9. awk Command #2