find -daystart argument explanation - shell

So I understand that a line such as:
find /var/log/ -mtime +60 -type f -exec ls -l {} \;
Will list all files in /var/log which were modified 60 days or more ago.
After reading through the find man page though I noticed:
Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and
-mtime) from the beginning of today rather than from 24 hours
ago. This option only affects tests which appear later on the
command line.
Can someone explain the rest? (-amin, -atime, -cmin, -ctime, -mmin) The man page itself does not seem to really declare what each of these do?
Some example questions which might help me understand:
Find files modified an hour or more ago?
Find files modified between 60 minutes and 10 minutes ago?
Find files modified 2 weeks ago?
Find files created in the last 5 minutes?

Find files modified an hour or more ago?
-mmin +60
Find files modified between 60 minutes and 10 minutes ago?
-mmin -60 -mmin +10
Find files modified 2 weeks ago?
-mtime +7 -mtime -8
Find files created in the last 5 minutes?
Can't be done. POSIX has no specification for creation time.
These options are explained in the TESTS subsection of the EXPRESSIONS section of the find(1) man page.

Related

Move all the Files generated 23 hrs. after they were first created

I am using below command to pick the files 23 hrs after they were first created, but it is not picking can you tell me where i am going wrong
find /test/files -maxdepth 1 -type f -mtime +0.9
mtime +1 means 24 hours later
so, used +0.9 so it should pick 23 hours , but it is not picking.
I am afraid fractions will not work in find. What you can do is to create file with timestamp 23 hours ago and with find get older files:
touch -d '23 hours ago' /tmp/tmp_file
find /test/files -maxdepth 1 -type f ! -newer /tmp/tmp_file

Find and list files from last 3-days starting from midnight of first day [duplicate]

This question already has answers here:
Using find to locate files modified within yesterday
(2 answers)
Closed 2 years ago.
please assist, I am trying to list the files from last 3 days in directory starting from midnight of first day from last 3-days. I created this so far " find ./* -type f -mtime -3 -exec ls {} ;" This only pulls data from current time to - 3days. It doesn't get data from midnight of first day. I need a data start from last 3-days starting midnight to today.
Please assist.
thank you
You can touch a file with the earliest date you want to use. Then use find's -newer option.
touch -t <earliestDate> someTempFile
find . -type f -newer someTempFile -exec ls -l {} \;
You don't need -exec if you execute ls with no options and you're constrained to normal files.

In unix, how to extract last 60 days files from yesterday

I'm able to extract last 60 days files from current date. But I want last 60 days files from yesterday.
Below is the command, I'm using to fetch last 60 days files
find . -name $val\* -mtime -60 -print
I can pipe the output to another find probably like below
find . -name $val\* -mtime -60|find . -name $val\* -mtime 1 -print
But that would produce files which was modified exactly one days ago from the list of last 60 days files.
Pls help me how to achieve it.
You can provide multiple predicates to a single find command to filter the
list of files being returned. In this case, combining -mtime +1 with your
first command will return all the files that have been modified less than 60 days ago and (logical AND is implicit) more than one day ago:
find . -name $val\* -mtime -60 -mtime +1 -print
Is this command useful?
find . -name $val\* \( -mtime -61 -and -not -mtime -1 \) -print
It will list all last 61 days files but exclude files which were modified in last 24 hours.

Find directories that are older than 60 days by name

I have a directory with some files and subdirectories. In that directory I need to find files by name pattern ".cm-2015.10.10" that are older than 30 days. This command finds me the needed directories:
find comdit/ -type d -name .cm-[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9] -print
but how can I specify that I only need folders older than 60 days? Adding -ctime +60 did nothing for me. What am I doing wrong?
It's -mtime which you are looking for:
find comdit/ -type d -mtime +30 -name .cm-[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9] -print
Here are the docs:
-atime n
File was last accessed n*24 hours ago. When find figures out
how many 24-hour periods ago the file was last accessed, any
fractional part is ignored, so to match -atime +1, a file has to
have been accessed at least two days ago.
-ctime n
File's status was last changed n*24 hours ago. See the comments
for -atime to understand how rounding affects the interpretation
of file status change times.
-mtime n
File's data was last modified n*24 hours ago. See the comments
for -atime to understand how rounding affects the interpretation
of file modification times.

Bash command to delete everything older than half a day

I've got a simple bash script, cron'd to run at midnight each night, which creates a backup or files and stores them as a .tar.gz in my Dropbox. Before this happens, however, I need the script to delete the previous night's backup.
To do this I'm currently running this command:
find ~/Dropbox/Backups/casper/* -mtime +0.5 -exec rm {} \;
Which to my mind should delete anything older than half a day - but it doesn't seem to work (it keeps the previous nights back-up, but deletes anything before this)
Can someone point me in the right direction please? Thank you
From the manpage for find:
-mtime n
File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the
interpretation of file modification times.
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last
accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days
ago.
From this we can see that the 0.5 is dropped, then 1 day ago is required. You probably want to use -mmin instead.
For example (from babah):
# 720 is 60 times 12
find ~/Dropbox/Backups/casper/* -mmin 720 -print -exec rm {} \;

Resources