Knowee
Questions
Features
Study Tools

You want to create a Bash script that will automatically delete log files older than 7 days in a specific directory. Which command sequence correctly accomplishes this task while considering best practices for error handling and efficiency?1.0 Marksfind /path/to/logs -type f -name "*.log" -mtime +7 -exec rm {} \;for file in $(find /path/to/logs -type f -name "*.log" -mtime +7); dorm "$file" || echo "Error deleting $file"donefor file in /path/to/logs/*.log; do[ -f "$file" ] && find "$file" -mtime +7 -exec rm {} \;donefind /path/to/logs -type f -name "*.log" -mtime +7 | xargs rmrm $(find /path/to/logs -type f -name "*.log" -mtime +7)Clear Answer

Question

You want to create a Bash script that will automatically delete log files older than 7 days in a specific directory. Which command sequence correctly accomplishes this task while considering best practices for error handling and efficiency?1.0 Marksfind /path/to/logs -type f -name ".log" -mtime +7 -exec rm {} ;for file in (find/path/to/logstypefname".log"mtime+7);dorm"(find /path/to/logs -type f -name "*.log" -mtime +7); dorm "file" || echo "Error deleting file"doneforfilein/path/to/logs/.log;do[f"file"donefor file in /path/to/logs/*.log; do[ -f "file" ] && find "file"mtime+7execrm  donefind/path/to/logstypefname".log"mtime+7xargsrmrmfile" -mtime +7 -exec rm {} \;donefind /path/to/logs -type f -name "*.log" -mtime +7 | xargs rmrm (find /path/to/logs -type f -name ".log" -mtime +7)Clear Answer

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct command sequence to accomplish this task is:

find /path/to/logs -type f -name "*.log" -mtime +7 -exec rm {} \;

Here's a step-by-step explanation:

  1. find /path/to/logs -type f -name "*.log": This command finds all files (-type f) with the extension .log in the directory /path/to/logs.

  2. -mtime +7: This option is used with the find command to search for files that are older than 7 days.

  3. -exec rm {} \;: This option is used with the find command to execute the rm command on each file that the find command finds. The {} is a placeholder for the current file, and the \; indicates the end of the -exec command.

This command sequence is efficient because it only invokes the rm command once for each file, and it handles errors well because the -exec option ensures that the rm command is only run if the find command successfully finds a file.

This problem has been solved

Similar Questions

Choose the command which will print all the directories within the current directory, whose names starts with the letter 'K' and are accessed in last two days.find /home -type d -mtime +2 -printfind . -type l -mtime +2 -printfind /home -type d -atime +2 -name 'K*' -printfind . -type d -atime -2 -name 'K*' -print

You're creating a Bash script to automate backups of important configuration files. The script should store backups in a folder named with the current date (e.g., "2023-07-06"). Which command correctly generates such a folder name in Bash?1.0 Marksfolder_name=$(date +%Y-%m-%d)folder_name=date +%Y-%m-%dfolder_name=date +%Ffolder_name=date -Ifolder_name="date +%Y-%m-%d"

Scenario: You are a cybersecurity expert who has been hired by a company to perform a security assessment of their network. During the assessment, you discover that one of the company's servers has been compromised by an attacker. The attacker has left behind several files and directories on the server, including local log files. Your goal is to clean the server and restore it to its normal state. What is the most effective way to clean the local log files after the host has been compromised?Select one:a.By overwriting the log files with random datab.By leaving the log files as is and only deleting the other files and directories left behind by the attackerc.By restoring the log files from a backupd.By deleting the log files manually

Which of the following commands can be used to delete a file on a Linux system?Question 17Answera.rm file.txtb.delete file.txtc.del file.txtd.erase file.txt

Which of the following is NOT true about medication logs?A new log is required each day.They are required to be maintained for a minimum of 12 months after the last day the child received the medicine.They must include the date and time the medication was administered.They must record the dosage administered.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.