2307

12 分钟

#Bash 的 pathchk 命令

pathchk [OPTION]... [NAME]...

功能

检查文件名(路径)是否有效或可移植。

类型

可执行文件(/usr/bin/pathchk),属于 coreutils

参数

  • OPTION 选项:
    • -p - 检查文件名是否在大多数 POSIX 系统有效
    • -P - 空的文件名和以 - 开头的文件名无效
    • --portability - 检查是否在所有 POSIX 系统上有效;相当于 -p -P
    • --help - 显示帮助
    • --version - 显示版本
  • NAME - 文件名列表

返回值

  • 0 - 所有文件名都通过了检查
  • 1 - 存在某个文件名未通过检查

#示例

$ pathchk -p filename; echo $? 0 $ pathchk -p -- -filename; echo $? 0 $ pathchk -P -- -filename; echo $? pathchk: leading '-' in a component of file name '-filename' 1
  • $? 表示上一个命令的返回值
  • -- 表示后面的参数不被当作选项

#推荐阅读

#手册

PATHCHK(1) User Commands PATHCHK(1) NAME pathchk - check whether file names are valid or portable SYNOPSIS pathchk [OPTION]... NAME... DESCRIPTION Diagnose invalid or non-portable file names. -p check for most POSIX systems -P check for empty names and leading "-" --portability check for all POSIX systems (equivalent to -p -P) --help display this help and exit --version output version information and exit AUTHOR Written by Paul Eggert, David MacKenzie, and Jim Meyering. REPORTING BUGS GNU coreutils online help: <https://www.gnu.org/software/coreutils/> Report any translation bugs to <https://translationproject.org/team/> COPYRIGHT Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO Full documentation <https://www.gnu.org/software/coreutils/pathchk> or available locally via: info '(coreutils) pathchk invocation' GNU coreutils 9.4 April 2024 PATHCHK(1)

创建于 2025/11/21

更新于 2025/11/21