How do I not delete files in only the directory I am in?Cron job to delete files older than 3 daysDelete old...

The ring of global sections of a regular scheme

Why don't B747s start takeoffs with full throttle?

Is it OK to bring delicacies from hometown as tokens of gratitude for an out-of-town interview?

Does any lore text explain why the planes of Acheron, Gehenna, and Carceri are the alignment they are?

Is it a problem that pull requests are approved without any comments

Personalization conditions switching doesn`t work in Experience Editor (9.1.0, Initial Release)

Why does a helium balloon rise?

Pass variable to cat

What is a simple, physical situation where complex numbers emerge naturally?

Regarding eBGP Multipath

Is the decompression of compressed and encrypted data without decryption also theoretically impossible?

California: "For quality assurance, this phone call is being recorded"

How were concentration and extermination camp guards recruited?

Can a magnetic field of an object be stronger than its gravity?

How to pass a regex when finding a directory path in bash?

Accidentally cashed a check twice

3 as a Sum of 3 Pan Digital Expressions

Align text within align

Metal bar on DMM PCB

Do adult Russians normally hand-write Cyrillic as cursive or as block letters?

Responsibility for visa checking

The term for the person/group a political party aligns themselves with to appear concerned about the general public

Chopin: marche funèbre bar 15 impossible place

What does War Machine's "Canopy! Canopy!" line mean in "Avengers: Endgame"?



How do I not delete files in only the directory I am in?


Cron job to delete files older than 3 daysDelete old files but keep one each week/month/yearHow to delete the files in one folder which are more than 60 days old in UNIX?Delete files older than X days +Delete files older than 500 daysRemove old files in a directory but not the rootFind and rm command deleted the files inside the directory and the directory itselfError in deleting files or directories older than 1 dayDelete directories if they do not have newer filesHow to delete all directories in a directory older than 2 weeks except the latest one that match a file pattern?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I want to delete files older than 30 days in a directory, but not in directories below the one I am in.










share|improve this question









New contributor



Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    What do you mean by below? Are you talking about subdirectories or directories listed below when you list in a sorted-by-time order?

    – perennial_noob
    1 hour ago











  • I saw the "not delete" in the title after answering your question. Is it correct that you want to delete files in the current directory, but not in subdirectories?

    – Freddy
    51 mins ago


















0















I want to delete files older than 30 days in a directory, but not in directories below the one I am in.










share|improve this question









New contributor



Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    What do you mean by below? Are you talking about subdirectories or directories listed below when you list in a sorted-by-time order?

    – perennial_noob
    1 hour ago











  • I saw the "not delete" in the title after answering your question. Is it correct that you want to delete files in the current directory, but not in subdirectories?

    – Freddy
    51 mins ago














0












0








0


1






I want to delete files older than 30 days in a directory, but not in directories below the one I am in.










share|improve this question









New contributor



Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I want to delete files older than 30 days in a directory, but not in directories below the one I am in.







files date rm delete






share|improve this question









New contributor



Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited 46 mins ago









Jeff Schaller

46.2k1165150




46.2k1165150






New contributor



Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 1 hour ago









SamSam

1




1




New contributor



Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










  • 1





    What do you mean by below? Are you talking about subdirectories or directories listed below when you list in a sorted-by-time order?

    – perennial_noob
    1 hour ago











  • I saw the "not delete" in the title after answering your question. Is it correct that you want to delete files in the current directory, but not in subdirectories?

    – Freddy
    51 mins ago














  • 1





    What do you mean by below? Are you talking about subdirectories or directories listed below when you list in a sorted-by-time order?

    – perennial_noob
    1 hour ago











  • I saw the "not delete" in the title after answering your question. Is it correct that you want to delete files in the current directory, but not in subdirectories?

    – Freddy
    51 mins ago








1




1





What do you mean by below? Are you talking about subdirectories or directories listed below when you list in a sorted-by-time order?

– perennial_noob
1 hour ago





What do you mean by below? Are you talking about subdirectories or directories listed below when you list in a sorted-by-time order?

– perennial_noob
1 hour ago













I saw the "not delete" in the title after answering your question. Is it correct that you want to delete files in the current directory, but not in subdirectories?

– Freddy
51 mins ago





I saw the "not delete" in the title after answering your question. Is it correct that you want to delete files in the current directory, but not in subdirectories?

– Freddy
51 mins ago










1 Answer
1






active

oldest

votes


















0














To list the files before you delete them:



find . -maxdepth 1 -mtime +30 -type f -ls


To delete the files:



find . -maxdepth 1 -mtime +30 -type f -exec rm {} +


with





  • . specifying the current directory


  • -maxdepth 1 descend at most 1 level of directories


  • -mtime +30 only files last modified > 30 days


  • -type f only regular files






share|improve this answer
























  • Should it be +29 ? I think +0 is 1 day ago ?

    – dedowsdi
    15 mins ago












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Sam is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f522248%2fhow-do-i-not-delete-files-in-only-the-directory-i-am-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














To list the files before you delete them:



find . -maxdepth 1 -mtime +30 -type f -ls


To delete the files:



find . -maxdepth 1 -mtime +30 -type f -exec rm {} +


with





  • . specifying the current directory


  • -maxdepth 1 descend at most 1 level of directories


  • -mtime +30 only files last modified > 30 days


  • -type f only regular files






share|improve this answer
























  • Should it be +29 ? I think +0 is 1 day ago ?

    – dedowsdi
    15 mins ago
















0














To list the files before you delete them:



find . -maxdepth 1 -mtime +30 -type f -ls


To delete the files:



find . -maxdepth 1 -mtime +30 -type f -exec rm {} +


with





  • . specifying the current directory


  • -maxdepth 1 descend at most 1 level of directories


  • -mtime +30 only files last modified > 30 days


  • -type f only regular files






share|improve this answer
























  • Should it be +29 ? I think +0 is 1 day ago ?

    – dedowsdi
    15 mins ago














0












0








0







To list the files before you delete them:



find . -maxdepth 1 -mtime +30 -type f -ls


To delete the files:



find . -maxdepth 1 -mtime +30 -type f -exec rm {} +


with





  • . specifying the current directory


  • -maxdepth 1 descend at most 1 level of directories


  • -mtime +30 only files last modified > 30 days


  • -type f only regular files






share|improve this answer













To list the files before you delete them:



find . -maxdepth 1 -mtime +30 -type f -ls


To delete the files:



find . -maxdepth 1 -mtime +30 -type f -exec rm {} +


with





  • . specifying the current directory


  • -maxdepth 1 descend at most 1 level of directories


  • -mtime +30 only files last modified > 30 days


  • -type f only regular files







share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









FreddyFreddy

3,9331417




3,9331417













  • Should it be +29 ? I think +0 is 1 day ago ?

    – dedowsdi
    15 mins ago



















  • Should it be +29 ? I think +0 is 1 day ago ?

    – dedowsdi
    15 mins ago

















Should it be +29 ? I think +0 is 1 day ago ?

– dedowsdi
15 mins ago





Should it be +29 ? I think +0 is 1 day ago ?

– dedowsdi
15 mins ago










Sam is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Sam is a new contributor. Be nice, and check out our Code of Conduct.













Sam is a new contributor. Be nice, and check out our Code of Conduct.












Sam is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f522248%2fhow-do-i-not-delete-files-in-only-the-directory-i-am-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...