Decode fstab Paths Safely Before Running a Command
fstab-decode turns the escaped paths inside /etc/fstab back into real characters before handing them to another command. The installed utility is from sysvinit-utils 3.08-6ubuntu3 and lives at /usr/sbin/fstab-decode. This guide uses harmless printf checks first, then shows how the same pattern relates to filesystem commands.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about ten minutes. You need a shell, the sysvinit-utils package, and a readable source of fstab-style path arguments. The examples do not change mounts or files. The final unmount pattern is potentially service-disrupting, and should only be run after reviewing its decoded arguments.
1. Check the installed command
Confirm that the utility is available, and see which copy your shell will run:
$ command -v fstab-decode
/usr/sbin/fstab-decode
$ fstab-decode
Usage: fstab-decode command [arguments]
- No options to choose. Its interface is one command followed by zero or more arguments.
- Decode then execute. It decodes each supplied argument, then runs the command with the decoded argument list.
Checkpoint
The usage line should identify command [arguments]. If the command is missing, install or repair the package through your normal system administration process. Do not copy a replacement binary into /usr/sbin.
2. Decode the common fstab escapes
fstab represents spaces and tabs in a path as \040 and \011. A newline is \012, and a literal backslash is \134. Pass those sequences as shell arguments and let printf display the result:
$ fstab-decode printf 'arg=<%s>\n' 'plain' 'archive\040old' 'tab\011name' 'line\012break' 'slash\134name'
arg=<plain>
arg=<archive old>
arg=<tab name>
arg=<line
break>
arg=<slash\name>
Each encoded value stays one argument. The decoded space or newline is data inside that argument; it does not cause a second round of shell word splitting. The visible tab and line break in the output are expected.
Run a compact argument-count check when the distinction matters:
$ fstab-decode sh -c 'printf "argc=%s\n" "$#"; printf "arg=<%s>\n" "$@"' sh 'one\040two' 'three'
argc=2
arg=<one two>
arg=<three>
The extra sh after -c is the shell's $0; the remaining values become $1 and later positional parameters.
3. Turn a list into decoded command arguments
The useful workflow is to produce one fstab-escaped path per line, then use command substitution to pass those lines as separate shell words. This read-only example previews VFAT mount points from the local fstab instead of unmounting anything:
$ (set -f; fstab-decode printf 'mountpoint=<%s>\n' $(awk '$3 == "vfat" { print $2 }' /etc/fstab))
(no output on this machine)
Your output may be empty, or may contain different mount points. The subshell's set -f disables pathname expansion while the command substitution is expanded. That matters because an asterisk or question mark in an input path could otherwise be treated as a shell pattern before fstab-decode sees it. The subshell keeps that setting from changing your interactive shell.
Review the generated list separately if the result is unexpected:
$ awk '$3 == "vfat" { print $2 }' /etc/fstab
(no output on this machine)
Do not add quotes around the entire command substitution in this pattern. Quoting it would pass the complete multi-line output as one argument, rather than one argument per source line.
4. Apply the pattern to an operation that changes state
The manual's representative use is unmounting every VFAT mount point listed in /etc/fstab:
$ (set -f; sudo fstab-decode umount $(awk '$3 == "vfat" { print $2 }' /etc/fstab))
Warning
Stop before running this. umount can interrupt users and services, and sudo elevates the operation.
- Preview first. Run the preview from step 3, then check every path.
- Confirm nothing is in use. No required filesystem should still be active on those mounts.
- Arrange a recovery window. If a mount is needed again, remount it using your normal documented procedure, for example the appropriate
mountcommand or service configuration for that host. There is no automatic undo supplied byfstab-decode.
A safer habit is to replace umount with printf until the argument list is exactly right. Keep the command in a subshell so the temporary glob setting is not retained.
5. Check failures without guessing
If the target command cannot be started, fstab-decode exits with status 127 and reports the operating system error:
$ fstab-decode command-that-does-not-exist
fstab-decode: command-that-does-not-exist: No such file or directory
$ printf '%s\n' "$?"
127
When the command does start, fstab-decode returns the target command's status. Capture it immediately if a script needs to act on failure:
fstab-decode some-command 'path\040with\040spaces'
status=$?
if [ "$status" -ne 0 ]; then
printf 'decoded command failed with status %s\n' "$status" >&2
exit "$status"
fi
Do not treat a successful decode as proof that a path exists, is mounted, or is safe to operate on. Those are separate checks belonging to the command you are running.
Done means
- Command confirmed.
fstab-decoderesolves to the installed utility and accepts a command plus arguments. - Escapes understood.
\040,\011,\012and\134decode to the intended path characters. - List reviewed before use. A list-producing command is checked before its output is used operationally.
- Globbing disabled where needed. Pathname expansion is turned off in the example subshell when untrusted or unusual names are possible.
- Unmounts treated as elevated work. Any command that unmounts filesystems has a deliberate recovery plan behind it.