Linux common commands -97: dirname

The 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]

Common parameters:


 dirname /etc/nginx/sites-enabled/default

 # 最后一个字符是/,以倒数第二个/来判断dirname /etc/nginx/sites-enabled/

 # 相对路径dirname NVIDIA_CUDA-11.2_Samples/1_Utilities/deviceQuery/

This article is reprinted from
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment