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

git-ls-files(1) avoiding symlinks

From
ACAlejandro Colomar <alx+git@kernel.org>
Date
Nov 6, 2026, 13:35 UTC
Message-ID
<au3Tyaz_LoYDuskn@devuan>
Hi!

Yesterday, we were discussing alternative methods for grepping source code. Here's a list of similar alternatives:

	$ find . -type f | xargs grep ARRAY_END;
	$ git ls-files | xargs grep ARRAY_END;
	$ git grep ARRAY_END;

The version using find(1) has some problems: it is slow, especially after having built a kernel, when the directory is full of temporary objects.

The version using git-grep(1) without IPC is the fastest, and doesn't have any problems, but it is limited to just grep(1). If we want to use sed(1), or any other programs, we're out of luck.

A common program I want to use is grepc(1), which searches source code. See for example this code for finding the creat(2) system call:

	$ git ls-files | grep '\.[ch]$' | xargs grepc creat;
	fs/open.c:SYSCALL_DEFINE2(creat, const char __user *, pathname, umode_t, mode)
	{
		int flags = O_CREAT | O_WRONLY | O_TRUNC;
		if (force_o_largefile())
			flags |= O_LARGEFILE;
		return do_sys_open(AT_FDCWD, pathname, flags, mode);
	}
	include/linux/syscalls.h:asmlinkage long sys_creat(const char __user *pathname, umode_t mode);
	tools/include/nolibc/fcntl.h:static __attribute__((unused))
	int creat(const char *path, mode_t mode)
	{
		return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
	}

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?

Have a lovely day! Alex

-- 
<https://www.alejandro-colomar.es>
Next: D. Ben Knoble
Message 1 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.