NAME
pathchk
—
validate filenames
SYNOPSIS
pathchk |
[-Pp ] path… |
DESCRIPTION
Checks for validity and/or portability of paths:
- total length,
- length of individual components,
- character set, and
- searchability.
With -p
, each path
is considered as if on an abstract base-line POSIX system:
- maximum length of
_POSIX_PATH_MAX
(256), - maximum component length of
_POSIX_NAME_MAX
(14), - the portable filename character set:
[A-Za-z0-9._-]+
.
Otherwise, it resides on the current system:
- maximum length of
PATH_MAX
(most likely 4096), - maximum component length of
pathconf(
_PC_NAME_MAX
) for the parent directory, if exists, or_POSIX_NAME_MAX
, - alphabet verified indirectly by
lstat(2), which should return
EINVAL
, - searchability verified by
lstat(2), which returns
EACCES
if any component was unsearchable.
OPTIONS
-P
- Additionally reject empty paths and components starting with "-"s.
-p
- Check for the POSIX system (see above).
--portability
-Pp
EXIT STATUS
1 if any path failed any check.
EXAMPLES
Check whether a directory tree can be safely transferred to any conformant system:
$
find
. -exec
pathchk
-Pp
{} +
pathchk: ./POSIX/POSIX.1-202x_d1.pdf: POSIX.1-202x_d1.pdf: too long (19 > 14) pathchk: ./POSIX/IEEE P1003.2 Draft 11.2−September 1991.txt: IEEE P1003.2 Draft 11.2−September 1991.txt: too long (44 > 14) pathchk: ./POSIX/IEEE P1003.2 Draft 11.2−September 1991.txt: IEEE P1003.2 Draft 11.2−September 1991.txt: non-portable characters: − pathchk: ./BSD/UNIX_Users_Manual_Release_3_Jun80.pdf: UNIX_Users_Manual_Release_3_Jun80.pdf: too long (37 > 14) pathchk: ./BSD/PWB UNIX User's Manual, Edition 1.0.pdf: PWB UNIX User's Manual, Edition 1.0.pdf: too long (39 > 14) pathchk: ./BSD/PWB UNIX User's Manual, Edition 1.0.pdf: PWB UNIX User's Manual, Edition 1.0.pdf: non-portable characters: ' , pathchk: ./Документация по ДЕМОС 2.10.tbz2: Документация по ДЕМОС 2.10.tbz2: too long (50 > 14) pathchk: ./Документация по ДЕМОС 2.10.tbz2: Документация по ДЕМОС 2.10.tbz2: non-portable characters: Документация по ДЕМОС pathchk: ./fips180-2withchangenotice.pdf: fips180-2withchangenotice.pdf: too long (29 > 14)
SEE ALSO
STANDARDS
Conforms to IEEE Std 1003.1-2008
(“POSIX.1”); --portability
is
an extension, originating from the GNU system.
HISTORY
Created in IEEE Std 1003.2-1992
(“POSIX.2”) with only -p
, to,
alongside
sh(1) noclobber (set
-C
), replace the need for the proposed
mktemp(1), validfnam
, and similar utilities,
quoting pairing pathchk
with a loop over
"$TMPDIR
/application_abbreviation$$
.suffix"
as sufficient, instead.
IEEE Std 1003.1-2008
(“POSIX.1”) adds -P
, noting
that the -Pp
needs to be used to ensure "full
filename portability" across all systems, with the split being retained
for compatibility.
BUGS
PATH_MAX
, well, isn't — it's
defined to 4096 on all modern systems for compatibility,
but longer paths are, usually, perfectly legal, just not necessarily usable
as a syscall argument. Keep this in mind.