The dirname command in Linux is used to extract the directory component from a path or file name. It returns the directory name without the file name or any trailing slashes.

Syntax:

dirname [option] file_name

Options:

  • -z or --zero : Output a zero byte (null character) at the end of each line.
  • -h or --help : Display help information and exit.
  • -V or --version : Output version information and exit.

Example:

$ dirname /home/user/example.txt
/home/user

$ dirname /usr/local/bin/
/usr/local

$ dirname /usr/local/bin
/usr/local

$ dirname ./documents/report.docx
./documents
``
linux dirname

原文地址: https://www.cveoy.top/t/topic/h79w 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录