CtrlK
BlogDocsLog inGet started
Tessl Logo

dirname

Strip last component from file name. Use when extracting the directory path from a full file path.

67

Quality

80%

Does it follow best practices?

Impact

No eval scenarios have been run

SecuritybySnyk

Passed

No known issues

Optimize this skill with Tessl

npx tessl skill review --optimize ./.flox/pkgs/skill-coreutils/skills/dirname/SKILL.md
SKILL.md
Quality
Evals
Security

dirname - Strip Last Component from File Name

Synopsis

dirname [OPTION] NAME...

Output each NAME with its last non-slash component and trailing slashes removed. If NAME contains no slashes, output '.'.

Flags

FlagLong FormDescription
-z--zeroEnd each output line with NUL, not newline
--helpDisplay help
--versionOutput version

Examples

# 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)

Gotchas

  • 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).
  • For bash parameter expansion, ${var%/*} is similar to dirname "$var" but behaves differently for paths without slashes.
  • Multiple arguments are supported without special flags (unlike basename which needs -a).
Repository
flox/floxenvs
Last updated
Created

Is this your skill?

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.