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

Clash 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*
linux files directory delete
 |Â
show 6 more comments
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*
linux files directory delete
@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
 |Â
show 6 more comments
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*
linux files directory delete
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
linux files directory delete
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
 |Â
show 6 more comments
@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
 |Â
show 6 more comments
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
@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