REDIRFD(1)

πŸ“¦ version 2.9.9.2, in nixpkgs unstable

πŸŽ€ REDIRFD(1) β€” the redirfd girlies' guide πŸŽ€

okay so bestie, we're doing the redirfd page from the General Commands Manual section, and honestly? it's giving backstage-pass-for-your-file-descriptors. let's get into it πŸ’…


✨ NAME ✨

redirfd β€” redirect a given file descriptor to a file, then execute a program. that's the whole personality. that's the job. slay.


🌸 SYNOPSIS 🌸

redirfd [-r | -w | -u | -a | -x] [-n] [-b] fd file prog...
redirfd [-r | -w | -u | -a | -x] [-n] [-b] [-f] [-e | -E] var file
        prog...

two whole flavors, both iconic, pick your fighter 🫢


πŸ’– DESCRIPTION πŸ’–

so redirfd takes the file descriptor number fd, redirects it to file, and then exec(3)s into prog.... like it literally becomes your program. main character energy, no going back.

when you run it with the -v option, the first argument gets interpreted as an environment variable instead. yes, the page says -v and we are simply not asking questions πŸ’€ anyway β€” redirfd opens file, stores the obtained file descriptor into environment variable var, then execs into prog.... cute, right?

and here's the receipts, because i know you love a shell-equivalence moment:

  • redirfd -r n file prog... is roughly equivalent to sh -c 'exec prog... n<file'
  • redirfd -w n file prog... is roughly equivalent to sh -c 'exec prog... n>file'
  • redirfd -u n file prog... is roughly equivalent to sh -c 'exec prog... n<>file'
  • redirfd -a n file prog... is roughly equivalent to sh -c 'exec prog... n>>file'
  • redirfd -x n file prog... has no portable shell equivalent. not me being built different 😭πŸ”₯

πŸ¦‹ Special fifo handling πŸ¦‹

the -n and -b options are especially useful with named pipes. like, this is their moment. their era. their arc.

  • opening a fifo for reading, blocking if there is no writer:
redirfd -r n fifo prog...
  • opening a fifo for reading, with instant success even if there is no writer, and blocking at the first attempt to read from it:
redirfd -r -nb n fifo prog...
  • opening a fifo for writing, blocking if there is no reader:
redirfd -w n fifo prog...
  • opening a fifo for writing, with instant success even if there is no reader:
redirfd -w -nb n fifo prog...
⚠️ warning bestie, for real for real: the first attempt to write to the fifo will raise a SIGPIPE if there is still no reader at that time. the named pipe semantics normally do not allow a fifo to be open for writing without a reading end, and you should know what you are doing if you're using redirfd this way. not a vibe check you wanna fail πŸ™ˆ

πŸ’… OPTIONS πŸ’…

one and only one of the -r, -w, -u -a, or -x options must be given; the -n and -b options may be added in any case. choose wisely, bestie πŸŽ€

  • -r β€” open file for reading. just read. that's it. that's the whole thing.
  • -w β€” open file for writing, truncating it if it already exists. bye bye old contents πŸ‘‹
  • -u β€” open file for reading and writing. both?? both. multi-talented king.
  • -a β€” open file for appending, creating it if it doesn't exist. adding to the conversation, not interrupting it ✨
  • -x β€” open file for writing, creating it, failing if it already exists. exclusive. doesn't do seconds. periodt.
  • -n β€” open file in non-blocking mode. no waiting around, we're busy πŸ’…
  • -b β€” change mode of file after opening it: to non-blocking mode if the -n option was not given, to blocking mode if it was. yes it's the flip-flop option. iconic behaviour honestly.
  • -f β€” interpret the first argument as an environment variable, and stores the new file descriptor into that variable before execing. putting the fd in the env, lowkey genius.
  • -e β€” no autoimport. this is the default. the "we do nothing extra" icon.
  • -E β€” autoimport. this is only useful with the -f option. instead of executing prog..., execute importas -uSi var prog.... this substitutes var into the command line instead of putting it into the environment. fancy πŸ’…

🌈 SEE ALSO 🌈

emptyenv(1), envfile(1), exec(1), execline-cd(1), execline-umask(1), exit(1), export(1), fdblock(1), fdclose(1), fdmove(1), fdreserve(1), fdswap(1), getcwd(1), getpid(1), heredoc(1), piperw(1), posix-cd(1), posix-umask(1), trap(1), tryexec(1), unexport(1), wait(1), withstdinas(1), exec(3)

this man page is ported from the authoritative documentation at: https://skarnet.org/software/execline/redirfd.html β€” go read the source bestie, it's giving scholar energy πŸ“š


πŸ‘‘ AUTHORS πŸ‘‘

Laurent Bercot Alexis <flexibeast@gmail.com> (man page port)


okay that's the whole page, you're officially an expert, go redirect something responsibly πŸ§šβ€β™€οΈ and hey β€” this one's filed under Debian, dated May 5, 2026, so go forth and slay πŸ’œβ­πŸ’–

πŸ“¦ where this page comes from