<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/zsh-manipulate-filenames-with-modifiers-like-r-root-and-e-extension--0bvafqoyh" -->

---
title: Zsh: manipulate filenames with modifiers like :r (root)...
description: Zsh offers built-in filename modifiers as suffixes on parameter expansions to slice up paths without calling external commands like dirname or basename. The...
canonical: https://daily.dev/posts/zsh-manipulate-filenames-with-modifiers-like-r-root-and-e-extension--0bvafqoyh
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Zsh: manipulate filenames with modifiers like :r (root) and :e (extension) | daily.dev
og:description: Zsh offers built-in filename modifiers as suffixes on parameter expansions to slice up paths without calling external commands like dirname or basename. The...
og:url: https://daily.dev/posts/zsh-manipulate-filenames-with-modifiers-like-r-root-and-e-extension--0bvafqoyh
og:image: https://api.daily.dev/og/posts/0BVafqOyH.png
og:image:alt: Zsh: manipulate filenames with modifiers like :r (root) and :e (extension)
og:image:width: 1200
og:image:height: 630
og:locale: 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 · 1 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 strip the file extension from a filename in a zsh script?

Use the :r modifier on a parameter expansion, which drops the extension and returns the root of the path. For example, if f=talks/robot.png, then ${f:r} returns talks/robot. Combine it with :t (tail) as ${f:t:r} to get just the bare filename without directory or extension, e.g. robot.

_Developers scripting file conversions in zsh can find more shell parameter tricks on daily.dev._

### How can I batch convert PNG images to WebP using a zsh loop and ImageMagick?

Loop over the files with for i in *.png; do magick $i ${i:r}.webp; done. The magick command from ImageMagick infers input and output formats from file extensions, and the :r modifier strips .png from the filename before appending .webp to build the output name. Zsh does not word-split unquoted variables, so filenames with spaces stay safe without quoting.

_Anyone automating image format conversions can browse more shell and tooling tips 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
- [A shell exclamation mark is not for yelling. Be lazy](https://daily.dev/posts/a-shell-exclamation-mark-is-not-for-yelling-be-lazy-ota4wgej1) · Lobsters · 0 upvotes · 0 comments
- [Zsh: tab complete glob qualifiers](https://daily.dev/posts/zsh-tab-complete-glob-qualifiers-trzdr8umc) · Adam Johnson · 1 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)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"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","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/zsh-manipulate-filenames-with-modifiers-like-r-root-and-e-extension--0bvafqoyh"},"datePublished":"2026-08-24T23:20:42.821Z","dateModified":"2026-09-14T06:43:03.262Z","description":"Zsh offers built-in filename modifiers as suffixes on parameter expansions to slice up paths without calling external commands like dirname or basename. The...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cfa81121289a3d4c0baf3783ff9b9b0d?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cfa81121289a3d4c0baf3783ff9b9b0d?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Adam Johnson","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Adam Johnson","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/bf70f4401c284aa5b628d1966029342c","url":"https://daily.dev/sources/adamj"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/zsh-manipulate-filenames-with-modifiers-like-r-root-and-e-extension--0bvafqoyh","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"cli,shell,bash","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Adam Johnson","item":"https://daily.dev/sources/adamj"},{"@type":"ListItem","position":3,"name":"Zsh: manipulate filenames with modifiers like :r (root) and :e (extension)"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/zsh-manipulate-filenames-with-modifiers-like-r-root-and-e-extension--0bvafqoyh#faq","mainEntity":[{"@type":"Question","name":"How do I strip the file extension from a filename in a zsh script?","acceptedAnswer":{"@type":"Answer","text":"Use the :r modifier on a parameter expansion, which drops the extension and returns the root of the path. For example, if f=talks/robot.png, then ${f:r} returns talks/robot. Combine it with :t (tail) as ${f:t:r} to get just the bare filename without directory or extension, e.g. robot. Developers scripting file conversions in zsh can find more shell parameter tricks on daily.dev."}},{"@type":"Question","name":"How can I batch convert PNG images to WebP using a zsh loop and ImageMagick?","acceptedAnswer":{"@type":"Answer","text":"Loop over the files with for i in *.png; do magick $i ${i:r}.webp; done. The magick command from ImageMagick infers input and output formats from file extensions, and the :r modifier strips .png from the filename before appending .webp to build the output name. Zsh does not word-split unquoted variables, so filenames with spaces stay safe without quoting. Anyone automating image format conversions can browse more shell and tooling tips on daily.dev."}}]}
```

