How to List Only Today’s Files in Linux: A Practical and Complete Guide

How to List Only Today’s Files in Linux: A Practical and Complete Guide
Photo by Kolby Milton / Unsplash

Managing files efficiently is part of every developer’s daily routine. One common need is to display only the files modified today. While the ls command is often the first tool people think of, it is important to understand its limitations and the proper alternatives available in Linux.

This article walks you through the correct methods, highlights important considerations, and explains common pitfalls so you can reliably filter files by date like a pro.


Why ls Alone Cannot Filter Today’s Files

It is a common misconception that ls can filter files based on dates. Although ls can display timestamps, it cannot perform date-based filtering by itself. Any attempt to “filter” using ls relies on using grep on the date string, which can work but is not fully reliable.

Example (works but not robust):

ls -lt --time-style=+%F | grep "$(date +%F)"

This approach is not recommended because:

  • It may fail if your locale or time format differs.
  • It does not handle timezones well.
  • It cannot detect files touched today but with time formatting differences.

For accurate results, use find.


The Correct and Reliable Way: Using find

The find command is designed for filesystem queries and handles time-based filtering with precision.

List only files modified today

find . -maxdepth 1 -type f -daystart -mtime 0

Breakdown:

  • . → search in current directory
  • -maxdepth 1 → don’t enter subdirectories
  • -type f → files only
  • -daystart → counts time from the start of the current day, not 24 hours backward
  • -mtime 0 → modified between today at 00:00 and now

This is the most accurate method.


Show in a Detailed Listing (similar to ls -l)

If you want the output to look like a normal ls -lh listing:

find . -maxdepth 1 -type f -daystart -mtime 0 -exec ls -lh {} +

This gives you:

  • file size
  • permissions
  • owner
  • timestamp
  • human-readable formatting

Including Subdirectories

If you want to scan the entire folder tree:

find . -type f -daystart -mtime 0

Filtering Files Modified in the Last X Hours

Sometimes you want files from the last 24 hours (not from 00:00 today).

find . -type f -mmin -1440

Where:

  • -mmin -1440 means “modified less than 1440 minutes ago”

Filtering by Creation Time (If Supported)

Some filesystems (like ext4 with crtime) allow viewing creation time, but standard find cannot filter by creation time directly.
To inspect a single file’s creation time:

stat filename

Look at Birth: timestamp.


Case Study: Why These Commands Matter

Imagine you're working on:

  • log directory cleanups
  • CI/CD artifact detection
  • daily backup verification
  • analyzing newly uploaded files

Relying on ls can produce false matches or miss files. Using find ensures precision and stability, especially in production environments.


Additional Tips and Considerations

1. Timezone Awareness

Linux timestamps follow system timezone. If you recently changed timezone or use UTC for consistency (common in servers), be aware that “today” depends on system clock.

2. Hidden Files

To include hidden files (.env, .config, etc.):

find . -maxdepth 1 -daystart -mtime 0 -type f -print

Find does not ignore hidden files.

3. Excluding Certain Files

Example: skip .log files:

find . -maxdepth 1 -type f -daystart -mtime 0 ! -name "*.log"

4. Using xargs for Performance

If you expect thousands of files:

find . -type f -daystart -mtime 0 -print0 | xargs -0 ls -lh

This avoids command-execution overhead.

5. Select Using Access Time

To filter by last accessed today:

find . -daystart -atime 0 -type f

6. Select Using Change Time

To filter by metadata changes (permissions, ownership):

find . -daystart -ctime 0 -type f

Finally

Listing only today’s files in Linux requires a proper understanding of what each tool can and cannot do. While ls is helpful for viewing, find is the correct tool for filtering.

To summarize the essential commands:

Most Accurate

find . -maxdepth 1 -type f -daystart -mtime 0

Detailed View

find . -maxdepth 1 -type f -daystart -mtime 0 -exec ls -lh {} +

Search Entire Directory Tree

find . -type f -daystart -mtime 0

With these methods, you can reliably locate all files modified today, control the output, and tailor the filtering to your workflow.

Support Us

Share to Friends