Sponsored Content
Top Forums Shell Programming and Scripting Deleting the files between particular dates Post 302916443 by Makarand Dodmis on Wednesday 10th of September 2014 04:50:46 AM
Old 09-10-2014
Hi Shiv

i am assuming you are running below code today.
So it will list 10 days older files but not 253 days older.
243 means 01 jan 14 to 31 Aug 14. and 1 sep to 10 sep (10 days)
The files before 01 jan 14 will not be listed.
first list the files . verify the files then run the rm command
to list the files
Code:
find . -type f -mtime +10 -mtime -253 -exec ls {} +

to delete the files
Code:
find . -type f -mtime +10 -mtime -253 -exec rm {} +

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remove files by dates

I've tried every way possible to remove files by date and nothing seems to work. Does anyone have an idea how to remove files by dates? Thanks in advance.... (1 Reply)
Discussion started by: dman110168
1 Replies

2. UNIX for Dummies Questions & Answers

deleting files with dates 3 months ago

please help me with this????? :confused: :confused: i need to create a program that will run in unix that will delete all files in a given directory that is at least 3 months old. first the program will need to automatically know what date it is right now to determine the files it will... (3 Replies)
Discussion started by: godalle
3 Replies

3. UNIX for Dummies Questions & Answers

Files and dates

Hello all. I am trying to do a file listing on a particular directory by date. I need to list the files and their directories that have a timestamp between Dec-1-2006 and Jan-1-2007. Any help would be greatly appreciated. (1 Reply)
Discussion started by: mastachef
1 Replies

4. UNIX for Dummies Questions & Answers

files between any two given dates

Can any one help me in getting all the files between any two given dates.. (8 Replies)
Discussion started by: thanuman
8 Replies

5. UNIX for Dummies Questions & Answers

Deleting the files comparing the creation dates

Hi Gurus, I am new to unix. I have a requirement where i need to delete some files in a folder twice a week. Suppose i have a folder AAA. In that i have files from 01/04/2008 to 10/04/2008 I want to remove all the files except last 3 days i.e., 10,9th & 8th. Every week twice we want to... (2 Replies)
Discussion started by: pssandeep
2 Replies

6. Shell Programming and Scripting

AIX system.... deleting files in remote directory after retrieving files

Hi Friends, I am new to this , I am working on AIX system and my scenario is to retrive the files from remote system and remove the files from the remote system after retreving files. I can able to retrieve the files but Can't remove files in remote system. Please check my code and help me out... (3 Replies)
Discussion started by: vinayparakala
3 Replies

7. AIX

Copy files for particular dates

Hi, I need to copy particular date files from one directory to another. For example, I have thousands of files in /home/usr From this I need to copy only particular date files (each date contains thousand number of files) to some directory of another server. Could anyone please help me... (3 Replies)
Discussion started by: teddy2882
3 Replies

8. UNIX for Advanced & Expert Users

Find all files other than first two files dates & last file date for month

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

9. Shell Programming and Scripting

Files between two dates in UNIX

Hi Team, I need to connect to a prod server and need to get the files which falls between two dates. I should not create ant files on that machine. I am using korn shell. Your help is very much appreciated. Vinay (13 Replies)
Discussion started by: gvkumar25
13 Replies

10. UNIX for Dummies Questions & Answers

Need to Move files of different dates

Hi, Currently I'm moving the files based on date like below. "mv *20150901* backup_folder" - Limitation: can move only 1 day files to backup folder. I want to move the files of different dates like 20150901,02, 03, 04..... Is there any single command to do it. Thanks in advance!! (2 Replies)
Discussion started by: prakashs1218
2 Replies
TMPWATCH(8)						   System Administrator's Manual					       TMPWATCH(8)

NAME
tmpwatch - removes files which haven't been accessed for a period of time SYNOPSIS
tmpwatch [-u|-m|-c] [-MUXadfqstvx] [--verbose] [--force] [--all] [--nodirs] [--nosymlinks] [--test] [--fuser] [--quiet] [--atime|--mtime|--ctime] [--dirmtime] [--exclude path] [--exclude-user user] [--exclude-pattern pattern] time dirs DESCRIPTION
tmpwatch recursively removes files which haven't been accessed for a given time. Normally, it's used to clean up directories which are used for temporary holding space such as /tmp. When changing directories, tmpwatch is very sensitive to possible race conditions and will exit with an error if one is detected. It does not follow symbolic links in the directories it's cleaning (even if a symbolic link is given as its argument), does not switch filesystems (including non-trivial bind mounts), skips lost+found directories owned by the root user, and only removes empty directories, regular files, symbolic links, and on some systems also unused sockets. By default, tmpwatch dates files by their atime (access time), not their mtime (modification time). If files aren't being removed when ls -l implies they should be, use ls -u to examine their atime to see if that explains the problem. If the --atime, --ctime or --mtime options are used in combination, the decision about deleting a file will be based on the maximum of these times. The --dirmtime option implies ignoring atime of directories, even if the --atime option is used. The time parameter defines the threshold for removing files. If the file has not been accessed for time, the file is removed. The time argument is a number with an optional single-character suffix specifying the units: m for minutes, h for hours, d for days. If no suffix is specified, time is in hours. Following this, one or more directories may be given for tmpwatch to clean up. OPTIONS
-u, --atime Make the decision about deleting a file based on the file's atime (access time). This is the default. Note that the periodic updatedb file system scans keep the atime of directories recent. -m, --mtime Make the decision about deleting a file based on the file's mtime (modification time) instead of the atime. -c, --ctime Make the decision about deleting a file based on the file's ctime (inode change time) instead of the atime; for directories, make the decision based on the mtime. -M, --dirmtime Make the decision about deleting a directory based on the directory's mtime (modification time) instead of the atime; completely ignore atime for directories. -a, --all Remove all file types, not just regular files, symbolic links and directories. On systems where tmpwatch can remove unused sockets, make the decision only based on file times, ignoring possible use of the socket. -d, --nodirs Do not attempt to remove directories, even if they are empty. -f, --force Remove root-owned files even if root doesn't have write access (akin to rm -f). -l, --nosymlinks Do not attempt to remove symbolic links. -q, --quiet Report only fatal errors. -s, --fuser Attempt to use the "fuser" command to see if a file is already open before removing it. Not enabled by default. Does help in some circumstances, but not all. Dependent on fuser being installed in /sbin. Not supported on HP-UX or Solaris. -t, --test Don't remove files, but go through the motions of removing them. This implies -v. -U, --exclude-user=user Don't remove files owned by user, which can be an user name or numeric user ID. -v, --verbose Print a verbose display. Two levels of verboseness are available -- use this option twice to get the most verbose output. -x, --exclude=path Skip path; if path is a directory, all files contained in it are skipped too. If path does not exist, it must be an absolute path that contains no symbolic links. -X, --exclude-pattern=pattern Skip paths matching pattern; if a directory matches pattern, all files contained in it are skipped too. pattern must match an abso- lute path that contains no symbolic links. SEE ALSO
cron(1), ls(1), rm(1), fuser(1) AUTHORS
Erik Troan <ewt@redhat.com> Preston Brown <pbrown@redhat.com> Nalin Dahyabhai <nalin@redhat.com> Miloslav Trmac <mitr@redhat.com> 4th Berkeley Distribution 2009-10-15 TMPWATCH(8)
All times are GMT -4. The time now is 06:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy