0
0
Linux CLIscripting~15 mins

find by modification time in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Find Files by Modification Time
📖 Scenario: You are managing files on a Linux system. Sometimes you need to find files that were changed recently to clean up or back up important data.
🎯 Goal: Learn how to use the find command to locate files based on their modification time.
📋 What You'll Learn
Create a directory with some files
Set a time threshold variable
Use the find command with the -mtime option
Display the list of files modified within the threshold
💡 Why This Matters
🌍 Real World
System administrators often need to find recently changed files to back up or clean up data.
💼 Career
Knowing how to use <code>find</code> with modification time is essential for Linux system management and scripting automation.
Progress0 / 4 steps
1
Create a directory and files
Create a directory called testdir and inside it create three empty files named file1.txt, file2.txt, and file3.txt.
Linux CLI
Need a hint?

Use mkdir to make a directory and touch to create empty files.

2
Set a modification time threshold
Create a variable called days and set it to 1 to represent files modified within the last 1 day.
Linux CLI
Need a hint?

Use days=1 to set the variable.

3
Use find command with modification time
Use the find command to list files in testdir that were modified within the last $days days. Use -mtime -$days option.
Linux CLI
Need a hint?

The -mtime -1 option finds files modified less than 1 day ago.

4
Display the found files
Print the output of the find command that lists files modified within the last $days days.
Linux CLI
Need a hint?

Just run the find command to see the list of files.