0

I can use the following command to delete child directories in a particular directory older than x number of days

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

but how would I delete child directories that were older than the date when another dirctory was created? I know I can get the date using

$ ls -l /var/www/cfs-web/current
lrwxrwxrwx 1 myuser mygroup 41 Feb 22 23:19 /path/to/main/dir

but I’m not sure how to combine this with the above.

1
  • 1
    ctime is not creation time. It's inode change time, i.e. the time that attributes or metadata were changed for the file/directory Feb 23, 2022 at 7:42

1 Answer 1

1

how would I delete child directories that were older than the date when another dirctory was created?

There is unlikely to be a created date or birth date attribute for files/directories.

If the last modified time will suffice, you can simply change ctime +10 to ! -newer reference where 'reference' is the directory whose modification time you want to use as a reference.

If your system does store birth date file attributes, you could use ! -newerBB reference.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .