4 ms·
Not sure if anyone actually uses it, but I would approach the problem with find, comm, and a sprinkle of sed: comm -23 <(find build -type f -iname "*.html"
by mftrhu 3y ago
Not sure if anyone actually uses it, but I would approach the problem with find, comm, and a sprinkle of sed:
comm -23 <(find build -type f -iname "*.html" -printf "%P\n" | sed 's/\.html$//' | sort) \
<(find source -type f -iname "*.md" -printf "%P\n" | sed 's/\.md$//' | sort)
The find commands get you a list of all the files (and only files - directories will have to be removed in a separate step) in each of the build and source folder, sed chops off the extension, while comm -23 compares them, printing only the files unique to the build folder, which you can then deal with as you see fit (e.g., by feeding them to xargs rm).
- hawski 3y agoUsing comm was exactly what I did use in my little experiment of a barebones SSG. I did save a list of generated files and compared them. This one liner is the meat of the whole solution: comm -23 <(awk 'NR>1' "$DSTDIR/build-info") <(find "$SRCDIR" -name "*$EXT" -type f -printf "%P\n" | tee >(gen_index) | xargs -n1 "$0" "$SRCDIR" "$DSTDIR" | sort | tee -a "$DSTDIR/build-info.new") | (cd "$DSTDIR" && xargs rm) Full source here: https://gist.github.com/hadrianw/060944011acfcadd889d937b960a5a1f https://gist.github.com/hadrianw/060944011acfcadd889d937b960...