pathchk
Check if file names are valid
TLDR
Check pathnames for validity in the current system
Check pathnames for validity on a wider range of POSIX compliant systems
Check pathnames for validity on all POSIX compliant systems
Only check for empty pathnames or leading dashes (-)
SYNOPSIS
pathchk [-p] PATHNAME...
PARAMETERS
-p, --portability
Checks the path for portability according to the POSIX.1-2001 standard. This imposes stricter rules on characters and length, such as limiting characters to the portable filename character set.
PATHNAME...
One or more pathnames to be checked for validity and portability. Multiple pathnames should be separated by spaces.
--help
Displays a help message and exits.
--version
Outputs version information and exits.
DESCRIPTION
pathchk is a utility that checks the validity and portability of one or more pathnames. It assesses whether a given path conforms to file system naming conventions and length restrictions, and if it's portable across different systems, specifically according to POSIX.1-2001 standards when the -p option is used. Without -p, it checks against the underlying operating system's rules.
The command examines aspects like character sets, maximum component length (filename or directory name), and total path length. It is crucial for developing portable shell scripts or applications that create files and directories, ensuring they will function correctly on various Unix-like systems. If all specified pathnames are valid and portable, pathchk exits silently with a status of zero. Otherwise, it prints diagnostic messages to standard error and exits with a non-zero status.
CAVEATS
pathchk only performs a syntactic check of the pathname based on character set and length constraints. It does not check if the path actually exists on the filesystem, if the user has permissions to create the path, or if the path is otherwise semantically valid in the current filesystem context. The definition of 'portable' depends heavily on the presence of the -p option; without it, checks are specific to the local system's limitations.
EXIT STATUS
Returns 0 if all specified pathnames are valid and portable according to the checks performed. Returns a non-zero value if any pathname is found to be invalid or non-portable.
STANDARD OUTPUT/ERROR
On success (exit status 0), pathchk produces no output to standard output or standard error. On failure (non-zero exit status), diagnostic error messages describing the issues are printed to standard error.
HISTORY
The pathchk command is part of the POSIX.1-2001 standard, which specifies its behavior for checking pathname validity and portability. It is widely implemented across Unix-like operating systems, most notably as part of the GNU Coreutils package, ensuring its availability and consistent behavior on Linux distributions and other systems that adopt GNU utilities. Its inclusion in POSIX underscores its importance for writing robust and cross-platform shell scripts and applications.