From 1c4e37ed8a4dbf23a0b719dee459ec26bad533fb Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 11 Nov 2024 20:15:43 -0600 Subject: [PATCH] Add Count All Files Of Specific Type Tracked By Git as a Git TIL --- README.md | 3 ++- ...l-files-of-specific-type-tracked-by-git.md | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 git/count-all-files-of-specific-type-tracked-by-git.md diff --git a/README.md b/README.md index 5d43ba8..bcc3b73 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1503 TILs and counting..._ +_1504 TILs and counting..._ --- @@ -297,6 +297,7 @@ _1503 TILs and counting..._ - [Configure Global gitignore File](git/configure-global-gitignore-file.md) - [Configuring The Pager](git/configuring-the-pager.md) - [Copy A File From Another Branch](git/copy-a-file-from-another-branch.md) +- [Count All Files Of Specific Type Tracked By Git](git/count-all-files-of-specific-type-tracked-by-git.md) - [Create A New Branch With Git Switch](git/create-a-new-branch-with-git-switch.md) - [Delete All Untracked Files](git/delete-all-untracked-files.md) - [Determine The Hash Id For A Blob](git/determine-the-hash-id-for-a-blob.md) diff --git a/git/count-all-files-of-specific-type-tracked-by-git.md b/git/count-all-files-of-specific-type-tracked-by-git.md new file mode 100644 index 0000000..92f0560 --- /dev/null +++ b/git/count-all-files-of-specific-type-tracked-by-git.md @@ -0,0 +1,27 @@ +# Count All Files Of Specific Type Tracked By Git + +I want to get a count of all the markdown files in my [TIL +repo](https://github.com/jbranchaud/til). Since all the files I care about are +tracked by `git`, I can use `git ls-files` to get a listing of all files. That +command on its own lists all files tracked by your git repository. Though there +are many other flags we can apply, that will do for my purposes. + +By giving `git ls-files` a pattern to match against, I can turn up just, for +instance, markdown files (`*.md`). I can pipe that to `wc -l` to get a count +rather than exploding my terminal with a list of file names. + +```bash +❯ git ls-files '*.md' | wc -l + 1503 +``` + +That command includes `README.md` and `CONTRIBUTING.md`, but really I only want +to count the markdown files that constitute a TIL. Those all happen to be +nested under a single directory. So I can tweak the glob pattern like so: + +```bash +❯ git ls-files '*/*.md' | wc -l + 1501 +``` + +See `man git-ls-files` for more details.