Skip to content

Instantly share code, notes, and snippets.

@Drewlius
Created September 18, 2026 14:40
Show Gist options
  • Select an option

  • Save Drewlius/bc0bbd928c94c64e28d0f89f00355b8e to your computer and use it in GitHub Desktop.

Select an option

Save Drewlius/bc0bbd928c94c64e28d0f89f00355b8e to your computer and use it in GitHub Desktop.
tags
linux
terminal
file-search
fish
aliases
Linux File Search
Terminal Search Commands
created 2026-07-17

Linux Terminal File Search Guide

Use the smallest likely search folder. Searching ~/Projects is faster and clearer than searching /.

Pick the right tool

I want to find… Use
A name of a file or directory fd, or find when fd is unavailable
Text inside files rg (ripgrep)
A file anywhere on the system, very quickly locate
What is in one directory ls
A result from a fuzzy interactive list fzf

Use --help for complete built-in documentation:

fd --help
rg --help
find --help

Quote patterns that contain spaces or special characters: rg 'connection refused'.


1. ls: inspect your current location

ls lists a single directory; it does not search into subdirectories.

ls                         # Names in the current directory
ls -la                     # Long details, including hidden files
ls -lah                    # Human-readable sizes
ls -lt                     # Newest modified entries first
ls -lahS                   # Largest entries first
ls -d */                   # Directories only, here

ls -lah ~/Documents
ls -lt ~/Downloads

You can filter a listing, though this is not a replacement for a real filename search:

ls -la | rg -i 'obsidian'  # Current directory entries containing “obsidian”

2. fd: fast, friendly filename searching

fd is a modern, convenient alternative to common find usage. It searches beneath the current directory unless you give it a path.

fd 'report'                         # Names containing report
fd -i 'report' ~/Documents          # Case-insensitive name search
fd -e md ~/Documents/Obsidian       # Files ending in .md
fd -t d 'project' ~/                # Directories only
fd -t f -e pdf ~/Documents          # PDF files only
fd -H 'config' ~                    # Include hidden files/directories
fd -E node_modules -E .git 'app' .  # Exclude noisy directories

Important options:

  • -t f — regular files; -t d — directories; -t l — symbolic links.
  • -e md — extension filter (write md, not .md).
  • -i — ignore letter case.
  • -H — include hidden paths.
  • -I — do not respect .gitignore or other ignore files.

By default, fd hides dotfiles and respects .gitignore; that is usually helpful in code projects.


3. find: universal and precise

find is installed on virtually every Linux system. Use it for advanced conditions such as size, modification time, ownership, or permissions.

find ~/Documents -name '*.pdf'              # Files/directories whose name ends .pdf
find ~/Documents -iname '*invoice*'         # Ignore case
find ~/Documents -type d -name 'Projects'   # Directories named Projects
find ~ -type f -name '*.md'                  # Markdown files under home
find ~/Downloads -type f -size +1G           # Files larger than 1 GiB
find ~/Projects -type f -mtime -7            # Modified within 7 days

Rules to remember:

  1. Give the search location first: find ~/Documents ....
  2. Use -type f for files and -type d for directories.
  3. Quote wildcard patterns: -name '*.md'. Otherwise your shell can expand * before find sees it.
  4. -name is case-sensitive; -iname is not.

Searching all of / can produce permission errors. This hides only the errors, not matches:

find / -type f -iname '*filename*' 2>/dev/null

Always preview matches before a modifying action:

find ~/Downloads -type f -name '*.part' -print
find ~/Downloads -type f -name '*.part' -delete  # Only after checking the previous output

4. rg / ripgrep: search text inside files

Use rg for words, phrases, error messages, function names, or settings stored inside files.

rg 'TODO' ~/Projects                       # Search text below ~/Projects
rg -i 'connection refused' ~/Documents     # Ignore case
rg -l 'API_KEY' ~/.config                  # Matching filenames only
rg -g '*.md' 'backup' ~/Documents          # Only Markdown files
rg -g '!node_modules/**' 'import' .        # Exclude a path pattern
rg -C 3 'panic' ~/Projects                  # Three context lines around matches

rg uses regular expressions by default. Use -F for exact literal text:

rg -F 'https://example.com?a=1&b=2' ~/Documents
rg -F '[TODO]' .

Like fd, it normally skips hidden and ignored paths. Use these deliberately:

rg --hidden 'setting' ~/.config  # Include hidden paths
rg -uuu 'setting' .              # Include hidden, ignored, and binary files; use sparingly

Search Fish command history too:

history search --contains 'docker'

5. locate: indexed system-wide name search

locate searches a filesystem database, so it is extremely fast—but a very new file may not appear until the database updates.

locate -i 'obsidian'
locate -i --limit 30 'notes'
locate -i --regex '.*\.pdf$'       # Paths ending in .pdf

Many systems update the database automatically. If installed/configured, refresh it manually with:

sudo updatedb

Use locate to discover a likely path, then use ls, fd, or rg to inspect it.


6. Combine tools

Pipes (|) feed the output of one command to another.

# Find Markdown notes whose names mention Linux, then search them for “network”.
fd -i -e md 'linux' ~/Documents/Obsidian | xargs rg -n 'network'

# The ten largest regular files in Downloads.
find ~/Downloads -type f -printf '%s %p\n' | sort -nr | head -n 10

For names containing spaces or newlines, use NUL-safe options:

fd -0 -e md ~/Documents/Obsidian | xargs -0 rg -n 'search term'

7. fzf: interactively select a result (optional)

If fzf is installed, use it to narrow a list while typing:

fd -t f ~/Documents | fzf
rg -l 'search term' ~/Projects | fzf

The selected path is printed. To open it:

set chosen (fd -t f ~/Documents | fzf)
and xdg-open "$chosen"

Persistent Fish aliases

You use Fish, so alias --save creates a persistent shortcut. Run each command once; the aliases will be available in future Fish sessions.

# Better listings
alias --save ll 'ls -lah'
alias --save lt 'ls -lahtr'       # Newest entries at the bottom
alias --save lsize 'ls -lahS'     # Largest first

# Search names below the current directory
alias --save fdf 'fd -t f'
alias --save fdd 'fd -t d'
alias --save fdall 'fd -H -I'     # Include hidden and ignored paths

# Search text below the current directory
alias --save rgi 'rg -i'
alias --save rgh 'rg --hidden'

# System-wide indexed filename search
alias --save loci 'locate -i'

Examples:

ll ~/Documents
fdf -e md Obsidian
fdd 'node_modules' ~/Projects
rgi 'error message' ~/Projects
loci 'ssh_config'

An alias is not ideal for custom logic. This persistent Fish function searches names under your home directory, case-insensitively, including hidden paths:

function fhome --description 'Find paths under home, including hidden files'
    fd -H -i $argv ~
end
funcsave fhome

Use it as follows:

fhome obsidian
fhome -e pdf invoice

A simple decision routine

  1. I know the folder: ls -lah folder/
  2. I know part of the name: fd -i 'part' likely-folder/
  3. I know text inside it: rg -i 'phrase' likely-folder/
  4. I have no idea where it is: locate -i 'part', then narrow the location.
  5. I need filters like age or size: find.
  6. There are too many results: specify a narrower directory, extension (-e md), or type (-t f).

Safe habits

  • Begin in ~, ~/Documents, or a project directory rather than /.
  • Quote patterns containing *, spaces, ?, [, or shell punctuation.
  • Use rg -l when you need files containing text, not every matching line.
  • Preview results before attaching a command that changes or deletes files.
  • Narrow the search path first: it is the biggest speed and clarity improvement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment