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

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.

Related

Find and tar files which are X hours old

I am trying to tar all the log files of a specific folder which are X hours old, i have done it with X days and I need it for X hours.
find $DEST_DIRECTORY/*.log -type f ! -name "*.tar.gz" -mtime +$hours -exec mv '{}' ${DEST_DIRECTORY}/${TAR_DIR_NAME}/ \
Above code is not working for hours.
Use:
-mmin n to filter for files that were modified n minutes ago.
So in your example you should replace -mtime +$hours with -mmin +$[$hours * 60].
Full docs are here: http://man7.org/linux/man-pages/man1/find.1.html
you should try this :
find $DEST_DIRECTORY/*.log -type f ! -name "*.tar.gz" -mmin -180
180 refers to 3 hours and you can tweak it to your need

How to find files older than 60 minutes only in current directory

The following command it finding all the files which are older than 60 minutes but in sub directories also.
find . -type f -mmin +60 -print
How can we restrict it find files only in given directory?
I have archive folders in sub direcotries which have older files that is causing problem.
Thanks in advance :)
Use the -maxdepth 1 argument to find to limit results to the current directory.
So your full command would be find . -type f -mmin +60 -maxdepth 1 -print
find ./your-directory -daystart -maxdepth 1 -mmin +10 -type f -delete

Need to find files modified between 15 and 5 minutes ago

I'm trying to find all files in a given folder that were modified withing a certain time frame, say between 5 and 15 minutes ago.
Currently I can find anything modified say up to 15 minutes ago by using find -cmin
#!/bin/bash
minutes="15"
FILETYPES=`find . *PATTERN*.txt* -maxdepth 0 -type f -cmin -$minutes`
How do I give it a time frame?
Try this :
find . -name '*pattern.txt' -maxdepth 1 -type f \( -mmin -15 -a -mmin +5 \)
Notes
the parenthesis are not mandatory here with and : -a, but it's necessary for case with or: -o
always use single quotes around the pattern to prevent shell expansion of the wildcard
to give a pattern, use -name or -iname
for the date/hour, -mmin is the way to go for minutes and -mtime for days.
Using find, you can add additional conditions to create the range. Each condition is implied as "and" unless -o is used. You also want -mmin instead of -cmin for modified time (but they are often the same).
find . '*PATTERN*.txt*' -maxdepth 0 -type f -mmin -15 -mmin +5

Recursively delete files in directory

How do I recursively delete files in directory that were modified more than 6 hours ago?
This example work for 1 day:
find /data2/input -type f -mtime +1 -delete -print
Use -mmin instead of mtime. It will allow you to specify the number of minutes since the files was last modified. So for files older than 6 hours:
find /data2/input -type f -mmin +360 -delete -print
Check the flags -cmin or -mmin in the manual page.

find and number of days range

I tried to code in bash an archiving script but I can't seem to get find() working with an interval in number of days.
The ranges I need to code are
files last modified between today and 31 days old. This works:
find . -name "*.VER" -mtime -31 -exec mv '{}' /opt/html/31';' -print
files last modified between 31 days and 62 days old. This does not work:
find . -name "*.VER" -mtime -31 -mtime -62 -exec mv '{}' /opt/html/62 ';' -print
files last modified between 62 days and 93 days old
files last modified between 93 days and 124 days old
...you get the idea (up to year)....
Is there a way to code my find() command to use a number of days range??
I think you have to change the logic of + and - in the times:
find . -name "*.VER" -mtime +31 -mtime -62 -exec mv '{}' /opt/html/62 ';' -print
This tells: files with a mtime greater than 31 days but less than 61 days.

Resources