Bookmark this page

Guided Exercise: Locate Files on the System

In this exercise, you search for specific files on mounted file systems by using the find and locate commands.

Outcomes

  • Search for files with the find and locate commands.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command prepares your environment and ensures that all required resources are available.

[student@workstation ~]$ lab start fs-locate

Instructions

  1. On the workstation machine, use the ssh command to log in to the servera machine as the student user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$
  2. Use the locate command to search for files on the servera machine.

    1. Update the locatedb database manually on the server machine. Use the sudo updatedb command to update the database.

      [student@servera ~]$ sudo updatedb
      [sudo] password for student: student
      [student@servera ~]$
    2. Locate the logrotate.conf configuration file.

      [student@servera ~]$ locate logrotate.conf
      /etc/logrotate.conf
      /usr/share/man/man5/logrotate.conf.5.gz
    3. Locate the networkmanager.conf configuration file, ignoring case sensitivity.

      [student@servera ~]$ locate -i networkmanager.conf
      /etc/NetworkManager/NetworkManager.conf
      /etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf
      /usr/share/man/man5/NetworkManager.conf.5.gz
  3. Use the find command to search in real time on the servera machine according to the following requirements:

    • List all files in the /var/lib directory that the chrony user owns.

    • List all files in the /var directory that the root user and the mail group own.

    • List all files in the /usr/bin directory with a file size that is greater than 50 KB.

    • List all files in the /home/student directory that changed in the last 120 minutes.

    • List all the block device files in the /dev directory.

    1. Search for all files in the /var/lib directory that the chrony user owns, with root privilege.

      [student@servera ~]$ sudo find /var/lib -user chrony
      [sudo] password for student: student
      /var/lib/chrony
      /var/lib/chrony/drift
    2. List all files in the /var directory that the root user owns and that belong to the mail group.

      [student@servera ~]$ sudo find /var -user root -group mail
      /var/spool/mail
    3. List all files in the /usr/bin directory with a greater file size than 50 KB.

      [student@servera ~]$ find /usr/bin -size +50k
      /usr/bin/iconv
      /usr/bin/locale
      /usr/bin/localedef
      /usr/bin/cmp
      ...output omitted...
    4. List all files in the /home/student directory that changed in the last 120 minutes.

      [student@servera ~]$ find /home/student -mmin -120
      /home/student/.bash_logout
      /home/student/.bash_profile
      /home/student/.bashrc
      ...output omitted...
    5. List all block device files in the /dev directory.

      [student@servera ~]$ find /dev -type b
      /dev/vdd
      /dev/vdc
      /dev/vdb
      /dev/vda3
      /dev/vda2
      /dev/vda1
      /dev/vda
  4. Return to the workstation machine as the student user.

    [student@servera ~]$ exit
    logout
    Connection to servera closed.
    [student@workstation]$

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish fs-locate

This concludes the section.

Revision: rh124-9.0-398f302