| tags |
|
||||
|---|---|---|---|---|---|
| aliases |
|
||||
| created | 2026-07-17 |
Use the smallest likely search folder. Searching ~/Projects is faster and clearer than searching /.
| 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 --helpQuote patterns that contain spaces or special characters: rg 'connection refused'.
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 ~/DownloadsYou 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”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 directoriesImportant options:
-t f— regular files;-t d— directories;-t l— symbolic links.-e md— extension filter (writemd, not.md).-i— ignore letter case.-H— include hidden paths.-I— do not respect.gitignoreor other ignore files.
By default, fd hides dotfiles and respects .gitignore; that is usually helpful in code projects.
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 daysRules to remember:
- Give the search location first:
find ~/Documents .... - Use
-type ffor files and-type dfor directories. - Quote wildcard patterns:
-name '*.md'. Otherwise your shell can expand*beforefindsees it. -nameis case-sensitive;-inameis not.
Searching all of / can produce permission errors. This hides only the errors, not matches:
find / -type f -iname '*filename*' 2>/dev/nullAlways 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 outputUse 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 matchesrg 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 sparinglySearch Fish command history too:
history search --contains 'docker'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 .pdfMany systems update the database automatically. If installed/configured, refresh it manually with:
sudo updatedbUse locate to discover a likely path, then use ls, fd, or rg to inspect it.
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 10For names containing spaces or newlines, use NUL-safe options:
fd -0 -e md ~/Documents/Obsidian | xargs -0 rg -n 'search term'If fzf is installed, use it to narrow a list while typing:
fd -t f ~/Documents | fzf
rg -l 'search term' ~/Projects | fzfThe selected path is printed. To open it:
set chosen (fd -t f ~/Documents | fzf)
and xdg-open "$chosen"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 fhomeUse it as follows:
fhome obsidian
fhome -e pdf invoice- I know the folder:
ls -lah folder/ - I know part of the name:
fd -i 'part' likely-folder/ - I know text inside it:
rg -i 'phrase' likely-folder/ - I have no idea where it is:
locate -i 'part', then narrow the location. - I need filters like age or size:
find. - There are too many results: specify a narrower directory, extension (
-e md), or type (-t f).
- Begin in
~,~/Documents, or a project directory rather than/. - Quote patterns containing
*, spaces,?,[, or shell punctuation. - Use
rg -lwhen 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.