Issue
I was given a Makefile for an assignment that gives me a make clean command. With the way the repository is set up, it deletes everything in the /bin and /out folders, except for a file called .gitignore. This is what the command looks like:
clean:
find out/ ! -name .gitignore -type f -delete && \
find bin/ ! -name .gitignore -type f -delete
Now that I'm doing my project, I need to store things in a folder called /bin/fonts and /bin/word_lists. I'm trying to modify the command so that it ignores these two files. The only problem is, I don't know what language these commands are written in, so I don't even know where to start looking at the syntax. Could somebody point me in the right direction? I tried something like this:
clean:
find out/ ! -name .gitignore -type f -delete && \
find bin/ ! -name .gitignore ! -name fonts/FreeSans.ttf -type f -delete
But it still deletes everything in fonts, and even if it did work the way I wanted, that doesn't really solve the problem of saving every single font in the folder.
I also tried this:
clean:
find out/ ! -name .gitignore -type f -delete && \
find ./bin -mindepth 1 ! -name .gitignore ! -regex '^./fonts/\(/.*\)?' ! -regex '^./word_lists/\(/.*\)?' -delete
following this post, but it instead deleted everything INCLUDING the folders bin/fonts as well as bin/word_lists.
Any help would be greatly appreciated!
Solution
-name
does not examine the full file path, it only matches against the file name (so -name FreeSans.ttf
would match, but match this file name in any directory).
The predicate you are looking for is called -path
but then you need to specify a pattern for the entire path.
clean:
find out/ bin/ ! -name .gitignore ! -path 'bin/fonts/*
! -path 'bin/word_lists/*' -type f -delete
(Notice also how I condensed the find
to traverse two directories at the same time. I assume you mean bin
not /bin
; perhaps see also Difference between ./
and ~/
)
Answered By - tripleee