Due to low disk space, a Linux administrator finding and removing all log files that were modified more than 180 days ago. Which of the following commands will accomplish this task?
A.
find /var/log -type d -mtime +180 -print -exec rm {} \;
B.
find /var/log -type f -modified +180 -rm
C.
find /var/log -type f -mtime +180 -exec rm {} \
The correct answer is C, "find /var/log -type f -mtime +180 -exec rm {} ;". This command will accomplish the task of finding and removing all log files that were modified more than 180 days ago.
Here's a breakdown of the command:
The find command is used to search for files and directories in a specific location, in this case, "/var/log".
The -type f option is used to search only for regular files, excluding directories and other file types.
The -mtime +180 option is used to select only files that have a modification time more than 180 days ago.
The -exec rm {} \; option is used to execute the rm command on each file that matches the criteria specified in the previous options. The curly braces {} are replaced with the name of each file found and the backslash \; is used to end the command.
The other options, A and D, contain incorrect syntax or incorrect commands. Option B only has the "find" and "rm" commands and is missing the options to specify the type of files to search for and the time frame for modification. Option D uses the incorrect option "-remove" instead of "-exec rm {} ;".
A. The 'find' command with its '-exec' option requires an escaped semi-colon, '\;' (B) There is no predicate, modified. (C) This would work just as well as answer, A, if the command ended with a semi-colon. (D) Nonsense.
THE CORRECT OPTION IS C. I've tested this, but used 1600 days so found only one file that old, used option C and it deleted it only, results below:
# find /var/log -type f -mtime +1600
/var/log/anaconda/syslog <<<<<<<<<<< found this file over 1600 days old-didn't want to remove anything important
# find /var/log -type f -mtime +1600 -exec rm {} \; <<<<<<<<<<< Executed option C
# find /var/log -type f -mtime +1600 <<<<<<<<<<< Ran command again and /var/log/anaconda/syslog is no longer present
The correct command to accomplish this task is C:
This command uses the find utility to search for files in the /var/log directory and its subdirectories. The -type f option specifies to search only for files (not directories), and the -mtime +180 option specifies to search for files that were modified more than 180 days ago. The -exec rm {} \; option specifies to execute the rm command on each file found by the find command. The {} characters are a placeholder for each file that is found, and the \; at the end of the command is used to terminate the -exec option.
Note that the other options listed are incorrect and should not be used.
Disagree. Correct answer should be C. The question refers to removing log "files". The type option for find needs -f for files.
upvoted 7 times
...
This section is not available anymore. Please use the main Exam Page.XK0-005 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
linux_admin
Highly Voted 1 year, 9 months agolinux_admin
1 year, 9 months agoNvoid
Highly Voted 1 year, 11 months agobc1235813
Most Recent 8 months agoe418137
9 months agoBryanSME
11 months agoDamon54
1 year, 3 months agoKnifeClown1
1 year, 9 months agoCkl22
1 year, 10 months agoMissAllen
2 years ago