Find files modified over 1 hour ago but less than 3 days
Find has -mtime and -mmin:
find . -mtime +3 -mmin -60
From the find manual:
Numeric arguments can be specified as:
+n for greater than n
-n for less than n
n for exactly n
find -mtime files older than 1 hour
What about -mmin
?
find /var/www/html/audio -daystart -maxdepth 1 -mmin +59 -type f -name "*.mp3" \
-exec rm -f {} \;
From man find:
-mmin n
File's data was last modified n minutes ago.
Also, make sure to test this first!
... -exec echo rm -f '{}' \;
^^^^ Add the 'echo' so you just see the commands that are going to get
run instead of actual trying them first.
Find the files that have been changed in last 24 hours
To find all files modified in the last 24 hours (last full day) in a particular specific directory and its sub-directories:
find /directory_path -mtime -1 -ls
Should be to your liking
The -
before 1
is important - it means anything changed one day or less ago.
A +
before 1
would instead mean anything changed at least one day ago, while having nothing before the 1
would have meant it was changed exacted one day ago, no more, no less.
Find files created 1 hour ago
I think what you want is
find . -cmin +60 -exec ls -al {} \;
It will list all the files in current directory created more than 60 minutes agp.
The '+' in the '+60' means more than 60 minutes ago while a '-' in the '-60' means less than 60 minutes ago.
Using find to locate files modified within yesterday
Use find with mtime
and daystart
, it will find files modified 1*24 hours ago, starting calculations from midnight (daystart):
find dir -daystart -mtime 1
Get all files modified in last 30 days in a directory
A couple of issues
- You're not limiting it to files, so when it finds a matching directory it will list every file within it.
- You can't use
>
in-exec
without something likebash -c '... > ...'
. Though the>
will overwrite the file, so you want to redirect the entirefind
anyway rather than each-exec
. +30
isolder
than 30 days,-30
would be modified in last 30 days.-exec
really isn't needed, you could list everything with various-printf
options.
Something like below should work
find . -type f -mtime -30 -exec ls -l {} \; > last30days.txt
Example with -printf
find . -type f -mtime -30 -printf "%M %u %g %TR %TD %p\n" > last30days.txt
This will list files in format "permissions owner group time date filename". -printf
is generally preferable to -exec
in cases where you don't have to do anything complicated. This is because it will run faster as a result of not having to execute subshells for each -exec
. Depending on the version of find
, you may also be able to use -ls
, which has a similar format to above.
Related Topics
Undefined Reference to Symbol 'Pthread_Key_Delete@@Glibc_2.2.5
Is There an Equivalent to Dbus on Osx
What Is The Meaning of This Macro _Ior(My_Macig, 0, Int)
How to Curl Using Ipv6 Address
Linux - Check If There Is an Empty Line at The End of a File
New Syscall Not Found (Linux Kernel 3.0.0) Where Should I Start Looking
Load Warning: Cannot Find Entry Symbol _Start
How to Call Makefile Located in Other Directory
Linux Ssh Bash Fork Retry: No Child Processes
Understanding Linux Directory Permissions Reasoning
How to Answer Yes in Bash Script
Execute Bash Script Remotely via Curl
Jenkins/Hudson Ci Minimum Requirements for a Linux Rh Installation