Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3988792
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:17:41+00:00 2026-05-20T06:17:41+00:00

For small C/C++ projects I am used to write my clean target as follow:

  • 0

For small C/C++ projects I am used to write my clean target as follow:

clean:
    $(RM) *.o *~

For slightly bigger projects, when sources are dispatched in subdirectories, say src1 and src2, I would write

clean:
    $(RM) src1/*.o src1/*~ src2/*.o src2/*~

With even more subdirectories, it quickly becomes messy… So I realized I could use the find command like this:

clean:
    find . -name "*.o" -exec $(RM) {} \;
    find . -name "*~"  -exec $(RM) {} \;

However I saw that people often use find in conjunction with xargs instead of using -exec and I wonder why since it seems to work fine…

What do you use and why?

I know that for big projects, or for better compatibility, I should probably use cmake or autotools but I like the simplicity of a Makefile for small projects.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:17:41+00:00Added an answer on May 20, 2026 at 6:17 am

    Because exec creates one sub-process per file being deleted. xargs, on the other hand, batches them up.

    It’s effectively the difference between:

    rm src1/a.o
    rm src1/b.o
    rm src2/c.o
    

    and:

    rm src1/a.o src1/b.o src2/c.o
    

    It’s probably not going to matter that much unless you have a lot of files but it’s worth knowing for that use case.

    But I don’t use either of those methods. I make each directory responsible for building itself (and it’s subordinate directories), by having a Makefile in there. Then, from the top level make, I have something like:

    all:
        for i in module1 module2 \
        do \
            cd $i \
            $(MAKE) all \
            cd .. \
        done
    

    Same deal for the clean target. I don’t assume that cleaning is the same action for every single subdirectory.

    By doing that, the relevant actions are localised. If I have a directory where .o files are actually third party objects for me to link with (so I don’t have the source), I make sure that clean won’t delete them in that relevant makefile. The solution you have would hose them, causing much angst and gnashing of teeth 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been quite used to working on small projects which I coded with 1,000
I want to start using Python for small projects but the fact that a
Im just writing a small Ajax framework for re-usability in small projects and i've
Git's tab autocompletion is useful for small projects, but I'm currently working on two
i'm not a full RoR developer (php developer mostly), i've only don't small projects/tutorials,
I have MANY small Test Projects where I put together just enough code to
I've been making small scale projects for a while now. I haven't started a
I typically work on small-sized projects that involve only 2-3 people working on the
I have several small open-source projects that I wrote. All my attempts to find
I recently started using scons to build several small cross-platform projects. One of these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.