×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Calculate number of days between two days on sun solaris only

Calculate number of days between two days on sun solaris only

Calculate number of days between two days on sun solaris only

(OP)
Hello!

Must list "n" files from a given directory (exe: / export / home / test /), to recover part of the file names in a variable and then compare the variable with a specific date.

Eg

I have the file TEST-2012-09-18.LOG, just need to assign the value to a particular variable 09.18.2012 and subsequently compare this variable (date) with the current date, if the difference is more than 30 days, I delete the file.

I await return of you!!

hugs

RE: Calculate number of days between two days on sun solaris only

The find command I believe will do what you want. below is the command that I use to search for specific files that are older than 30 days and delete them. In my case I am only looking at files in the directory named backup and sub directories for files that start with the letters xln.

find /backup/* -name xln* -mtime +30 -exec rm -f {} \; >/dev/null 2>&1

RE: Calculate number of days between two days on sun solaris only

Tolson's solution assumes the last modification times of the files matches the dates in the filenames; if that is the case then it is the best way to go about it.

Otherwise you may find this ksh function useful for your date calculations.

Personally I usually use perl to do date calculations with the C-like POSIX functions, for example this will return the date 30 days ago:

CODE

perl -e 'use POSIX;($d,$m,$y)=(localtime time)[3..5];print strftime "%Y-%m-%d\n",localtime(mktime(0,0,0,$d-30,$m,$y));' 

If you choose to use that, I would extract the date from the filename without dashes and just do a numerical comparison, e.g. if (20120913 < 20120917) then delete it.

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

RE: Calculate number of days between two days on sun solaris only

(OP)
How to subtract 30 days to a given date?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close