---
title: "Zsh: manipulate filenames with modifiers like :r (root) and :e (extension)"
url: https://daily.dev/posts/zsh-manipulate-filenames-with-modifiers-like-r-root-and-e-extension--0bvafqoyh
source_url: https://adamj.eu/tech/2026/08/24/zsh-filename-modifiers
type: article
source: "Adam Johnson"
published: 2026-08-24T23:20:42.821Z
updated: 2026-08-24T23:21:03.193Z
tags: ["cli", "shell", "bash"]
reading_time: 2
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Zsh: manipulate filenames with modifiers like :r (root) and :e (extension)

**[Adam Johnson](https://daily.dev/sources/adamj)** · 2 min read · 0 upvotes · 0 comments

## Summary

Zsh offers built-in filename modifiers as suffixes on parameter expansions to slice up paths without calling external commands like dirname or basename. The four core modifiers are :h (head, directory part), :t (tail, filename part), :r (root, strips extension), and :e (extension, keeps only extension), and they can be chained left to right, e.g. :t:r reduces a full path to a bare filename. A practical example shows using :r in a loop to batch-convert PNG images to WebP with ImageMagick's magick command, building output filenames like robot.webp from robot.png.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://adamj.eu/tech/2026/08/24/zsh-filename-modifiers>

## Questions this post answers

### How do I remove the file extension from a filename in a zsh script?

Use the :r modifier on a parameter expansion, which strips the extension from a path. For example, with f=talks/robot.png, ${f:r} returns talks/robot. This is useful for building output filenames, such as converting robot.png to robot.webp by appending .webp to ${i:r} in a loop.

_daily.dev surfaces shell scripting tricks like this for developers automating file conversions._

### How can I get just the filename without directory or extension in zsh?

Chain the :t and :r modifiers together as :t:r, applied left to right. The :t modifier keeps only the filename (like basename), and :r then strips its extension, so ${f:t:r} on talks/robot.png returns just robot. This avoids separate calls to basename and further string manipulation.

_developers scripting file processing pipelines can find more zsh patterns like this on daily.dev._

## Similar posts on daily.dev

- [Zsh: select generated files with \(om\[1\]\) glob qualifiers](https://daily.dev/posts/zsh-select-generated-files-with-om-1-glob-qualifiers-fbfmj2ts0) · Adam Johnson · 0 upvotes · 0 comments

---

Tags: [#cli](https://daily.dev/tags/cli), [#shell](https://daily.dev/tags/shell), [#bash](https://daily.dev/tags/bash)

[View this post on daily.dev](https://daily.dev/posts/zsh-manipulate-filenames-with-modifiers-like-r-root-and-e-extension--0bvafqoyh)
