Find and delete folders within directory that are older than x days [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite













This question already has an answer here:



  • Delete sub-directories with YYYYMMDD in name older than N days

    4 answers



  • delete folders older than 1 day

    5 answers



Reopen voters: The 'already answered' question, is different. I am not looking to match the folder names, I want to look at the creation date time and use this to find the x days. I will be looking for folders older than 6 months, so unless I am mistaken, the 'already answered' is incorrect.




Inside a directory, I store date named folders of website backups.



/Users/myname/Desktop/rsync/


As an example:



/Users/myname/Desktop/rsync/10-06-18
/Users/myname/Desktop/rsync/11-06-18
/Users/myname/Desktop/rsync/12-06-18


In my bash script, I need to check to find any direct descendants of the 'rsync' folder that are older than x days and delete them.



Using the following, I am able to find files that are older than 2 days, but this is within the child folders as well.



find /Users/myname/Desktop/rsync -mtime +2 -print


If anyone can show me how I would limit this to just the direct descendant folder and potentially how to delete them, that would be much appreciated.







share|improve this question













marked as duplicate by Kusalananda bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jun 15 at 9:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • You first point out that you have folders with dates in their names, but you don't want to use these date? Also, the datestamp of creation is most likely not stored, unless that's what the folder name is.
    – Kusalananda
    Jun 15 at 9:15







  • 1




    I added another dupe. This looks at the modification time of folders, and at least one answer discusses -maxdepth and -mindepth, which is what you want to use, along with -prune.
    – Kusalananda
    Jun 15 at 9:32











  • See also a similar question: unix.stackexchange.com/questions/228216/… Note that you will want to add -maxdepth 1 to this, apart from taking my comment to the (currently only) answer there into account.
    – Kusalananda
    Jun 15 at 9:48






  • 1




    Are the modification timestamps of those date-stamped directories not in alignment with their filename-date?
    – Jeff Schaller
    Jun 15 at 11:01














up vote
1
down vote

favorite













This question already has an answer here:



  • Delete sub-directories with YYYYMMDD in name older than N days

    4 answers



  • delete folders older than 1 day

    5 answers



Reopen voters: The 'already answered' question, is different. I am not looking to match the folder names, I want to look at the creation date time and use this to find the x days. I will be looking for folders older than 6 months, so unless I am mistaken, the 'already answered' is incorrect.




Inside a directory, I store date named folders of website backups.



/Users/myname/Desktop/rsync/


As an example:



/Users/myname/Desktop/rsync/10-06-18
/Users/myname/Desktop/rsync/11-06-18
/Users/myname/Desktop/rsync/12-06-18


In my bash script, I need to check to find any direct descendants of the 'rsync' folder that are older than x days and delete them.



Using the following, I am able to find files that are older than 2 days, but this is within the child folders as well.



find /Users/myname/Desktop/rsync -mtime +2 -print


If anyone can show me how I would limit this to just the direct descendant folder and potentially how to delete them, that would be much appreciated.







share|improve this question













marked as duplicate by Kusalananda bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jun 15 at 9:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • You first point out that you have folders with dates in their names, but you don't want to use these date? Also, the datestamp of creation is most likely not stored, unless that's what the folder name is.
    – Kusalananda
    Jun 15 at 9:15







  • 1




    I added another dupe. This looks at the modification time of folders, and at least one answer discusses -maxdepth and -mindepth, which is what you want to use, along with -prune.
    – Kusalananda
    Jun 15 at 9:32











  • See also a similar question: unix.stackexchange.com/questions/228216/… Note that you will want to add -maxdepth 1 to this, apart from taking my comment to the (currently only) answer there into account.
    – Kusalananda
    Jun 15 at 9:48






  • 1




    Are the modification timestamps of those date-stamped directories not in alignment with their filename-date?
    – Jeff Schaller
    Jun 15 at 11:01












up vote
1
down vote

favorite









up vote
1
down vote

favorite












This question already has an answer here:



  • Delete sub-directories with YYYYMMDD in name older than N days

    4 answers



  • delete folders older than 1 day

    5 answers



Reopen voters: The 'already answered' question, is different. I am not looking to match the folder names, I want to look at the creation date time and use this to find the x days. I will be looking for folders older than 6 months, so unless I am mistaken, the 'already answered' is incorrect.




Inside a directory, I store date named folders of website backups.



/Users/myname/Desktop/rsync/


As an example:



/Users/myname/Desktop/rsync/10-06-18
/Users/myname/Desktop/rsync/11-06-18
/Users/myname/Desktop/rsync/12-06-18


In my bash script, I need to check to find any direct descendants of the 'rsync' folder that are older than x days and delete them.



Using the following, I am able to find files that are older than 2 days, but this is within the child folders as well.



find /Users/myname/Desktop/rsync -mtime +2 -print


If anyone can show me how I would limit this to just the direct descendant folder and potentially how to delete them, that would be much appreciated.







share|improve this question














This question already has an answer here:



  • Delete sub-directories with YYYYMMDD in name older than N days

    4 answers



  • delete folders older than 1 day

    5 answers



Reopen voters: The 'already answered' question, is different. I am not looking to match the folder names, I want to look at the creation date time and use this to find the x days. I will be looking for folders older than 6 months, so unless I am mistaken, the 'already answered' is incorrect.




Inside a directory, I store date named folders of website backups.



/Users/myname/Desktop/rsync/


As an example:



/Users/myname/Desktop/rsync/10-06-18
/Users/myname/Desktop/rsync/11-06-18
/Users/myname/Desktop/rsync/12-06-18


In my bash script, I need to check to find any direct descendants of the 'rsync' folder that are older than x days and delete them.



Using the following, I am able to find files that are older than 2 days, but this is within the child folders as well.



find /Users/myname/Desktop/rsync -mtime +2 -print


If anyone can show me how I would limit this to just the direct descendant folder and potentially how to delete them, that would be much appreciated.





This question already has an answer here:



  • Delete sub-directories with YYYYMMDD in name older than N days

    4 answers



  • delete folders older than 1 day

    5 answers









share|improve this question












share|improve this question




share|improve this question








edited Jun 15 at 9:29









peterh

3,91882755




3,91882755









asked Jun 15 at 9:00









ccdavies

1846




1846




marked as duplicate by Kusalananda bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jun 15 at 9:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Kusalananda bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jun 15 at 9:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • You first point out that you have folders with dates in their names, but you don't want to use these date? Also, the datestamp of creation is most likely not stored, unless that's what the folder name is.
    – Kusalananda
    Jun 15 at 9:15







  • 1




    I added another dupe. This looks at the modification time of folders, and at least one answer discusses -maxdepth and -mindepth, which is what you want to use, along with -prune.
    – Kusalananda
    Jun 15 at 9:32











  • See also a similar question: unix.stackexchange.com/questions/228216/… Note that you will want to add -maxdepth 1 to this, apart from taking my comment to the (currently only) answer there into account.
    – Kusalananda
    Jun 15 at 9:48






  • 1




    Are the modification timestamps of those date-stamped directories not in alignment with their filename-date?
    – Jeff Schaller
    Jun 15 at 11:01
















  • You first point out that you have folders with dates in their names, but you don't want to use these date? Also, the datestamp of creation is most likely not stored, unless that's what the folder name is.
    – Kusalananda
    Jun 15 at 9:15







  • 1




    I added another dupe. This looks at the modification time of folders, and at least one answer discusses -maxdepth and -mindepth, which is what you want to use, along with -prune.
    – Kusalananda
    Jun 15 at 9:32











  • See also a similar question: unix.stackexchange.com/questions/228216/… Note that you will want to add -maxdepth 1 to this, apart from taking my comment to the (currently only) answer there into account.
    – Kusalananda
    Jun 15 at 9:48






  • 1




    Are the modification timestamps of those date-stamped directories not in alignment with their filename-date?
    – Jeff Schaller
    Jun 15 at 11:01















You first point out that you have folders with dates in their names, but you don't want to use these date? Also, the datestamp of creation is most likely not stored, unless that's what the folder name is.
– Kusalananda
Jun 15 at 9:15





You first point out that you have folders with dates in their names, but you don't want to use these date? Also, the datestamp of creation is most likely not stored, unless that's what the folder name is.
– Kusalananda
Jun 15 at 9:15





1




1




I added another dupe. This looks at the modification time of folders, and at least one answer discusses -maxdepth and -mindepth, which is what you want to use, along with -prune.
– Kusalananda
Jun 15 at 9:32





I added another dupe. This looks at the modification time of folders, and at least one answer discusses -maxdepth and -mindepth, which is what you want to use, along with -prune.
– Kusalananda
Jun 15 at 9:32













See also a similar question: unix.stackexchange.com/questions/228216/… Note that you will want to add -maxdepth 1 to this, apart from taking my comment to the (currently only) answer there into account.
– Kusalananda
Jun 15 at 9:48




See also a similar question: unix.stackexchange.com/questions/228216/… Note that you will want to add -maxdepth 1 to this, apart from taking my comment to the (currently only) answer there into account.
– Kusalananda
Jun 15 at 9:48




1




1




Are the modification timestamps of those date-stamped directories not in alignment with their filename-date?
– Jeff Schaller
Jun 15 at 11:01




Are the modification timestamps of those date-stamped directories not in alignment with their filename-date?
– Jeff Schaller
Jun 15 at 11:01















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)