after compiling a file1.cpp, I get an executable file1.
My directory is filling up with lots of these executables and I don't need them.. is there any way I can mass delete them because I see no file extension?
eg to delete all text files we write rm *.txt, is there any similar method?
thanks.
Copyright © 2024 Q2A.ES - All rights reserved.
Answers & Comments
Verified answer
You're right - you can't mass delete in a trivial fashion. However, assuming you have one fileX for each fileX.cpp, something like the following loop (all one line) will delete them for you.
for F in * ; do file "$F" | grep -q ELF && test -f "$F.cpp" && rm -f "$F" ; done
I *strongly* suggest that the first time you run it, you prefix the "rm" with "echo" (i.e. "echo rm" instead of "rm") to show you the list of files that will be deleted...!
I see no reason for why you would have several executable files.
But you might have several object files which you can automatically remove at compile time by adding:
clean:
rm *.o
to the end of your makefile.
Note: Before the rm, it has to be a TAB; not spaces.