Which of the following commands will accomplish this task?

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 {}
D . find /var/log -type c -atime +180 Cremove

Answer: C

Explanation:

The command that will accomplish the task of finding and removing all log files that were modified more than 180 days ago is find /var/log -type f -mtime +180 -exec rm {} ;. This command will use find to search for files (-type f) under /var/log directory that have a modification time (-mtime) older than 180 days (+180). For each matching file, it will execute (-exec) the rm command to delete it, passing the file name as an argument ({}). The command will end with a semicolon (;), which is escaped with a backslash to prevent shell interpretation.

The other options are not correct commands for accomplishing the task. The find /var/log -type d -mtime +180 -print -exec rm {} ; command will search for directories (-type d) instead of files, and print their names (-print) before deleting them. This is not what the task requires. The find /var/log -type f -modified +180 -rm command is invalid because there is no such option as -modified or -rm for find. The correct options are -mtime and -delete, respectively. The find /var/log -type c -atime +180 Cremove command is also invalid because there is no such option as Cremove for find. Moreover, it will search for character special files (-type c) instead of regular files, and use access time (-atime) instead of modification time.

References: find(1) – Linux manual page; Find and delete files older than n days in Linux

Latest XK0-005 Dumps Valid Version with 136 Q&As

Latest And Valid Q&A | Instant Download | Once Fail, Full Refund

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments