A system administrator needs to perform a cleanup operation within the /var/log/app_temp directory. The task is to find and remove all regular files with a .tmp extension that are larger than 1MB. Which of the following commands will accomplish this task most effectively?
grep -r "*.tmp" /var/log/app_temp | xargs rm
find /var/log/app_temp -type f -name "*.tmp" -size +1M
find /var/log/app_temp -type f -name "*.tmp" -size +1M -delete
find /var/log/app_temp -type d -name "*.tmp" -size +1M -delete
The correct command is find /var/log/app_temp -type f -name "*.tmp" -size +1M -delete. Here is a breakdown of the command:
find /var/log/app_temp: This specifies the starting directory for the search.
-type f: This tells find to look only for regular files, not directories or other file types.
-name "*.tmp": This is the pattern for the filename. The wildcard * matches any sequence of characters, so this finds all files ending in .tmp.
-size +1M: This filters for files that are larger than 1 Mebibyte.
-delete: This is an action that tells find to delete the files it has found that match all the preceding criteria. It is generally safer and more efficient than using -exec rm {} \;.
The other options are incorrect. One option omits the -delete action, so it only finds the files but does not remove them. Another option incorrectly uses -type d, which would search for directories instead of files. The grep command is unsuitable for this task as it is designed to search for text within files, not to find files by their attributes like size and name, and the piping to rm is syntactically incorrect for file deletion.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the `-type f` option in the `find` command do?
Open an interactive chat with Bash
Why is `-delete` considered safer than using `-exec rm {} \;`?
Open an interactive chat with Bash
What does the `-size +1M` option do in the `find` command?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Services and User Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access