Sponsored Content
Top Forums Shell Programming and Scripting List 2 weeks older file on specific directory Post 302928414 by jim mcnamara on Thursday 11th of December 2014 12:39:11 PM
Old 12-11-2014
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
Code:
touch -t 201411270000 end
find /path -type f ! -newer end

2. get files written after Nov 27, i.e., from the first second of Nov 28 -> present

Code:
# you should add seconds to the touch -t value
touch -t 201411272359 start
find /path -type f -newer start

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.

Code:
# older files more then 14 * 86400 seconds old.
find /path -type f -mtime +14
# newer - files written after (the time and date of) 84600 * days in the past
find /path -type f -mtime -14

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

Code:
# mind the touch seconds
touch -t 201411070000 start
touch -t 201411202359 stop
find /path -type f \( -newer start -a  ! -newer end \)

 

10 More Discussions You Might Find Interesting

1. Solaris

List all files that contain a specific directory

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)
Discussion started by: Sat510
7 Replies

2. Shell Programming and Scripting

List directory 7 days older

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)
Discussion started by: krishnarao
3 Replies

3. Shell Programming and Scripting

how to check whether the given file is 5 weeks older than current date

HI, I need to check whether the given file is 5 weeks older than current date ?? Can anyone give me the script for this ?? (1 Reply)
Discussion started by: risshanth
1 Replies

4. AIX

find for specific content in file in the directory and list only file names

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)
Discussion started by: madhu_Jagarapu
2 Replies

5. UNIX for Dummies Questions & Answers

Linux shortcutkey to search specific file from a list of directory?!

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)
Discussion started by: patrick87
7 Replies

6. Shell Programming and Scripting

Delete the files older than 3 weeks in a particular directory.

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)
Discussion started by: rajsharma
3 Replies

7. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

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)
Discussion started by: pp_ayyanar
1 Replies

8. Shell Programming and Scripting

[SOLVED] Pull lines older than N weeks

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)
Discussion started by: karstenjhilton
8 Replies

9. Shell Programming and Scripting

Move log files with date and delete older than 3 weeks

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)
Discussion started by: Nakul_sh
1 Replies

10. Shell Programming and Scripting

Bash to list all folders in a specific directory

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)
Discussion started by: cmccabe
5 Replies
TOUCH(1)							   User Commands							  TOUCH(1)

NAME
touch - change file timestamps SYNOPSIS
touch [OPTION]... FILE... DESCRIPTION
Update the access and modification times of each FILE to the current time. Mandatory arguments to long options are mandatory for short options too. -a change only the access time -B, --backward=SECONDS Modify the time by going back SECONDS seconds. For example, touch -r foo -B 5 bar will make the file bar 5 seconds older than file foo. -c, --no-create do not create any files -d, --date=STRING parse STRING and use it instead of current time -F, --forward=SECONDS Modify the time by going forward SECONDS seconds. For example, touch -r foo -F 5 bar will make the file bar 5 seconds newer than file foo. -f (ignored) -m change only the modification time -r, --reference=FILE use this file's times instead of current time -t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time --time=WORD set time given by WORD: access atime use (same as -a) modify mtime (same as -m) --help display this help and exit --version output version information and exit Note that the -d and -t options accept different time-date formats. AUTHOR
Written by Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, and Randy Smith. REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>. COPYRIGHT
Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for touch is maintained as a Texinfo manual. If the info and touch programs are properly installed at your site, the command info touch should give you access to the complete manual. touch (coreutils) 4.5.3 October 2002 TOUCH(1)
All times are GMT -4. The time now is 06:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy