Intro To 'pathchk' Command In Linux
2024-02-21 - By Robert Elder
I use the 'pathchk' command to check if a file or path name is portable:
pathchk -P -p my-example-path#1
pathchk: nonportable character ‘#’ in file name 'my-example-path#1'
Check Portability Of Path Names
The 'pathchk' command can check for a number of different portability issues with file and path names:
info pathchk
...
For each NAME, ‘pathchk’ prints an error message if any of these
conditions is true:
1. One of the existing directories in NAME does not have search
(execute) permission,
2. The length of NAME is larger than the maximum supported by the
operating system.
3. The length of one component of NAME is longer than its file
system’s maximum.
...
This command will check for path names that are too long to be POSIX compliant:
pathchk -P -p aaaaaaaaaaaaaaa
pathchk: limit 14 exceeded by length 15 of file name component ‘aaaaaaaaaaaaaaa’
and this command will check for an empty file name:
pathchk -P -p ''
pathchk: empty file name
Checking For Leading Dash Characters
The 'pathchk' command can also check for file names that contain a leading dash character:
pathchk -P -p -foo
pathchk: invalid option -- 'f'
Try 'pathchk --help' for more information.
and neither does this one:
pathchk -P -p '-foo'
pathchk: invalid option -- 'f'
Try 'pathchk --help' for more information.
or this one:
pathchk -P -p "-foo"
pathchk: invalid option -- 'f'
Try 'pathchk --help' for more information.
This command however, does work:
pathchk -P -p -- -foo
pathchk: leading '-' in a component of file name '-foo'
since it uses the special double dash argument that indicates the end of optional arguments as described in the POSIX specification (see Guideline 10).
Checking For Directory Permission Issues
You can also check for 'directory' permission issues:
mkdir foo
touch foo/boo
chmod u-x foo
ls -ld foo
drw-rwxr-x 2 robert robert 4096 Feb 10 17:07 foo
pathchk foo/boo
pathchk: foo/boo: Permission denied
Filesystem Length Limits
Some filename limits are imposed by the filesystem. You can check for file name constrains that are based on operating system limits instead of POSIX limits:
pathchk aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
pathchk: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: File name too long
The '--portability' Flag
The GNU Core Utils implementation of the 'pathchk' command also supports the 'portability' flag, that can be used in place of the two -p flags:
pathchk --portability my-example-path#1
pathchk --portability aaaaaaaaaaaaaaa
pathchk --portability ''
pathchk --portability -- -foo
pathchk: nonportable character ‘#’ in file name 'my-example-path#1'
pathchk: limit 14 exceeded by length 15 of file name component ‘aaaaaaaaaaaaaaa’
pathchk: empty file name
pathchk: leading '-' in a component of file name '-foo'
info pathchk
‘--portability’
Print an error message if a file name is not portable to all POSIX
hosts. This option is equivalent to ‘-p -P’.
And that's why the 'pathchk' command is my favourite Linux command.
Intro To 'stty' Command In Linux
Published 2023-10-04 |
$1.00 CAD |
Intro To 'nproc' Command In Linux
Published 2023-07-15 |
Intro To 'comm' Command In Linux
Published 2023-09-06 |
How To Force The 'true' Command To Return 'false'
Published 2023-07-09 |
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21 |
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01 |
Intro To 'chroot' Command In Linux
Published 2023-06-23 |
Join My Mailing List Privacy Policy |
Why Bother Subscribing?
|