Bird
0
0

Which command creates an xz compressed archive of the logs directory including only files modified within the last 7 days?

hard📝 Application Q8 of 15
Linux CLI - Archiving and Compression
Which command creates an xz compressed archive of the logs directory including only files modified within the last 7 days?
Afind logs -mtime -7 -print0 | tar --null -T - -cJf logs.tar.xz
Btar -cJf logs.tar.xz --newer-mtime='7 days ago' logs
Ctar -cJf logs.tar.xz logs --exclude='*' --include='*7days*'
Dfind logs -mtime +7 | tar -cJf logs.tar.xz -T -
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    Create an xz compressed archive including only files modified in last 7 days.
  2. Step 2: Analyze options

    find logs -mtime -7 -print0 | tar --null -T - -cJf logs.tar.xz uses find with -mtime -7 to select files modified within 7 days, then passes them to tar with --null and -T - to read null-separated filenames.
  3. Step 3: Why others are incorrect

    tar -cJf logs.tar.xz --newer-mtime='7 days ago' logs uses --newer-mtime which is not a standard tar option. tar -cJf logs.tar.xz logs --exclude='*' --include='*7days*' uses invalid --include and --exclude patterns. find logs -mtime +7 | tar -cJf logs.tar.xz -T - finds files modified more than 7 days ago, opposite of requirement.
  4. Final Answer:

    find logs -mtime -7 -print0 | tar --null -T - -cJf logs.tar.xz -> Option A
  5. Quick Check:

    Use find with -mtime and tar with --null -T - [OK]
Quick Trick: Use find -mtime -7 with tar --null -T - for selective archiving [OK]
Common Mistakes:
  • Using incorrect tar options like --newer-mtime
  • Confusing -mtime +7 with -mtime -7
  • Trying to filter files inside tar without external find

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes