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!

*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.

Jobs

basing on dir names, find those "older" than 10 days

basing on dir names, find those "older" than 10 days

basing on dir names, find those "older" than 10 days

(OP)

hi,
I have many of dirs named like in example:
31DEC15
01JAN16
...
09JAN16
...

and want to delete those whose name is older than 10 days

I have no gnu sort on a system (no -M), is there any possibility to get reliable solution in such case?

RE: basing on dir names, find those "older" than 10 days

Using find with -exec should work

find /path/to/parent/directory/* -type d -ctime +10 -exec rm -rf {} \;




Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: basing on dir names, find those "older" than 10 days

That's not actually deleting based on the "name". That's deleting based on the actual creation date of the directory. While that may be what the OP needs, it's not what he asked for. There may be a requirement for deleting based on the date in the name, and not actual creation date.

RE: basing on dir names, find those "older" than 10 days

Hi

Given the lack of GNU find, I assume GNU Awk is also on short supply. So I would go with a standard Awk script which filters its input using its parameter :

CODE --> name_date_older_than.awk

BEGIN {
    split("JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC", m)
    for (i in m)
        m[m[i]] = i

    ARGC = 0
}

sprintf("%02d%02d%02d", substr($0, 6, 2), m[substr($0, 3, 3)], substr($0, 1, 2)) < ARGV[1] 

Which should be executed as :

CODE --> command line

master # ls -1 | awk -f name_date_older_than.awk 160118 

The output being the list of filenames older than what was specified as parameter.

Feherke.
feherke.ga

RE: basing on dir names, find those "older" than 10 days

And of course the OP is welcome to modify the command line to suit his or her needs .... Thus learning a bit more about shell scripting than being spoon fed an instant solution, it simply needs the addition of a -regex predicate with a fairly simple regular expression.


such as

[0-9]{2}[A-Z]{2}[0-9]{2}

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

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!

Resources

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