Dirname

dirname是一个标准UNIX程序。给予dirname一个路径名时,它会删除最后一个斜线('/')后的任何后缀,并返回结果。单一UNIX规范描述了dirname。它主要用于shell脚本中。

用法

单一UNIX规范中的dirname定义为:

 dirname NAME

例如:

 $ dirname /usr/home/carpetsmoker/dirname.wiki
   /usr/home/carpetsmoker

性能

由于dirname只接受一个操作数,在shell脚本内循环中使用可能会降低性能。考虑

while read file; do
        dirname "$file"
done < some-input

上面的例子会导致每行输入调用一个单独的进程。由于这个原因,通常会用shell替换来代替

echo "${file%/*}";

参见

外部链接

文件系統
  • 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
用户环境
  • clear
  • env
  • exit
  • history英语history (Unix)
  • id
  • logname
  • mesg英语mesg
  • passwd
  • su
  • sudo
  • uptime
  • talk英语talk (software)
  • tput英语tput
  • uname
  • w
  • wall英语wall (Unix)
  • who
  • whoami
  • write英语write (Unix)
文本编辑
  • 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
壳层内建
网络
查找
文档
  • apropos英语apropos (Unix)
  • help英语help (command)
  • man
软件开发
杂项
  • bc
  • cal
  • dc
  • expr
  • lp英语lp (Unix)
  • lpr
  • sleep
  • true和false
  • yes