REWRITEFS(1)
β¨ rewritefs(1) β mod_rewrite-like FUSE filesystem β¨
bestie, welcome to the rewritefs(1) manual π
this is literally the page for a FUSE filesystem that rewrites file names on the fly, and itβs giving βdotfiles but make it fashion.β letβs go π«Ά
π NAME π
rewritefs β mod_rewrite-like FUSE filesystem
πΈ Description πΈ
rewritefs is a FUSE filesystem similar to web serversβ mod_rewrite. It can change the name of accessed files on-the-fly β¨
The short story: I needed a tool to manage my dotfiles. I forked Luc DufreneΒ΄s libetc [http://ordiluc.net/fs/libetc/] after it seemed unmaintained. Here is its description:
Unfortunately, I eventually run into LD_PRELOAD problems (mainly with programs using dlopen like VirtualBox and screen). So I decided to rewrite it using FUSE, and make it more generic ππ
π Dependencies π
fuse3 & pcre2. Thatβs all.
To use contexts, you need /proc/(pid)/cmdline. But donβt use contexts if you can avoid it ! π
π Installation π
make && sudo make install
π¦ Configuration π¦
For a complete description of the configuration syntax format, see below.
Make sure that user_allow_other is enabled in /etc/fuse.conf πΈ
β¨ Example 1 β¨
The following example demonstrates how one can get the program to do what libetc does :
m#^(?!\.)# .
m#^\.(cache|config|local)# .
m#^\.# .config/
That is, all dotfiles will be put in .config/ (without the leading dot), excepting .cache and .local π
π Example 2 π
This example show how to use contexts ; it is like the former, but ignore the rewrite rules for busybox:
m#^(?!\.)# .
m#^\.(cache|config|local)# .
- /^\S*busybox/
/^/ .
- //
m#^\.# .config/
π Usage π
Once you have written your configuration file, you use rewritefs to mount the βrewrittenβ filesystem, for example :
rewritefs -o config=/mnt/home/me/.config/rewritefs /mnt/home/me /home/me
Then, accessing to files in /home/me will follow rules defined in your config file β¨
π Directory auto-creation π
When using backreferences of in rules of the formβ¦
/(.+) - (.+)/ \1/\2
β¦it is possible that the directory into which an operation is being redirected does not exist yet. To support such rules, rewritefs may be invoked with the option -o autocreate. This option will cause rewritefs to automatically create all non-existing parent directories when a path is being rewritten.
Note that, due to FUSE limitations, the parent directories will be created using the umask with which rewritefs has been invoked, instead of the umask of the process requesting accessing the file π
π₯ Using rewritefs with mount(8) or fstab(5) π₯
rewritefs /mnt/home/me /home/me -o config=/mnt/home/me/.config/rewritefs,allow_other
allow_other and default_permissions is here to allow standards users to access the filesystem with standard permissions.
So, you can use the fstab entry:
/mnt/home/me /home/me fuse.rewritefs config=/mnt/home/me/.config/rewritefs,allow_other 0 0
See mount.fuse(8) for all FUSE options π«Ά
π Using rewritefs with pam_mount(8) π
Letβs suppose that you want to use rewritefs to replace libetc (itβs its primary goal, after all). You need to mount the rewritefs on your home when you login. This can be achieved with pam_mount.
Letβs say you have your raw home dirs in /mnt/home/$USER. Then, to use rewritefs on /home/$USER with configuration file stored at /mnt/home/$USER/.config/rewritefs, you need to add this to pam_mount.xml:
<volume fstype="fuse" path="rewritefs##/mnt/home/%(USER)" mountpoint="~"
options="config=/mnt/home/%(USER)/.config/rewritefs,allow_other" />
You can add user="me" to limit this to yourself (but think to create symlinks for other users !)
Donβt forget to activate pam_mount in your pam configuration too. This is distribution-dependent ; you have to refer to the corresponding documentation π
π FAQ π
Q: I installed rewritefs with the default config, and now ls returns me something like that :
ls: cannot access /home/user/.vimrc: No such file or directory
ls: cannot access /home/user/.zshrc: No such file or directory
d????????? ? ? ? ? ? .ssh/
Short answer: You have to manually move .vimrc, zshrc, .ssh/ inside .config before using rewritefs.
Long answer: If .ssh is translated (by the rules you gave to rewritefs) into .config/ssh, and that you didnβt renamed .ssh into .config/ssh yourself (i.e. that .ssh still exists and .config/ssh doesnβt exists on the original filesystem), thatβs the intended behavior.
Rewritefs does not rewrite readdir(), since it would need βbackwardsβ rewriting (and thatβs not technically possible, since the rules are defined using regular expressions). ls calls readdir(), which returns .ssh. ls then tries to call stat(".ssh") to find metadata (permissions, mtime and so on), which is rewritten into stat(".config/ssh") which does not exists, hence this error π
π Configuration syntax format π
π§ Regular expressions π§
The Regexp syntax is similar to Perl. Recognized flags are : i, x, u and g. Example of valid regexps are:
/foo/i
m/fOo/u
m/dev\/null/
m|tata|
m|This\sis
\san\sextended
\sregexep|x
Note that m{foo} is not recognized ; you must use m{foo{
i and x has the same meaning than in Perl. u means βuse utf-8β (both for pattern and input string).
The g flag is described in the βRewrite ruleβ section.
β Command line match β
Syntax:
- REGEXP
Limit the following rules to programs matching REGEXP (comparing with the content of /proc/(pid)/cmdline, replacing null characters with spaces)
π Rewrite rule π
Syntax:
REGEXP rewritten-path
A file matching REGEXP will be rewritten to rewritten-path. To be more accurate, the matched data will be replaced by rewritten-path in the filename. For example, with this rule:
/fo/ ba
accessing to foo will be translated into bao. > Warning: if you donβt start your regexp with ^, information will be rewritten into inbamation !
If rewritten-path is ., it means βdonΒ΄t rewrite anythingβ.
. and .. will never be proposed to be translated.
You can access captured groups as backreferences (\1, \2, β¦).
A regular expression can be written in more than one line, in particular in conjunction with the x flag.
The g flag indicates that the substition is global, and not limited to the first match. Consider this simple rule:
/:/ -
Applied to A:B:C, the rewritten path will be A-B:C. With the g flag, the rewritten path will be A-B-C β¨
π Comment π
A line starting with #
π Performances π
Some rules to keep the overhead smallest possible :
- use the fast pruning technique described in
config.example - avoid using contexts whenever you can
- avoid using backreferences in your regexp (
\1) - avoid using backreferences in your rewritten path. You can generally avoid them by using lookarounds.
For example, instead of writing:
/\.(gtk-bookmarks|mysql_history)/ .cache/\1
you can write the more efficient:
/\.(?=gtk-bookmarks|mysql_history)/ .cache/
I urge you to read βMastering regular expressionsβ if you want to make rules substantially different from the example π
β REWRITEFS(1), January 2020. byeee π
π
π¦ where this page comes from
- nixpkgs unstable: rewritefs 0-unstable-2026-08-24
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms