3

I google the find doc,and wrote this

find . -type f -depth 1 -Btime 1

howerver ,I doesn`t work? how can I get this done?

newlife
  • 778
  • 1
  • 6
  • 20

3 Answers3

4

-Btime 5 matches files that were created five days ago (where 4.1 is rounded up to 5 and 5.1 is rounded up to 6). If you meant files created between now and five days ago, use -Btime -5.

find . -type f -Btime -5 # five days ago or newer
find . -type f -Btime 5 # five days ago
find . -type f -Btime +5 # five days ago or older
find . -type f -Btime +5 -Btime -10 # between five days ago and ten days ago

Also -maxdepth 1 or -mindepth 1 -maxdepth 1 is faster than -depth 1. -depth 1 traverses all files under the directory tree.

The format that can be used with -atime, -Btime, -ctime, and -mtime is described under -atime:

-atime n[smhdw]
        If no units are specified, this primary evaluates to true if the difference
        between the file last access time and the time find was started, rounded up to
        the next full 24-hour period, is n 24-hour periods.

        If units are specified, this primary evaluates to true if the difference between
        the file last access time and the time find was started is exactly n units.  Pos-
        sible time units are as follows:

        s       second
        m       minute (60 seconds)
        h       hour (60 minutes)
        d       day (24 hours)
        w       week (7 days)

        Any number of units may be combined in one -atime argument, for example, ``-atime
        -1h30m''.  Units are probably only useful when used in conjunction with the + or
        - modifier.
Lri
  • 26,768
  • 8
  • 84
  • 82
0

Your post is similar to this thread. Anyhow you can have a command like this.

find -newerct 'now -1 hour'

Or

BEFORE=$(( $(date '+%s') - 3600 )) ## In seconds = 1 hour.
find -type f -printf '%C@ %p\n' | while read -r TS FILE; do TS=${TS%.*}; [[ TS -ge BEFORE ]] && echo "$FILE"; done

If you plan to base it from modification time, you can have this

find -newermt '-1 hour'

Or

BEFORE=$(( $(date '+%s') - 3600 )) ## In seconds = 1 hour.
find -type f -printf '%T@ %p\n' | while read -r TS FILE; do TS=${TS%.*}; [[ TS -ge BEFORE ]] && echo "$FILE"; done
Community
  • 1
  • 1
konsolebox
  • 72,135
  • 12
  • 99
  • 105
  • thanks for your quick reply,which shell does you use? what '-newerct'does do? I can`t find this option in doc – newlife Sep 07 '13 at 16:49
  • `-newerct` is the inode change time (like `-ctime`); not the creation time (like `-newerbt` or `-Btime`). OS X's `find` doesn't support `-printf`, but you can install GNU `find` with `brew install findutils`. – Lri Sep 07 '13 at 17:04
0
find . -type f -depth 1 -Btime -1

and "-" to the num defined

newlife
  • 778
  • 1
  • 6
  • 20