Grep file after loaded after a particular minute - shell

Can anyone please help me in getting the command to search files loaded after a particular minute.
Example:-
I want the files loaded after the time 2017/02/15.11.
That means all the files loaded after 11

First, you need to convert you custom date into a recognizable date format:
DATE="2017/02/15.11"
TIME="${DATE##*.}:00"
DATE="${DATE%.*}"
echo "DATE: ${DATE} TIME: ${TIME}"
Then just pass it to find:
find /dir -newermt "${DATE} ${TIME}"

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 to get the current date and time in specific format in Shell

I just want to get the system current time using below format in shell
Expected Format:
2019-02-14T08:08:12.300Z
I tried below piece of script but It returned something different.
CURRENTDATE=`date +"%Y-%m-%d %T"`
echo $CURRENTDATE
Output
2019-02-27 01:22:57
I just ran date command in my linux box and got below response back:
-bash-3.2$ date
Wed Feb 27 01:43:26 PST 2019
We are passing the above output as input JSON file. But this output is not accepted by our JSON. So I just want to pass the date and time format in the above specified format (Expected Format).
You may use:
dt=$(date '+%Y-%m-%dT%T.%zZ')
echo "$dt"
2019-02-27T04:35:56.-0500Z
Also note use of --iso-8601=seconds:
date --iso-8601=seconds
2019-02-27T04:37:29-05:00
You can also use this one like
currentDate=$(date +"%Y-%m-%dT%H:%M:%SZ")
echo $currentDate
OutPut :-
2022-07-12T18:05:27Z

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.)

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

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

Resources