‘make clean’ using find

Using ‘find’ utility you can easily define ‘make clean’ in similar way to this:

clean:
     find -type f \( -iname "*.a" -or \
          -iname "*.p_hi" -or \
          -iname "*.hi" -or \
          -iname "*.o" -or \
          -iname "*.p_o" -or \
          -iname "*.o_p" -or \
          -iname "*.pyc" -or \
          -iname "*~" \) -delete

It will recursively delete all files with given extensions. I can’t think of any other way to do the same think so easily and in so generic way.

Advertisements

~ by Tener on 07/08/2009.

2 Responses to “‘make clean’ using find”

  1. If you use Bazaar or git, you can also type “bzr clean-tree” or “git clean” to remove unwanted/untracked files.

  2. I presume in many cases those commands might do the job – and it’s good to know! However, there is at least one case when they doesn’t do the job.

    I’m currently working on this project:
    http://code.google.com/p/ii-project-x/source/browse/

    It’s written in Python. As you must know it’s interpreter creates *.pyc files when running programs. These are ignored by git. But there is also a file called “index.yaml”. It is created by the server and stores some important data, which we don’t want to delete, but rather use in other way. But since it changes so often, it would be nuisance (and would create a lot of noise) to include changes in this file in version control system. So it’s ignored*.

    Now, we often want to delete *.pyc files, but retain index.yaml. There is no way git or Bazaar would tell the difference: both are ignored, and will be deleted by “bzr clean-tree –ignored” or equivalent “git clean -X”. They will simply delete too much.

    (* It’s not really true, as we do track it 🙂 but it might have been)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: