dirname
| dirname | |
|---|---|
Example of dirname command | |
| Developer(s) | Various open-source and commercial developers |
| Operating system | Unix, Unix-like, IBM i |
| Platform | Cross-platform |
| Type | Command |
| License | coreutils: GPLv3+ |
dirname은 유닉스와 유닉스-계열 운영 시스템의 표준 컴퓨터 프로그램입니다. dirname이 경로이름에 주어질 때, 그것은 마지막 슬래시 ('/') 문자로 시작하는 임의의 접미사를 삭제하고 결과를 반환할 것입니다. dirname은 단일 유닉스 사양에 설명되어 있고 주로 쉘 스크립트에서 사용됩니다.
History
GNU coreutils에 번들된 dirname 버전은 David MacKenzie와 Jim Meyering에 의해 작성되었습니다.[1]
dirname 명령은 IBM i 운영 시스템에도 이식되었습니다.[2]
Usage
dirname에 대해 단일 유닉스 사용은 다음입니다:
dirname string
string
Examples
dirname은 후행 슬래시를 무시하는 경로이름에서 디렉토리-경로 이름을 검색할 것입니다:
$ dirname /home/martin/docs/base.wiki
/home/martin/docs
$ dirname /home/martin/docs/.
/home/martin/docs
$ dirname /home/martin/docs/
/home/martin
$ dirname base.wiki
.
$ dirname /
/
Performance
dirname은 오직 하나의 피연산자를 허용하므로, 쉘 스크립트의 내부 루프 내에서 사용법은 성능이 저하될 수 있습니다. 다음을 생각해 보십시오:
while read file; do
dirname "$file"
done < some-input
위의 발췌문은 입력의 각 줄에 대해 별도의 프로세스 호출을 발생시킵니다. 이러한 이유로, 쉘 대체가 전형적으로 대신 사용됩니다:
echo "${file%/*}";
또는 만약 상대 경로이름이 마찬가지로 처리되어야 하면
if [ -n "${file##*/*}" ]; then
echo "."
else
echo "${file%/*}";
fi
이들은 dirname과 다르게 후행 슬래시를 처리함을 주목하십시오.
Misconceptions
우리가 후행 슬래시로 끝나는 경로가 디렉토리라고 생각할 수 있습니다. 그러나 실제로, 후행 슬래시는 디렉토리 내의 모든 파일을 나타냅니다.
/home/martin/docs/.
경로를 디렉토리로 나타내는 올바른 방법은 후행 슬래시와 마침표를 사용하는 것입니다.[according to whom?][citation needed]
See also
References
- ^ https://linux.die.net/man/1/dirname
- ^ IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). Retrieved 2020-09-05.
{{cite web}}: CS1 maint: url-status (link)
External links
- : return the directory portion of a pathname – Commands & Utilities Reference, The Single UNIX Specification, Issue 7 from The Open Group
- – Linux User Commands Manual
- – OpenBSD General Commands Manual