The following question relates to ZFS on Linux (ZoL) / OpenZFS, as it is provided e.g. in Debian Buster and Debian Bullseye.

As the title says, I'd like to know whether ZFS snapshot names theoretically can contain newlines (as normal filenames can do), and if yes, how I can work safely through a list of snapshot names in a script.

I have tried to create snapshots with such names, but zfs (fortunately) refused to do that. However, I'd like to be sure, and therefore, I'm asking here.

A bit of background: On this site and elsewhere, there often is the question how we could parse the output of ls to work through the list of file names name by name. The answer mostly is: Don't do this, because there can be unexpected side effects, for example if the file names contain newlines; instead, use bash's globbing. I have understood that (in fact, I always did it like that).

However, when it comes to ZFS snapshot names, there is no globbing. For example, on my box, when I issue something like zfs list -H -r -o name -t snapshot rpool/vm-garak, I get a list of snapshot names having the entries separated by a newline:

root@cerberus ~/scripts # zfs list -H -r -o name -t snapshot rpool/vm-garak

I have some scripts which work through this list name by name; that is, line by line, relying on the fact the the newline character reliably indicates a new snapshot name.

As long as I have the snapshot creation under my control, this is safe, because I can avoid unreasonable snapshot names. But the snapshots are created by somebody else, so what if there is a newline in the name? As mentioned above, I had no success with creating such snapshot names, but I am surely not aware of all weird methods which could produce them.

A final note: I am aware that I eventually could get away with globbing as long as it concerns normal dataset (file system) snapshots, because ZFS puts them into a hidden directory and makes them accessible as normal directories / files. However, in my case, the snapshots are snapshots from ZVOLs, which ZFS does not make accessible that way.

1 Answer 1


Based on this document there is no way you can have new line in to the name of ZFS snapshot. So IMHO parse it line by line.

Each component can only contain alphanumeric characters in addition to the following four special characters:
    Underscore (_)
    Hyphen (-)
    Colon (:)
    Period (.)
Pool names must begin with a letter, except for the following restrictions:
    The beginning sequence c[0-9] is not allowed.
    The name log is reserved.
    A name that begins with mirror, raidz, raidz1, raidz2, raidz3, or spare is not allowed because these names are reserved.
    Pool names must not contain a percent sign (%).
Dataset names must begin with an alphanumeric character.
Dataset names must not contain a percent sign (%).

I found naming convention in Openindiana, but unfortunately the site is under maintenance

  • 1
    Wow. That was fast. Accepted and +1. I missed that document. I probably should have mentioned that I was talking about ZFS on Linux / OpenZFS, but I'll now assume that it is the same there.
    – Binarus
    Oct 4, 2021 at 15:52
  • 1
    @Binarus, I try to open wiki of Openindiana, where probably is closer to linux version, but seems like server is down Oct 4, 2021 at 16:13
  • 1
    @Binarus, will add the page in the answer Oct 4, 2021 at 16:22
  • 3
    The source confirms this. github.com/openzfs/zfs/blob/… / github.com/openzfs/zfs/blob/…
    – steve
    Oct 4, 2021 at 16:31
  • 1
    Funny how their definition of alphanumeric seems not to include the alpha (α, A) letter. Oct 4, 2021 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.