xref: /freebsd/usr.bin/basename/basename.1 (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
1.\" Copyright (c) 1990, 1993, 1994
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.Dd June 21, 2021
32.Dt BASENAME 1
33.Os
34.Sh NAME
35.Nm basename , dirname
36.Nd return filename or directory portion of pathname
37.Sh SYNOPSIS
38.Nm
39.Ar string
40.Op Ar suffix
41.Nm
42.Op Fl a
43.Op Fl s Ar suffix
44.Ar string
45.Op Ar ...
46.Nm dirname
47.Ar string
48.Op Ar ...
49.Sh DESCRIPTION
50The
51.Nm
52utility deletes any prefix ending with the last slash
53.Ql \&/
54character present in
55.Ar string
56(after first stripping trailing slashes),
57and a
58.Ar suffix ,
59if given.
60The
61.Ar suffix
62is not stripped if it is identical to the remaining characters in
63.Ar string .
64The resulting filename is written to the standard output.
65A non-existent suffix is ignored.
66If
67.Fl a
68is specified, then every argument is treated as a
69.Ar string
70as if
71.Nm
72were invoked with just one argument.
73If
74.Fl s
75is specified, then the
76.Ar suffix
77is taken as its argument, and all other arguments are treated as a
78.Ar string .
79.Pp
80The
81.Nm dirname
82utility deletes the filename portion, beginning
83with the last slash
84.Ql \&/
85character to the end of
86.Ar string
87(after first stripping trailing slashes),
88and writes the result to the standard output.
89.Sh EXIT STATUS
90.Ex -std basename dirname
91.Sh EXAMPLES
92The following line sets the shell variable
93.Ev FOO
94to
95.Pa /usr/bin .
96.Pp
97.Dl FOO=`dirname /usr/bin/trail`
98.Sh SEE ALSO
99.Xr csh 1 ,
100.Xr sh 1 ,
101.Xr basename 3 ,
102.Xr dirname 3
103.Sh STANDARDS
104The
105.Nm
106and
107.Nm dirname
108utilities are expected to be
109.St -p1003.2
110compatible.
111.Sh HISTORY
112The
113.Nm
114utility first appeared in
115.At v7 .
116The
117.Nm dirname
118utility first appeared in
119.At III .
120