git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-ls-files(1) avoiding symlinks

From
ACAlejandro Colomar <alx+git@kernel.org>
Date
Nov 6, 2026, 14:45 UTC
Message-ID
<au3lu4jYwZ5hBZSy@devuan>
In-Reply-To
<CALnO6CB-b2XuvwkQ9pJp5ENuc12oGMdgbcwz1VKD_i3KWfKuHA@mail.gmail.com>
Hi Ben,
> Date: 2026-11-06 09:15:22-0500
> From: "D. Ben Knoble" <ben.knoble@gmail.com>
>
[...]
Show 11 quoted lines
> > A problem with git-ls-files(1) is that it doesn't have a way to filter
> > files by type.  That is, it will list symlinks, which will affect the
> > search.  With find(1), I can control that with '-type f', which makes
> > sure I only search in regular files.  I'd like to have some feature in
> > git-ls-files(1) that allows me to print files of the specified type.
> > Since git(1) knows the type of the files, this should be doable without
> > much overhead, right?
> 
> Perhaps something with "git ls-files --format='%(objectmode) %(path)'
> -z"? Of course, your examples already omit -z, so if you can assume
> that it might be simpler.
Hmmm, that could work.  Thanks!
	$ git ls-files --format='%(objectmode) %(path)' \
	| grep -v ^120000 \
	| sed 's/^.* //' \
	| grep '\.[ch]$' \
	| xargs grepc creat;
With -z it becomes a bit tedious:
	$ git ls-files -z --format='%(objectmode) %(path)' \
	| grep -zv ^120000 \
	| sed -z 's/^.* //' \
	| grep -z '\.[ch]$' \
	| xargs -0 grepc creat;

But, indeed, I don't care about files with spaces often, because I don't create them in my stuff.

I expect git-ls-files(1) could make this much simpler, though:
	$ git ls-files --type f \
	| grep '\.[ch]$' \
	| xargs grepc creat;

Have a lovely day! Alex

-- 
<https://www.alejandro-colomar.es>
Previous: D. Ben KnobleNext: Alejandro Colomar
Message 3 of 6 in “git-ls-files(1) avoiding symlinks”
  1. Alejandro ColomarNov 6, 2026
  2. D. Ben KnobleNov 6, 2026
  3. Alejandro ColomarNov 6, 2026
  4. Alejandro ColomarNov 6, 2026
  5. Junio C HamanoNov 6, 2026
  6. Alejandro ColomarNov 6, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.