find closest parent directory containing a named file or directory
Find a file
2025-10-28 15:31:05 +10:00
closest.go version option added 2025-10-28 15:31:05 +10:00
go.mod initial commit 2025-09-30 11:49:36 +02:00
LICENSE initial commit 2025-09-30 11:49:36 +02:00
ReadMe.md initial commit 2025-09-30 11:49:36 +02:00

closest - inverted find

closest finds files (or directories) in the current working directory and all parent directories.

Example:

% pwd
/home/alice/dev/experiments/utils/closest/a/b/c

# find the closest .git directory
% closest .git
/home/alice/dev/experiments/utils/closest/.git

# add -p to show the parent directory of found files or directories
% closest -p .git
/home/alice/dev/experiments/utils/closest

# -a shows all parent .git directories / files
% closest -a .git
/home/alice/dev/experiments/utils/closest/.git
/home/alice/dev/experiments/utils/.git
/home/alice/dev/.git

# missing targets throw an error to STDERR
% closest foo
"foo" not found
exit 1

Installation

closest is a simple go program and is currently only available as source code.

Use go's go install command to download and install closest in your $GOPATH/bin directory.

go install codeberg.org/japh/closest@latest

Usage

%closest [options] <filename>...

Options

-a show all matches -p only show the parent directory of any found files

Source

https://codeberg.org/japh/closest

Author

Stephen Riehm japh-codeberg@opensauce.de