Strip last component from file name. Use when extracting the directory path from a full file path.
67
80%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Passed
No known issues
Optimize this skill with Tessl
npx tessl skill review --optimize ./.flox/pkgs/skill-coreutils/skills/dirname/SKILL.mddirname [OPTION] NAME...Output each NAME with its last non-slash component and trailing slashes removed. If NAME contains no slashes, output '.'.
| Flag | Long Form | Description |
|---|---|---|
| -z | --zero | End each output line with NUL, not newline |
| --help | Display help | |
| --version | Output version |
# Extract directory from path
dirname /path/to/file.txt
# Output: /path/to
# Current directory indicator
dirname file.txt
# Output: .
# Root-level file
dirname /file.txt
# Output: /
# Multiple arguments
dirname /path/to/file1.txt /other/file2.txt
# Output: /path/to\n/other
# In shell scripting: find script's directory
script_dir=$(dirname "$0")
# Navigate to script's directory
cd "$(dirname "$0")"
# Robust way to get script's absolute directory
script_dir=$(cd "$(dirname "$0")" && pwd)dirname is purely string-based. It does not check if the directory
exists or resolve symlinks. Use realpath for that.dirname /path/to/ outputs /path (trailing slash means to is
the last component).dirname name (no slashes) outputs . (current directory).${var%/*} is similar to
dirname "$var" but behaves differently for paths without slashes.basename which needs -a).bb1f07d
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.