basename(3) Library Functions Manual basename(3) basename, dirname - LIBRARY Standard C library (libc, -lc) #include char *dirname(char *path); char *basename(char *path); Warning: there are two different functions basename(); see below. The functions dirname() and basename() break a null-terminated pathname string into directory and filename components. In the usual case, dirname() returns the string up to, but not including, the final '/', and basename() returns the component following the final '/'. Trailing '/' characters are not counted as part of the pathname. path , dirname() <<.>>, basename() path. path <>, dirname() basename() <>. path null , dirname() basename() <<.>>. , dirname(), <> , basename(), . dirname() basename() path, . , . path, , path, , , , . ( SUSv2) , dirname() basename() : dirname basename /usr/lib /usr lib /usr/ / usr usr . usr / / / . . . .. . .. dirname() basename() , null ( free(3)). attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |basename(), dirname() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ basename() -- POSIX, , GNU, #define _GNU_SOURCE /* feature_test_macros(7) */ #include GNU , path , , <>. GNU dirname() . , glibc basename(), POSIX, -- GNU. POSIX.1-2008. POSIX.1-2001. POSIX, glibc, path, <>. Before glibc 2.2.1, the glibc version of dirname() did not correctly handle pathnames with trailing '/' characters, and generated a segfault if given a NULL argument. basename() dirname(): char *dirc, *basec, *bname, *dname; char *path = "/etc/passwd"; dirc = strdup(path); basec = strdup(path); dname = dirname(dirc); bname = basename(basec); printf("dirname=%s, basename=%s\n", dname, bname); . basename(1), dirname(1) Artyom Kunyov , Azamat Hackimov , Dmitriy Ovchinnikov , Dmitry Bolkhovskikh , ITriskTI , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . basename(3)