dirname command removes the non-directory part of the file name and only displays the content related to the directory, which is the opposite of the
basename command introduced earlier.
dirname keeps the last
/ and its preceding characters, and removes the rest. If there are no characters after the last
dirname uses the second-to-last
/ and ignores all characters after it.
Syntax format: dirname [parameter]
# 最后一个字符是/，以倒数第二个/来判断dirname /etc/nginx/sites-enabled/
# 相对路径dirname NVIDIA_CUDA-11.2_Samples/1_Utilities/deviceQuery/
This article is reprinted from https://xugaoxiang.com/2022/09/06/linux-cmds-97-dirname/
This site is for inclusion only, and the copyright belongs to the original author.