find

Alicia is a RHEL Sysadmin at Red Hat. Red Hat is purging any files that are in a proprietary file format from RHEL_Server_01. What find command will Alicia run to find and delete all files in / that have a .doc or .docx extension?

Alicia can use the following find command to locate and delete all files in the root directory ("/") that have a ".doc" or ".docx" extension:

find / -type f \( -name "*.doc" -o -name "*.docx" \) -exec rm {} +

Explanation of the command:

  • find /: Specifies the starting directory as the root directory ("/").
  • -type f: Searches for regular files.
  • \( -name "*.doc" -o -name "*.docx" \): Specifies the filename patterns to search for. The -name option is used to match the file extensions ".doc" and ".docx". The -o operator is used for logical OR between the two patterns.
  • -exec rm {} +: Executes the rm command to delete the found files. The {} is a placeholder that represents the found files, and + ensures that rm is called with as many files as possible to optimize performance.

Please note that this command will delete the files permanently, so it's crucial to exercise caution and double-check the command before executing it. Additionally, running commands with root privileges requires appropriate permissions and should be handled carefully.

You should also read:

find

Raysa is a RHEL Sysadmin studying for her LFCS exam. Please give her detailed command examples of the find command in 3 categories:…

find

Rihanna is a great singer by night, and a RHEL Sysadmin at Google by day. She is teaching a group of new hires…

find

Hector is a RHEL Sysadmin at IBM. He wants to find and delete all images with a .jpg extension in /home/hectorz/images/. What command…