SPONGE(1)
π SPONGE(1) π
okay bestie, gather round, because sponge is genuinely one of the most iconic little gremlins in the whole moreutils fam and i need you to get it π§β¨
πΈ NAME πΈ
sponge β soak up standard input and write to a file π«§
β¨ SYNOPSIS β¨
sed '...' file | grep '...' | sponge [-a] file
π DESCRIPTION π
so here's the vibe: sponge reads standard input and writes it out to the file you specified. that's it. that's the whole job. π
but wait β the why is the juicy part. unlike a plain shell redirect, sponge soaks up all its input before writing the output file. it's literally a sponge babe, it absorbs everything first, then squeezes it out. π§½
and why do we care?? because that means you can build pipelines that read from and write to the same file. the classic "wait, i can't redirect a file into itself" problem? yeah. solved. ate. no crumbs. π
sponge also preserves the permissions of the output file if it already exists. your chmod work stays intact, we love to see it π
when it can, sponge creates or updates the output file atomically by renaming a temp file into place. so clean, so safe, so main character energy β¨
β οΈ okay but heads up: that atomic glow-up cannot be done if TMPDIR is not in the same filesystem. the vibes are simply not transferable across filesystems, bestie π
and if the output file is a special file or symlink, the data will be written to it β but non-atomically. it's giving "we tried our best but the filesystem said no" π
and if no file is specified, sponge just outputs to stdout. easy peasy π
π OPTIONS π
-aβ Replace the file with a new file that contains the file's original content, with the standard input appended to it. and yes, this is done atomically when possible, because we stay classy π
π AUTHOR π
Colin Watson and Tollef Fog Heen β absolute legends, fr fr π«Ά
and that's the whole page, babe! this one's from the moreutils collection, dated 2006-02-19 β a certified classic that's still slaying all these years later. go build a pipeline that reads and writes the same file, you deserve it ππ¦β
π¦ where this page comes from
- debian bookworm: moreutils 0.67-1 Β· GPL-2.0-or-later
- debian trixie: moreutils 0.69-1 Β· GPL-2.0-or-later
- epel 10: moreutils 0.68-3.el10_0 Β· GPL-2.0-only
- epel 9: moreutils 0.68-1.el9 Β· GPLv2
- fedora 43: moreutils 0.68-5.fc43 Β· GPL-2.0-only
- fedora 44: moreutils 0.68-6.fc44 Β· GPL-2.0-only
- nixos 26.05: moreutils 0.70
- nixpkgs unstable: moreutils 0.70
- opensuse-leap 16.0: moreutils 0.68-bp160.1.13 Β· GPL-2.0-only AND GPL-2.0-or-later AND (GPL-2.0-or-later OR MIT) AND BSD-2-Clause AND SUSE-Public-Domain
- opensuse-leap 16.0: moreutils 0.68-bp160.1.13 Β· GPL-2.0-only AND GPL-2.0-or-later AND (GPL-2.0-or-later OR MIT) AND BSD-2-Clause AND SUSE-Public-Domain
- opensuse-leap 16.0: moreutils 0.68-bp160.1.13 Β· GPL-2.0-only AND GPL-2.0-or-later AND (GPL-2.0-or-later OR MIT) AND BSD-2-Clause AND SUSE-Public-Domain
- opensuse-leap 16.0: moreutils 0.68-bp160.1.13 Β· GPL-2.0-only AND GPL-2.0-or-later AND (GPL-2.0-or-later OR MIT) AND BSD-2-Clause AND SUSE-Public-Domain
- ubuntu jammy: moreutils 0.66-1 Β· GPL-2.0-or-later
- ubuntu noble: moreutils 0.69-1 Β· GPL-2.0-or-later
- ubuntu questing: moreutils 0.69-1
- ubuntu resolute: moreutils 0.69-1build1 Β· GPL-2.0-or-later
- ubuntu stonking: moreutils 0.70-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms