Remove files with names matching a pattern in a directory and preserve the rest

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











up vote
0
down vote

favorite












I have a folder with files named MA1, MA2, .... MA-i (without extension and in total more than 110000) with other file and other subdirectory.



I wish to delete all MA-i file and preserve the other files and the subdirectory



I tried without success



a@LinuxA:~/CLionProjects/ETC1/cmake-build-debug$ rm -f MA*









share|improve this question























  • @slm they are more than 110000 files. Maybe is it a time issue?
    – Gianni Spear
    Aug 8 at 22:34










  • try this - find . -name "MA-*" -rm -f "" +
    – slm♦
    Aug 8 at 22:36











  • @slm yes, I have 1100000 file named MA1, MA2,..., MA1100000 with other file (e.g. T1, T2,...T100). I wish to delete only the MAx files. Thanks for your time.
    – Gianni Spear
    Aug 8 at 22:36










  • Ah, OK so do this - find . -name "MA*" -rm -f "" +
    – slm♦
    Aug 8 at 22:37










  • My sentiment as well. We're not getting the full picture here IMO.
    – slm♦
    Aug 8 at 22:40














up vote
0
down vote

favorite












I have a folder with files named MA1, MA2, .... MA-i (without extension and in total more than 110000) with other file and other subdirectory.



I wish to delete all MA-i file and preserve the other files and the subdirectory



I tried without success



a@LinuxA:~/CLionProjects/ETC1/cmake-build-debug$ rm -f MA*









share|improve this question























  • @slm they are more than 110000 files. Maybe is it a time issue?
    – Gianni Spear
    Aug 8 at 22:34










  • try this - find . -name "MA-*" -rm -f "" +
    – slm♦
    Aug 8 at 22:36











  • @slm yes, I have 1100000 file named MA1, MA2,..., MA1100000 with other file (e.g. T1, T2,...T100). I wish to delete only the MAx files. Thanks for your time.
    – Gianni Spear
    Aug 8 at 22:36










  • Ah, OK so do this - find . -name "MA*" -rm -f "" +
    – slm♦
    Aug 8 at 22:37










  • My sentiment as well. We're not getting the full picture here IMO.
    – slm♦
    Aug 8 at 22:40












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a folder with files named MA1, MA2, .... MA-i (without extension and in total more than 110000) with other file and other subdirectory.



I wish to delete all MA-i file and preserve the other files and the subdirectory



I tried without success



a@LinuxA:~/CLionProjects/ETC1/cmake-build-debug$ rm -f MA*









share|improve this question















I have a folder with files named MA1, MA2, .... MA-i (without extension and in total more than 110000) with other file and other subdirectory.



I wish to delete all MA-i file and preserve the other files and the subdirectory



I tried without success



a@LinuxA:~/CLionProjects/ETC1/cmake-build-debug$ rm -f MA*






linux files directory delete






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 8 at 22:34

























asked Aug 8 at 22:25









Gianni Spear

1054




1054











  • @slm they are more than 110000 files. Maybe is it a time issue?
    – Gianni Spear
    Aug 8 at 22:34










  • try this - find . -name "MA-*" -rm -f "" +
    – slm♦
    Aug 8 at 22:36











  • @slm yes, I have 1100000 file named MA1, MA2,..., MA1100000 with other file (e.g. T1, T2,...T100). I wish to delete only the MAx files. Thanks for your time.
    – Gianni Spear
    Aug 8 at 22:36










  • Ah, OK so do this - find . -name "MA*" -rm -f "" +
    – slm♦
    Aug 8 at 22:37










  • My sentiment as well. We're not getting the full picture here IMO.
    – slm♦
    Aug 8 at 22:40
















  • @slm they are more than 110000 files. Maybe is it a time issue?
    – Gianni Spear
    Aug 8 at 22:34










  • try this - find . -name "MA-*" -rm -f "" +
    – slm♦
    Aug 8 at 22:36











  • @slm yes, I have 1100000 file named MA1, MA2,..., MA1100000 with other file (e.g. T1, T2,...T100). I wish to delete only the MAx files. Thanks for your time.
    – Gianni Spear
    Aug 8 at 22:36










  • Ah, OK so do this - find . -name "MA*" -rm -f "" +
    – slm♦
    Aug 8 at 22:37










  • My sentiment as well. We're not getting the full picture here IMO.
    – slm♦
    Aug 8 at 22:40















@slm they are more than 110000 files. Maybe is it a time issue?
– Gianni Spear
Aug 8 at 22:34




@slm they are more than 110000 files. Maybe is it a time issue?
– Gianni Spear
Aug 8 at 22:34












try this - find . -name "MA-*" -rm -f "" +
– slm♦
Aug 8 at 22:36





try this - find . -name "MA-*" -rm -f "" +
– slm♦
Aug 8 at 22:36













@slm yes, I have 1100000 file named MA1, MA2,..., MA1100000 with other file (e.g. T1, T2,...T100). I wish to delete only the MAx files. Thanks for your time.
– Gianni Spear
Aug 8 at 22:36




@slm yes, I have 1100000 file named MA1, MA2,..., MA1100000 with other file (e.g. T1, T2,...T100). I wish to delete only the MAx files. Thanks for your time.
– Gianni Spear
Aug 8 at 22:36












Ah, OK so do this - find . -name "MA*" -rm -f "" +
– slm♦
Aug 8 at 22:37




Ah, OK so do this - find . -name "MA*" -rm -f "" +
– slm♦
Aug 8 at 22:37












My sentiment as well. We're not getting the full picture here IMO.
– slm♦
Aug 8 at 22:40




My sentiment as well. We're not getting the full picture here IMO.
– slm♦
Aug 8 at 22:40










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










find . -iname 'MA*' | while read L ; do echo rm "$L"; rm "$L"; done


For progress, if your storage volume is dying you may not be able to delete certain files the normal way and you'll see it stop and hang on a particular file at which point you can use timeout to skip the ones that don't work.






share|improve this answer




















  • I wrote alessandro@LinuxAle:~/CLionProjects/ETCS/cmake-build-debug$ find . -iname 'MA*' | while read L ; echo rm "$L"; rm "$L"; done and I got this Error message bash: errore di sintassi vicino al token non atteso "done" (in English syntax error close to token )
    – Gianni Spear
    Aug 8 at 22:57










  • it works thanks!
    – Gianni Spear
    Aug 8 at 23:08










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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461385%2fremove-files-with-names-matching-a-pattern-in-a-directory-and-preserve-the-rest%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










find . -iname 'MA*' | while read L ; do echo rm "$L"; rm "$L"; done


For progress, if your storage volume is dying you may not be able to delete certain files the normal way and you'll see it stop and hang on a particular file at which point you can use timeout to skip the ones that don't work.






share|improve this answer




















  • I wrote alessandro@LinuxAle:~/CLionProjects/ETCS/cmake-build-debug$ find . -iname 'MA*' | while read L ; echo rm "$L"; rm "$L"; done and I got this Error message bash: errore di sintassi vicino al token non atteso "done" (in English syntax error close to token )
    – Gianni Spear
    Aug 8 at 22:57










  • it works thanks!
    – Gianni Spear
    Aug 8 at 23:08














up vote
1
down vote



accepted










find . -iname 'MA*' | while read L ; do echo rm "$L"; rm "$L"; done


For progress, if your storage volume is dying you may not be able to delete certain files the normal way and you'll see it stop and hang on a particular file at which point you can use timeout to skip the ones that don't work.






share|improve this answer




















  • I wrote alessandro@LinuxAle:~/CLionProjects/ETCS/cmake-build-debug$ find . -iname 'MA*' | while read L ; echo rm "$L"; rm "$L"; done and I got this Error message bash: errore di sintassi vicino al token non atteso "done" (in English syntax error close to token )
    – Gianni Spear
    Aug 8 at 22:57










  • it works thanks!
    – Gianni Spear
    Aug 8 at 23:08












up vote
1
down vote



accepted







up vote
1
down vote



accepted






find . -iname 'MA*' | while read L ; do echo rm "$L"; rm "$L"; done


For progress, if your storage volume is dying you may not be able to delete certain files the normal way and you'll see it stop and hang on a particular file at which point you can use timeout to skip the ones that don't work.






share|improve this answer












find . -iname 'MA*' | while read L ; do echo rm "$L"; rm "$L"; done


For progress, if your storage volume is dying you may not be able to delete certain files the normal way and you'll see it stop and hang on a particular file at which point you can use timeout to skip the ones that don't work.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 8 at 22:48









user1133275

2,277412




2,277412











  • I wrote alessandro@LinuxAle:~/CLionProjects/ETCS/cmake-build-debug$ find . -iname 'MA*' | while read L ; echo rm "$L"; rm "$L"; done and I got this Error message bash: errore di sintassi vicino al token non atteso "done" (in English syntax error close to token )
    – Gianni Spear
    Aug 8 at 22:57










  • it works thanks!
    – Gianni Spear
    Aug 8 at 23:08
















  • I wrote alessandro@LinuxAle:~/CLionProjects/ETCS/cmake-build-debug$ find . -iname 'MA*' | while read L ; echo rm "$L"; rm "$L"; done and I got this Error message bash: errore di sintassi vicino al token non atteso "done" (in English syntax error close to token )
    – Gianni Spear
    Aug 8 at 22:57










  • it works thanks!
    – Gianni Spear
    Aug 8 at 23:08















I wrote alessandro@LinuxAle:~/CLionProjects/ETCS/cmake-build-debug$ find . -iname 'MA*' | while read L ; echo rm "$L"; rm "$L"; done and I got this Error message bash: errore di sintassi vicino al token non atteso "done" (in English syntax error close to token )
– Gianni Spear
Aug 8 at 22:57




I wrote alessandro@LinuxAle:~/CLionProjects/ETCS/cmake-build-debug$ find . -iname 'MA*' | while read L ; echo rm "$L"; rm "$L"; done and I got this Error message bash: errore di sintassi vicino al token non atteso "done" (in English syntax error close to token )
– Gianni Spear
Aug 8 at 22:57












it works thanks!
– Gianni Spear
Aug 8 at 23:08




it works thanks!
– Gianni Spear
Aug 8 at 23:08

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461385%2fremove-files-with-names-matching-a-pattern-in-a-directory-and-preserve-the-rest%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

The Forum (Inglewood, California)

Palaiologos