Visit The New, Modern Unix Linux Community

Deleting the files based on the date's

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting the files based on the date's
# 1  
Deleting the files based on the date's

I have to write one script which will delete the files in the below passion.

If today is 17-Feb-2010 then the script delete only 17-JAN-2010 files from the directory.

Could you please help me, How will I delete the files when the year is leap year, if today is 30th Mar 2010 then how will handle such scenarios.

I have written simple script for getting the yesterday's date but I do not understand how to develop this script.

bash-3.00$ cat
 v_todaysdate=`date +%d`
v_yesterday=$((`date +%e` -1))
v_month=`date +%m`
v_year=`date +%Y`

if [ $v_yesterday -eq "0" ]
    if [ $v_month -eq "0" ]
  set `cal $v_month $v_year`
  shift $(($# - 1))
echo "Previous Date : - " $v_yesterday-$v_month-$v_year
echo "TodaysDate : - " $v_todaysdate-$v_month-$v_year

bash-3.00$ ./
Previous Date : - 16-02-2010

TodaysDate : - 17-02-2010

Last edited by vbe; 02-17-2010 at 06:44 AM.. Reason: code tags please
# 2  
Is this date part of the filename, and in exactly the same format you listed? Or is this the file's date stamp that you are referring to here?

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #729
Difficulty: Medium
BASIC stands for Basic All-purpose Symbolic Instruction Code.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt 2012-06-15 08:13" ! -newermt 2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

2. Shell Programming and Scripting

Deleting lines based on a condition for a group of files

hi i have a set of similar files. i want to delete lines until certain pattern appears in those files. for a single file the following command can be used but i want to do it for all the files at a time since the number is in thousands. awk '/PATTERN/{i++}i' file (6 Replies)
Discussion started by: anurupa777
6 Replies

3. UNIX for Dummies Questions & Answers

Deleting files based on Substring match

In folder there are files (eg ABS_18APR2012_XYZ.csv DSE_17APR2012_ABE.csv) . My requirement is to delete all the files except today's timestamp I tried doing this to list all the files not having today's date timestamp #!/bin/ksh DATE=`date +"%d%h%Y"` DIR=/data/rfs/... (9 Replies)
Discussion started by: manushi88
9 Replies

4. UNIX for Dummies Questions & Answers

deleting files based on the suffix

how do we delete files based on the suffix??? (1 Reply)
Discussion started by: saggiboy10
1 Replies

5. Shell Programming and Scripting

Deleting files based on their size

I have several files in a folder and I would like to delete the ones that do not contain all the required information (size) let say 1kb. Any ideas? (4 Replies)
Discussion started by: Xterra
4 Replies

6. UNIX for Dummies Questions & Answers

deleting files based on file name and modified time

Hi, I have some log files created in the following fashion Ex: file name modified date 1) s.log1 01-jan-08 2) s.log2 02-jan-08 3) s.log3 03-jan-08 4) s.log4 04-jan-08 Now I want to have the latest 2 logs and delete the others. Can you tell me the one liner /... (1 Reply)
Discussion started by: ammu
1 Replies

7. Shell Programming and Scripting

command for deleting log files based on some condition

Hello, Can anyone pls. provide me with the command for deleting files older then 15 days with a restriction to keep at least 5 files in a directory even if they are older then 15 days. Any help will be highly appreciated. Thanks, Pulkit (4 Replies)
Discussion started by: pulkit
4 Replies

8. Shell Programming and Scripting

Traversing thru dirs and deleting files based on date

Hi Folks I am pretty new to unix and shellscripting. I need help on writing logic on traversing recursively through a set of directories under a top-level folder and delete files(mostly text) which are 1 month old. Can you people help me on this? Thanks a lot Ravi (5 Replies)
Discussion started by: ravi2082
5 Replies

9. Programming

deleting files on particular date

Hello, In unix what is the command to delete files created on a particular date. for example: I have a list of files in a directory Nov 8 08:30 abc Nov 8 17:00 xyz Nov 9 12:30 test Nov 9 14:45 test2 Nov 9 18:15 quick Nov 10 07:20 quick2 Nov 11 19:00 quick3 Now i would like to delete... (1 Reply)
Discussion started by: jazz
1 Replies

10. Shell Programming and Scripting

Deleting files older than a given date

Hi all, I want to delete all files in a directory which are older than a given date. I thought of doing it by creating a file by the required date by using touch command. And then i would use find command on that file and try to find files older than that. I searched the man and found a... (3 Replies)
Discussion started by: rajugp1
3 Replies

Featured Tech Videos