How do I get ag to list all files, including empty ones?

+ravi@boxy:~$ mkdir new && cd new
+ravi@boxy:~/new$ echo stuff > non-empty && touch empty
+ravi@boxy:~/new$ ag -ul

How do I get empty to appear in the example above?

  • Just a guess but perhaps it's an optimization that says empty files can't match any text?
    – Jeff Schaller
    Commented Aug 14, 2016 at 13:20
  • Why do you want to find empty files with ag? The entire point of ag is to avoid searching files that have no chance to contain useful patterns. Commented Aug 14, 2016 at 16:00
  • They are files. Why break -l if a null pattern is supposed to match all files? ...Because it's faster and (and generally better) than 'find'.
    – Tom Hale
    Commented Aug 14, 2016 at 17:07

2 Answers 2


My suspicion is confirmed by looking at the source in the search_file function around line 258, where it checks the file's size. If the size is zero, it bails out:

if (f_len == 0) {
    log_debug("Skipping %s: file is empty.", file_full_path);
    goto cleanup;

To confirm that this is the case, you may be able to use the --debug option.


As @Jeff answers, the code didn't previously support this. I made a Pull Request to fix the issue which has just now been merged in.

Note: The project maintainer is asking for help as his available time for ag is limited.

  • Too bad this forces one to include all the (in my case) garbage files with -u
    – ig-dev
    Commented Jul 19, 2022 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .