The pathchk command checks that one or more pathnames are valid (i.e. they can be used to access or create a file without causing syntax errors) and portable (i.e. the name need not be adjusted). More extensive portability checks can be carried out -p option.
By default, the pathchk command checks the components of all pathname arguments based on the underlying file system. An error message is output for the pathname argument if:
It is longer than the maximum permitted pathname length ({
PATH_MAX
} bytes).It contains a component that is longer than the maximum permitted filename length ({
NAME_MAX
} bytes) in the relevant directory.It contains a component in a directory that is not searchable.
It contains a component with characters that are invalid in the directory.
The name length of a file or directory in a bs2fs file system does not contradict the rules for a bs2fs file system.
pathchk does not consider it an error if one or more components of a pathname argument do not exist, as long as the file with the specified pathname can be created and does not violate any of the checks described above.
Syntax
pathchk[ -p] pathname... |
option
pathchk does not perform a check on the underlying file system, but on generic portability conditions. An error message relating to the pathname argument is output if:
The pathnames to be checked. |
Locale
The following environment variables affect the execution of pathchk: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Hint
Using the test command you can check whether a certain pathname specifies an existing file. However there is no information about whether a component of the pathname was truncated (in a directory where the { |
Example
You can check if all pathnames in an imported data interchange archive are legitimate and unambiguous on the current system as follows: pax -f archive | sed -e \*(hO/ == .*/s///\*(hO | xargs pathchk if [ $? -eq 0 ] then pax -r -f archive else echo Investigate problems before importing files. exit 1 fi You can check whether all files in the current directory hierarchy can be transferred to another system, that the general portability conditions are met, and that the pax command is available as follows: find . -print | xargs pathchk -p if [ $? -eq 0 ] then pax -w -f archive . else echo Portable archive cannot be created. exit 1 fi You can check whether a specified pathname names a readable file and whether an application can create a file by extending the filename without truncating the pathname and without overwriting any existing files. case $- in *C*) reset="";; *) reset="set +C" set -C;; esac test -r "$path" && pathchk "$path.out" && rm "$path.out" > "$path.out" if [ $? -ne 0 ]; then printf "%s: %s not found or %s.out fails \ creation checks.\n" $0 "$path" "$path" $reset # reset the noclobber option in case a trap # on EXIT depends on it exit 1 fi $reset PROCESSING < "$path" > "$path.out" This example is based on the following:
|
See also
test |