dirname是一个标准UNIX程序。给予dirname一个路径名时,它会删除最后一个斜线('/'
)后的任何后缀,并返回结果。单一UNIX规范描述了dirname。它主要用于shell脚本中。
用法
单一UNIX规范中的dirname定义为:
例如:
$ dirname /usr/home/carpetsmoker/dirname.wiki
/usr/home/carpetsmoker
性能
由于dirname
只接受一个操作数,在shell脚本内循环中使用可能会降低性能。考虑
while read file; do
dirname "$file"
done < some-input
上面的例子会导致每行输入调用一个单独的进程。由于这个原因,通常会用shell替换来代替
echo "${file%/*}";
参见
外部链接
dirname
: return the directory portion of a pathname – 命令与工具(Commands & Utilities)参考,单一UNIX®规范第7期,由國際開放標準組織发布 dirname
: strip nondirectory suffix from filenames – 参考,单一UNIX®规范第7期,由國際開放標準組織发布
|
---|
| 文件系統 | - cat
- cd
- chmod
- chown
- chgrp
- cksum
- cmp
- cp
- dd
- du
- df
- file
- fsck
- fuser
- ln
- ls
- mkdir
- mount
- mv
- pax(英语:pax (Unix))
- pwd
- rm
- rmdir
- size
- split
- stat
- tee
- touch
- type(英语:type (Unix))
- umask(英语:umask)
|
---|
| 程序 | - at
- bg
- chroot
- cron
- fg
- kill
- killall(英语:killall)
- nice
- pgrep
- pkill(英语:pkill)
- ps
- pstree(英语:pstree)
- time
- top
|
---|
| 用户环境 | |
---|
| 文本编辑 | - awk
- banner(英语:banner (Unix))
- basename
- comm(英语:comm)
- csplit(英语:csplit)
- cut
- diff
- dirname
- ed
- ex
- fmt(英语:fmt)
- fold(英语:fold (Unix))
- head(英语:head (Unix))
- iconv
- join(英语:join (Unix))
- less
- more
- nl(英语:nl (Unix))
- paste(英语:paste (Unix))
- sed
- sort(英语:sort (Unix))
- spell(英语:spell (Unix))
- strings(英语:strings (Unix))
- tail
- tr
- uniq(英语:uniq)
- vi
- wc
- xargs
|
---|
| 壳层内建 | |
---|
| 网络(英语:Network utility) | |
---|
| 查找 | |
---|
| 文档 | - apropos(英语:apropos (Unix))
- help(英语:help (command))
- man
|
---|
| 软件开发 | |
---|
| 杂项 | - bc
- cal
- dc
- expr
- lp(英语:lp (Unix))
- lpr
- sleep
- true和false
- yes
|
---|
| |
|