Ive been a vocal of FIND command even before. Command below doesnt really give me the file that is older than two weeks.. Is there a script that will list me the log files that i want like for this date December 10, 2014, it shud list me the date between November 26, 2014 and below.
When i run that command, it gives me Novemebr 11, we all know nvember 11 is more than two weeks ago.
Ive been a vocal of FIND command even before. Command below doesnt really give me the file that is older than two weeks.. Is there a script that will list me the log files that i want like for this date December 10, 2014, it shud list me the date between November 26, 2014 and below.
When i run that command, it gives me Novemebr 11, we all know nvember 11 is more than two weeks ago.
that command seems to work fine for me ... shows me files from Nov 17, Nov 3, and older,
but not a file from Nov 28.
Can you show some ls -ltr commands and getfacl commands on the files you believe it should pull back .. and show the command running and not picking them up?
(setup a smaller test directory if you need to .. )
[edit]
[/edit]
Last edited by Ditto; 12-10-2014 at 03:56 PM..
Reason: working sample
Command below doesnt really give me the file that is older than two weeks find /tmp/logs* -type f -mtime +14 -exec ls -lrt {} \;
Well, I disagree. 11. November fits exactly into the range you specified to find.
c.f. man find:
Quote:
-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.
I disagreed with the quoted sentence from post#1, which means I'm d'accord with your (Ditto's) statement. -mtime points to a given point in time n *24 hours ago, +n opens that to a range larger than n, meaning everything older than that point in time.
mtime works days made of epoch seconds, see the stat structure for st_mtime.
There are 86400 seconds per day. -mtime 14 means EXACTLY, to the second, 86400*14 seconds ago. -mtime +14 means any file mtime equal to or greater than 86400*14,
-mtime -14 means less than 86400*14.
Some ways to get file by filetime using find (in the context of post #1)
With:
Today = Dec 12, two weeks ago = Nov 27
These examplesrefer to mtime, the last time the file was opened and written to. NOT
when it was created, but it usually works out to the same thing in most
users view. This is using POSIX find. Linux find is slightly different but
will work with these examples.
Note: touch examples are accurate to the minute only. touch -t syntax seems to vary.
Check your system.
Note: some filesystems have more precision on filetimes than others.
Note: "start" and "end" are dummy files in the current directory, a
directory that you can write in. I personally use dummy, dummy1, and
dummy2 so I know what they are and why they are empty. start and end are
clearer for this example. IMO.
1. get files last written exactly before Nov 27 at midnight
2. get files written after Nov 27, i.e., from the first second of Nov 28 -> present
3. Using mtime for files older than some number of days. mtime uses days
based on 86400 seconds per day. STARTING RIGHT NOW. So if you execute this
at 1500 you will get files which will have filetime of 1521 (and greater)
on what seems to be the wrong day. mtime does understand the calendar.
4. get files from two past times - a range Nov 7 -> Nov 20.
No files from Nov 6 and earlier, and no files dated Nov 21 -> now
I disagreed with the quoted sentence from post#1, which means I'm d'accord with your (Ditto's) statement. -mtime points to a given point in time n *24 hours ago, +n opens that to a range larger than n, meaning everything older than that point in time.
The below bash is trying to list the folders in a specific directory. It seems close but adds the path to the filename, which basename could strip off I think, but not sure why it writes the text file created? This list of folders in the directory will be used later, but needs to only be the... (5 Replies)
I have written a script which generate one logfile on every sunday and thursday
I want to move the older log files into /tmp directory befor generating new one so i used mv command like
mv usr/sbin/appl/logfile.txt usr/sbin/appl/tmp
2) But when i move this file to /tmp it will... (1 Reply)
There is another post in the forums that is similar to what I am trying to do, however, the thread is closed. So, I am creating this new one to see if someone could help. I am trying to use the code Ahamed posted, and tweak it.
With the info from the forum, I recreated the scenario the person... (8 Replies)
I Need help for one requirement,
I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix.
Example:
Source Directory : \a
destination Directory : \a\b
File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt)
File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Hi, Friends,
I am writing a script to delete all the files which are there for more than 3 weeks.
I have tried this :
find /home/appl/backup -type f -mtime +21 -exec rm -f {} \;
But i am not sure if it deletes only the files in specified directory or all the directorinies in the provieded... (3 Replies)
Hi,
I'm the new user of linux/unix. Can I ask that anybody know how to use the linux/unix shortcut key to search a specific file from a list of directory?
For example, I know the file name that I want to search. But I forget which directory or location is my desired file put.Got any shortcut... (7 Replies)
Hi,
I am trying to find the content of file using grep and find command and list only the file names
but i am getting entire file list of files in the directory
find . -exec grep "test" {} \; -ls
Can anyone of you correct this (2 Replies)
Say folder archive/ contains many folder each created on a day. this folder may contain files. i want to write a script to delete all the folder inside archive/ which are 7 days older. i used the below script for the reason.
find archive -mtime +7 -type d -exec rm -r {} \;
pls suggest me if... (3 Replies)
I need to list all files and subdirectories that contain "oradata".
For example, I have several files in several different directories that contain "oradata". I.e.
/u07/oradata/1.dbf
/u09/unix/whatever/oradata/2.xxx
That is, whatever file on the system that contains a directory called... (7 Replies)