dirname

 

NAME

dirname - strip all but the "containing-directory" part of a string  

PAGE DATE 19990409

SYNOPSIS

dirname string_argument
dirname {--help,--version}  

DESCRIPTION

dirname removes everything to the right of the rightmost slash in a string, not counting a possible slash at the extreme right end of a string. dirname doesn't actually know or care about files or directories, other than you can redirect dirname's output to a file, but that's actually the shell at work.

dirname operates on a single string argument, and sends it's output to standard out. dirname's output can be redirected, but redirecting to dirname's standard in is in effect an alias for /dev/null. string_argument may be subject to shell expansion or may be a variable. However, any expansion must result in a single argument.
If string_argument is a single component, that is, if it contains no slashes, dirname prints `.' to imply "the current directory". dirname doesn't care if string_argument actually happens to be a file, it is simply dealing with the name as a string. If string_argument ends with a /, the last part including the trailing slash is removed. This means that dirname returns "the pathname of the directory containing it's argument", even if it's argument is a directory, and without any actual filesystem intelligence, but rather in terms of what the resulting string manipulations look like.

EXAMPLES


$ dirname /some/pathname-like/string/ohteu
/some/pathname-like/string

$ dirname sumutha/pathname-like/string/ocrudeu/
sumutha/pathname-like/string

$ dirname aDoseOfNoSlashitol
.

 

GNU Options

--help
Print a usage message on standard output
--version
Print version information on standard output

SEE ALSO

dirname is roughly the opposite of basename .
Completely general truncating and otherwise modifying strings can be done with sed or awk . Both are complete, but scriptable and pipeable programming languages, but with some syntactic overhead compared to a simple utility like dirname. One could also use tr to change a delimiter in a string to or from a slash, which along with dirname, basename and also cut , gives a fairly general set of string operators directly from the shell.

RIGHTS

dirname in cLIeNUX is from the GNU shell utilities, and is subject to the GNU GPL. This seedoc contains a few snippets of the GNU manpage, but is not a derived work of it or anything else, and is Copyright 1999 Richard Allen Hohensee. This page is released for redistribution only as part of an intact and entire cLIeNUX Core.