What are the differences between rm and '-delete' in find? [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • find - exec rm vs -delete

    3 answers




We want to delete the files under /tmp that are older than 100 minutes.



What is the difference between:



find /tmp -type f -mmin +100 -exec rm {} ;


and:



find /tmp -type f -mmin +100 -exec -delete 


second - Is it possible to add some print / echo in the command so that it will print each file it deletes?



/tmp/hadoop-unjar7118762490947462979/META-INF/NOTICE was deleted !!!









share|improve this question















marked as duplicate by JdeBP, RalfFriedl, Christopher, Anthony Geoghegan, Rui F Ribeiro yesterday


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.











  • 2




    What's a "safe deletion"?
    – Jeff Schaller
    yesterday










  • since we are working on production machine , then I want to understand what the approach that is more safe , second how to add some safe rule that the command will deleted the files only under /tmp
    – yael
    yesterday








  • 1




    @yael that does not clarify user Jeff Schaller's question. Please edit your post to elaborate what exactly a "safe deletion" would be.
    – kemotep
    yesterday










  • I edit my question , hope it is clearly now
    – yael
    yesterday










  • If you're not sure what's going to be deleted, perhaps a "print-only" report would be a good start, followed by an "archive" or "move" action, then later followed by a remove action.
    – Jeff Schaller
    yesterday















up vote
0
down vote

favorite













This question already has an answer here:




  • find - exec rm vs -delete

    3 answers




We want to delete the files under /tmp that are older than 100 minutes.



What is the difference between:



find /tmp -type f -mmin +100 -exec rm {} ;


and:



find /tmp -type f -mmin +100 -exec -delete 


second - Is it possible to add some print / echo in the command so that it will print each file it deletes?



/tmp/hadoop-unjar7118762490947462979/META-INF/NOTICE was deleted !!!









share|improve this question















marked as duplicate by JdeBP, RalfFriedl, Christopher, Anthony Geoghegan, Rui F Ribeiro yesterday


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.











  • 2




    What's a "safe deletion"?
    – Jeff Schaller
    yesterday










  • since we are working on production machine , then I want to understand what the approach that is more safe , second how to add some safe rule that the command will deleted the files only under /tmp
    – yael
    yesterday








  • 1




    @yael that does not clarify user Jeff Schaller's question. Please edit your post to elaborate what exactly a "safe deletion" would be.
    – kemotep
    yesterday










  • I edit my question , hope it is clearly now
    – yael
    yesterday










  • If you're not sure what's going to be deleted, perhaps a "print-only" report would be a good start, followed by an "archive" or "move" action, then later followed by a remove action.
    – Jeff Schaller
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • find - exec rm vs -delete

    3 answers




We want to delete the files under /tmp that are older than 100 minutes.



What is the difference between:



find /tmp -type f -mmin +100 -exec rm {} ;


and:



find /tmp -type f -mmin +100 -exec -delete 


second - Is it possible to add some print / echo in the command so that it will print each file it deletes?



/tmp/hadoop-unjar7118762490947462979/META-INF/NOTICE was deleted !!!









share|improve this question
















This question already has an answer here:




  • find - exec rm vs -delete

    3 answers




We want to delete the files under /tmp that are older than 100 minutes.



What is the difference between:



find /tmp -type f -mmin +100 -exec rm {} ;


and:



find /tmp -type f -mmin +100 -exec -delete 


second - Is it possible to add some print / echo in the command so that it will print each file it deletes?



/tmp/hadoop-unjar7118762490947462979/META-INF/NOTICE was deleted !!!




This question already has an answer here:




  • find - exec rm vs -delete

    3 answers








shell-script find rm delete






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









terdon

127k31246423




127k31246423










asked yesterday









yael

2,38011958




2,38011958




marked as duplicate by JdeBP, RalfFriedl, Christopher, Anthony Geoghegan, Rui F Ribeiro yesterday


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 JdeBP, RalfFriedl, Christopher, Anthony Geoghegan, Rui F Ribeiro yesterday


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.










  • 2




    What's a "safe deletion"?
    – Jeff Schaller
    yesterday










  • since we are working on production machine , then I want to understand what the approach that is more safe , second how to add some safe rule that the command will deleted the files only under /tmp
    – yael
    yesterday








  • 1




    @yael that does not clarify user Jeff Schaller's question. Please edit your post to elaborate what exactly a "safe deletion" would be.
    – kemotep
    yesterday










  • I edit my question , hope it is clearly now
    – yael
    yesterday










  • If you're not sure what's going to be deleted, perhaps a "print-only" report would be a good start, followed by an "archive" or "move" action, then later followed by a remove action.
    – Jeff Schaller
    yesterday














  • 2




    What's a "safe deletion"?
    – Jeff Schaller
    yesterday










  • since we are working on production machine , then I want to understand what the approach that is more safe , second how to add some safe rule that the command will deleted the files only under /tmp
    – yael
    yesterday








  • 1




    @yael that does not clarify user Jeff Schaller's question. Please edit your post to elaborate what exactly a "safe deletion" would be.
    – kemotep
    yesterday










  • I edit my question , hope it is clearly now
    – yael
    yesterday










  • If you're not sure what's going to be deleted, perhaps a "print-only" report would be a good start, followed by an "archive" or "move" action, then later followed by a remove action.
    – Jeff Schaller
    yesterday








2




2




What's a "safe deletion"?
– Jeff Schaller
yesterday




What's a "safe deletion"?
– Jeff Schaller
yesterday












since we are working on production machine , then I want to understand what the approach that is more safe , second how to add some safe rule that the command will deleted the files only under /tmp
– yael
yesterday






since we are working on production machine , then I want to understand what the approach that is more safe , second how to add some safe rule that the command will deleted the files only under /tmp
– yael
yesterday






1




1




@yael that does not clarify user Jeff Schaller's question. Please edit your post to elaborate what exactly a "safe deletion" would be.
– kemotep
yesterday




@yael that does not clarify user Jeff Schaller's question. Please edit your post to elaborate what exactly a "safe deletion" would be.
– kemotep
yesterday












I edit my question , hope it is clearly now
– yael
yesterday




I edit my question , hope it is clearly now
– yael
yesterday












If you're not sure what's going to be deleted, perhaps a "print-only" report would be a good start, followed by an "archive" or "move" action, then later followed by a remove action.
– Jeff Schaller
yesterday




If you're not sure what's going to be deleted, perhaps a "print-only" report would be a good start, followed by an "archive" or "move" action, then later followed by a remove action.
– Jeff Schaller
yesterday










1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










Two alternatives come to mind for printing the file as it's being removed:



find /tmp -type f -mmin +100 -printf '%p was deleted!!n' -delete


or



find /tmp -type f -mmin +100 -exec rm -v {} ;


The former instructs GNU find to print the file name (fully-pathed) before deleting it; the latter tells find to execute rm -v on each filename, where -v instructs (GNU) rm to be verbose about what it's doing.



Output of the former would be like:



/tmp/.sh_history.6668 was deleted!!
/tmp/krb5cc_6094 was deleted!!
/tmp/.sh_history.18394 was deleted!!


While the output of the latter would be:



removed ‘/tmp/.sh_history.6668’
removed ‘/tmp/krb5cc_6094’
removed ‘/tmp/.sh_history.18394’


Another item to note on -exec rm {} vs -delete is that -exec rm will search your $PATH for rm while -delete directly unlinks the file. Not usually an issue, but something to be aware of.



Example:



$ pwd
/tmp/jeff
$ ls
bar foo rm
$ cat rm
#!/bin/sh
echo Hi, I am the fake rm: "$@"
$ PATH=/tmp/jeff:$PATH
$ find . -type f -exec rm {} ;
Hi, I am the fake rm: ./rm
Hi, I am the fake rm: ./bar
Hi, I am the fake rm: ./foo


With -delete, find will also traverse the search path in a depth-first manner by default. This allows it to delete directories that it will not later try to enter. You would have to use find with -depth if you use -exec rm -rf {} on directories, or you will cause find to complain about not finding the directories that it thought were there.






share|improve this answer



















  • 1




    Maybe worth adding -xdev just in case someone does something silly like mount --bind / /tmp/foobar
    – Stephen Harris
    yesterday










  • yes this is very good point , in case some user run - find / -type , insted of find /tmp -type , then how to avoid thsi such case , can we add in the cli some additional syntax that will avoid other partitions as "/"
    – yael
    yesterday












  • obviously running find / ... -delete is less "safe" than running find /tmp ... -delete; I'm not sure how to address the "safeness" here.
    – Jeff Schaller
    yesterday


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










Two alternatives come to mind for printing the file as it's being removed:



find /tmp -type f -mmin +100 -printf '%p was deleted!!n' -delete


or



find /tmp -type f -mmin +100 -exec rm -v {} ;


The former instructs GNU find to print the file name (fully-pathed) before deleting it; the latter tells find to execute rm -v on each filename, where -v instructs (GNU) rm to be verbose about what it's doing.



Output of the former would be like:



/tmp/.sh_history.6668 was deleted!!
/tmp/krb5cc_6094 was deleted!!
/tmp/.sh_history.18394 was deleted!!


While the output of the latter would be:



removed ‘/tmp/.sh_history.6668’
removed ‘/tmp/krb5cc_6094’
removed ‘/tmp/.sh_history.18394’


Another item to note on -exec rm {} vs -delete is that -exec rm will search your $PATH for rm while -delete directly unlinks the file. Not usually an issue, but something to be aware of.



Example:



$ pwd
/tmp/jeff
$ ls
bar foo rm
$ cat rm
#!/bin/sh
echo Hi, I am the fake rm: "$@"
$ PATH=/tmp/jeff:$PATH
$ find . -type f -exec rm {} ;
Hi, I am the fake rm: ./rm
Hi, I am the fake rm: ./bar
Hi, I am the fake rm: ./foo


With -delete, find will also traverse the search path in a depth-first manner by default. This allows it to delete directories that it will not later try to enter. You would have to use find with -depth if you use -exec rm -rf {} on directories, or you will cause find to complain about not finding the directories that it thought were there.






share|improve this answer



















  • 1




    Maybe worth adding -xdev just in case someone does something silly like mount --bind / /tmp/foobar
    – Stephen Harris
    yesterday










  • yes this is very good point , in case some user run - find / -type , insted of find /tmp -type , then how to avoid thsi such case , can we add in the cli some additional syntax that will avoid other partitions as "/"
    – yael
    yesterday












  • obviously running find / ... -delete is less "safe" than running find /tmp ... -delete; I'm not sure how to address the "safeness" here.
    – Jeff Schaller
    yesterday















up vote
4
down vote



accepted










Two alternatives come to mind for printing the file as it's being removed:



find /tmp -type f -mmin +100 -printf '%p was deleted!!n' -delete


or



find /tmp -type f -mmin +100 -exec rm -v {} ;


The former instructs GNU find to print the file name (fully-pathed) before deleting it; the latter tells find to execute rm -v on each filename, where -v instructs (GNU) rm to be verbose about what it's doing.



Output of the former would be like:



/tmp/.sh_history.6668 was deleted!!
/tmp/krb5cc_6094 was deleted!!
/tmp/.sh_history.18394 was deleted!!


While the output of the latter would be:



removed ‘/tmp/.sh_history.6668’
removed ‘/tmp/krb5cc_6094’
removed ‘/tmp/.sh_history.18394’


Another item to note on -exec rm {} vs -delete is that -exec rm will search your $PATH for rm while -delete directly unlinks the file. Not usually an issue, but something to be aware of.



Example:



$ pwd
/tmp/jeff
$ ls
bar foo rm
$ cat rm
#!/bin/sh
echo Hi, I am the fake rm: "$@"
$ PATH=/tmp/jeff:$PATH
$ find . -type f -exec rm {} ;
Hi, I am the fake rm: ./rm
Hi, I am the fake rm: ./bar
Hi, I am the fake rm: ./foo


With -delete, find will also traverse the search path in a depth-first manner by default. This allows it to delete directories that it will not later try to enter. You would have to use find with -depth if you use -exec rm -rf {} on directories, or you will cause find to complain about not finding the directories that it thought were there.






share|improve this answer



















  • 1




    Maybe worth adding -xdev just in case someone does something silly like mount --bind / /tmp/foobar
    – Stephen Harris
    yesterday










  • yes this is very good point , in case some user run - find / -type , insted of find /tmp -type , then how to avoid thsi such case , can we add in the cli some additional syntax that will avoid other partitions as "/"
    – yael
    yesterday












  • obviously running find / ... -delete is less "safe" than running find /tmp ... -delete; I'm not sure how to address the "safeness" here.
    – Jeff Schaller
    yesterday













up vote
4
down vote



accepted







up vote
4
down vote



accepted






Two alternatives come to mind for printing the file as it's being removed:



find /tmp -type f -mmin +100 -printf '%p was deleted!!n' -delete


or



find /tmp -type f -mmin +100 -exec rm -v {} ;


The former instructs GNU find to print the file name (fully-pathed) before deleting it; the latter tells find to execute rm -v on each filename, where -v instructs (GNU) rm to be verbose about what it's doing.



Output of the former would be like:



/tmp/.sh_history.6668 was deleted!!
/tmp/krb5cc_6094 was deleted!!
/tmp/.sh_history.18394 was deleted!!


While the output of the latter would be:



removed ‘/tmp/.sh_history.6668’
removed ‘/tmp/krb5cc_6094’
removed ‘/tmp/.sh_history.18394’


Another item to note on -exec rm {} vs -delete is that -exec rm will search your $PATH for rm while -delete directly unlinks the file. Not usually an issue, but something to be aware of.



Example:



$ pwd
/tmp/jeff
$ ls
bar foo rm
$ cat rm
#!/bin/sh
echo Hi, I am the fake rm: "$@"
$ PATH=/tmp/jeff:$PATH
$ find . -type f -exec rm {} ;
Hi, I am the fake rm: ./rm
Hi, I am the fake rm: ./bar
Hi, I am the fake rm: ./foo


With -delete, find will also traverse the search path in a depth-first manner by default. This allows it to delete directories that it will not later try to enter. You would have to use find with -depth if you use -exec rm -rf {} on directories, or you will cause find to complain about not finding the directories that it thought were there.






share|improve this answer














Two alternatives come to mind for printing the file as it's being removed:



find /tmp -type f -mmin +100 -printf '%p was deleted!!n' -delete


or



find /tmp -type f -mmin +100 -exec rm -v {} ;


The former instructs GNU find to print the file name (fully-pathed) before deleting it; the latter tells find to execute rm -v on each filename, where -v instructs (GNU) rm to be verbose about what it's doing.



Output of the former would be like:



/tmp/.sh_history.6668 was deleted!!
/tmp/krb5cc_6094 was deleted!!
/tmp/.sh_history.18394 was deleted!!


While the output of the latter would be:



removed ‘/tmp/.sh_history.6668’
removed ‘/tmp/krb5cc_6094’
removed ‘/tmp/.sh_history.18394’


Another item to note on -exec rm {} vs -delete is that -exec rm will search your $PATH for rm while -delete directly unlinks the file. Not usually an issue, but something to be aware of.



Example:



$ pwd
/tmp/jeff
$ ls
bar foo rm
$ cat rm
#!/bin/sh
echo Hi, I am the fake rm: "$@"
$ PATH=/tmp/jeff:$PATH
$ find . -type f -exec rm {} ;
Hi, I am the fake rm: ./rm
Hi, I am the fake rm: ./bar
Hi, I am the fake rm: ./foo


With -delete, find will also traverse the search path in a depth-first manner by default. This allows it to delete directories that it will not later try to enter. You would have to use find with -depth if you use -exec rm -rf {} on directories, or you will cause find to complain about not finding the directories that it thought were there.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday









Kusalananda

120k16225370




120k16225370










answered yesterday









Jeff Schaller

38.1k1053124




38.1k1053124








  • 1




    Maybe worth adding -xdev just in case someone does something silly like mount --bind / /tmp/foobar
    – Stephen Harris
    yesterday










  • yes this is very good point , in case some user run - find / -type , insted of find /tmp -type , then how to avoid thsi such case , can we add in the cli some additional syntax that will avoid other partitions as "/"
    – yael
    yesterday












  • obviously running find / ... -delete is less "safe" than running find /tmp ... -delete; I'm not sure how to address the "safeness" here.
    – Jeff Schaller
    yesterday














  • 1




    Maybe worth adding -xdev just in case someone does something silly like mount --bind / /tmp/foobar
    – Stephen Harris
    yesterday










  • yes this is very good point , in case some user run - find / -type , insted of find /tmp -type , then how to avoid thsi such case , can we add in the cli some additional syntax that will avoid other partitions as "/"
    – yael
    yesterday












  • obviously running find / ... -delete is less "safe" than running find /tmp ... -delete; I'm not sure how to address the "safeness" here.
    – Jeff Schaller
    yesterday








1




1




Maybe worth adding -xdev just in case someone does something silly like mount --bind / /tmp/foobar
– Stephen Harris
yesterday




Maybe worth adding -xdev just in case someone does something silly like mount --bind / /tmp/foobar
– Stephen Harris
yesterday












yes this is very good point , in case some user run - find / -type , insted of find /tmp -type , then how to avoid thsi such case , can we add in the cli some additional syntax that will avoid other partitions as "/"
– yael
yesterday






yes this is very good point , in case some user run - find / -type , insted of find /tmp -type , then how to avoid thsi such case , can we add in the cli some additional syntax that will avoid other partitions as "/"
– yael
yesterday














obviously running find / ... -delete is less "safe" than running find /tmp ... -delete; I'm not sure how to address the "safeness" here.
– Jeff Schaller
yesterday




obviously running find / ... -delete is less "safe" than running find /tmp ... -delete; I'm not sure how to address the "safeness" here.
– Jeff Schaller
yesterday



Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt