Finding the files which are not accessed/modified in last 30min? - bash

I've one requirement, i want to give the notifications to the users who have not accessed the files in 30 min. using the shell script. Is it possible to find the files which was not accessed in 30 min using find. I'd checked.
find /opt/SP/tibmft/scripts/ -mtime 0
which will fetch the files which was modifed in last 24 hours.
My requirement is fetch the files which was created in the last 30 min and not been accessed by the user? Please suggest the solution, how to achieve this?

Try using
find PATH -cmin -30 -and -amin +30

Is it possible to find the files which was not accessed in 30 min using find.
According to man find:
Numeric arguments can be specified as
+n for greater than n,
-n for less than n,
n for exactly n.
Please note, this is greater and less not greater/less or equal. So, you have to take some care in order to not have a 1 minute error due to that:
find PATH -not -amin +30
or
find PATH -amin -31
My requirement is fetch the files which was created in the last 30 min and not been accessed by the user?
Here is an attempt:
find PATH -amin -31 -not -newerBt "-30 minutes"
# ^^^^^^^^
# (B)irth date newer (t)han ...
... unfortunately, it does not work on my computer with ext4 file-system, as, to quote a comment by Barmar above: "Most Unix file-systems don't record file creation time. They just have modification, access, and inode change times."
Some random ideas:
According to one of your comment, this is potentially a periodic task. So one might investigate the use of a cron job to record the list of files at regular intervals?
If your file-system has snapshots you might build on that too. Maybe.

Try the following:
find $PATH -type f -cmin -30 amin +30

Related

wrong script and syntax trouble

goal:
find all documents (texts, pdfs, fotos, etc) on my computer (located in different files) which were changed after a specific date and copy them to a different file,
that's what I typed in a terminal:
find . maxdepth 1 -newermt 2022-02-26 -exec / cp /Schreibtisch/new files after feb 28
as a response I get: missing argument for -exec
cant find the error, pls help
tx,
michael

How can I find log files only within 2 minutes of current time from log folder

I am beginner to shell
I Have one log Folder where logs are getting generated in format as:
ACS_1/ACS1_Events_OG_Multiple_20200126_014453.log
ACS_2/ACS1_Events_OG_Multiple_20200126_014300.log
ACS_3/ACS1_Events_OG_Multiple_20200126_020553.log
I want to find logs which are falling in between 2 minutes of time (014315 to 014515)
I tried to use
find . -name "ACS1_Events_OG_Multiple_20200126_01[4][3,5]*"
but I'm not getting exact result, I have to create automated logs between any given time range.
so you can use cmin, just specify whether you want the time to be smaller or greater or equal to the time you want, using, respectively:
#smaller - you have to use - before your time
find your-location -cmin -your-time
#greater - you have to use + before your time
find your-location -cmin +your-time
#equal
find your-location -cmin your-time
for example we wanna check 2 minutes from current time
find . -iname "ACS1_Events_OG_Multiple_*.log" -cmin -2
or even better, for example as you wrote you have ACS1 ACS2 ACS3 so better to use ? instead of number, like this :
find . -iname "ACS?_Events_OG_Multiple_*.log" -cmin -2
good luck

Delete files whose last access time exceeds N days

The task is to write a bash scenario to delete in a directory those files whose last access time exceeds N days.
If there are no such files, the message should be displayed.
I'm trying to delete 1 file and find the last access time for it:
stat -c%x test.txt
The command returns a date: 2018-12-01 16:45:30.390000000 +0000
Then I'm writing a current date command:
date '+%Y-%m-%d %H:%M:%S.%N'
The command returns a date: 2018-12-01 18:39:16.873718766
Now I have no idea how to subtract this dates and apply to all files of the directory.
Use the command find with a parameter -atime.
find /path/to/dir -atime +100 -delete
deletes files accessed 101 or more days ago.

How to get access_log summary by goaccess starting from certain date?

Currently I keep 6 weeks of apache access_log. If I generate a access summary at month end:
cat /var/log/httpd/access_log* | goaccess --output-format=csv
the summary will include some access data from previous month.
How can I skip logs of previous month and summarise from first day of month?
p.s. the data-format is: %d/%b/%Y
You can trade the Useless Use of cat for a useful grep.
grep -n $(date +'[0-3][0-9]/%b/%Y') /var/log/httpd/access_log* |
goaccess --output-format=csv
If the logs are by date, it would be a lot more economical to skip the logs which you know are too old or too new, i.e. modify the wildcard argument so you only match the files you really want (or run something like find -mtime -30 to at least narrow the set to a few files).
(The cat is useless because, if goaccess is at all correctly written, it should be able to handle
goaccess --output-format=csv /var/log/httpd/access_log*
just fine.)

Find directories created less than a week ago

I know I can use this command to find directories created or modified less than a week ago:
find /home -type d -mtime -7
But how do I find directory that were created less than a week ago?
Creation time is not stored.
There is only 3 timestamps you can check
Last access time
Last modification time
Last change time
"Change" is one of: permission changes, rename etc.
While the modification is contents only.
Short answer: you can't.
There are three times stored in an inode
ctime: time of creation or change of the inode
mtime: time of last change of the file that the inode refers to
atime: time of last access to the file
The point is: ctime is altered not only by create, but also by chmod / chown, maybe even by ln (not sure). Man stat and man touch are your friends.
If you try to find fresh directories by means of find /home -type d -mtime -7 be prepared to also find older directories that had their mode or owner changed.

Resources