Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mkdirp(3g) [hpux man page]

mkdirp(3G)																mkdirp(3G)

NAME
mkdirp(), rmdirp() - create, remove directories in a path SYNOPSIS
DESCRIPTION
creates all the missing directories in the given path with the given mode (see chmod(2) for the values of mode.) The protection part of the mode argument is modified by the process's file creation mask (see umask(2)). rmdirp removes directories in path d. This removal starts at the end of the path and moves back toward the root as far as possible. If an error occurs, the remaining path is stored in d1. returns a 0 only if it is able to remove every directory in the path. To use these interfaces, link in the libgen library by specifying For example: RETURN VALUE
If a needed directory cannot be created, returns -1 and sets to one of the error numbers. If all the directories are created, or existed to begin with, it returns zero. EXAMPLES
WARNINGS
uses to allocate temporary space for the string. returns if a "" or "" is in the path. It returns if an attempt is made to remove the current directory. If an error occurs other than one of these two errors, returns SEE ALSO
chmod(2), mkdir(2), rmdir(2), umask(2), thread_safety(5). mkdirp(3G)

Check Out this Related Man Page

mkdirp(3GEN)					     String Pattern-Matching Library Functions					      mkdirp(3GEN)

NAME
mkdirp, rmdirp - create or remove directories in a path SYNOPSIS
cc [ flag ... ] file ... -lgen [ library ... ] #include <libgen.h> int mkdirp(const char *path, mode_t mode); int rmdirp(char *dir, char *dir1); DESCRIPTION
The mkdirp() function creates all the missing directories in path with mode. See chmod(2) for the values of mode. The rmdirp() function removes directories in path dir. This removal begins at the end of the path and moves backward toward the root as far as possible. If an error occurs, the remaining path is stored in dir1. RETURN VALUES
If path already exists or if a needed directory cannot be created, mkdirp() returns -1 and sets errno to one of the error values listed for mkdir(2). It returns zero if all the directories are created. The rmdirp() function returns 0 if it is able to remove every directory in the path. It returns -2 if a ``.'' or ``..'' is in the path and -3 if an attempt is made to remove the current directory. Otherwise it returns -1. EXAMPLES
Example 1: Example of creating scratch directories. The following example creates scratch directories. /* create scratch directories */ if(mkdirp("/tmp/sub1/sub2/sub3", 0755) == -1) { fprintf(stderr, "cannot create directory"); exit(1); } chdir("/tmp/sub1/sub2/sub3"); . . . /* cleanup */ chdir("/tmp"); rmdirp("sub1/sub2/sub3"); ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
chmod(2), mkdir(2), rmdir(2), malloc(3C), attributes(5) NOTES
The mkdirp() function uses malloc(3C) to allocate temporary space for the string. SunOS 5.10 14 Oct 2003 mkdirp(3GEN)
Man Page

15 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Recursively deleting directories

Say I have a directory call test, and several directories nested in it, and several directories nested in them. And I want to remove all directories within "test" and its subdirectories that have the name "cvs", how can I do this? I tried rm -r cvs, but that only removed the top level direcotry... (4 Replies)
Discussion started by: mikeshank
4 Replies

2. UNIX for Dummies Questions & Answers

How to list only directories?

How to list directories (not sub-directories) from a given path? (4 Replies)
Discussion started by: videsh77
4 Replies

3. Shell Programming and Scripting

Finding relative path of a file

I have to relatively get the path of a file to use it in the script. The directory structure is /export/opt/XTools/ and under this there are several version directories - 1.0_A0, 1.0_A1, 1.0_A2 etc.,. The actual file is under these directories: installscript.sh My script should pickup the... (4 Replies)
Discussion started by: chiru_h
4 Replies

4. UNIX for Dummies Questions & Answers

plz help me...

unfortunately...i created directory with name "-rf" but now am unable to remove it. (6 Replies)
Discussion started by: venkatramana
6 Replies

5. Shell Programming and Scripting

Last modified file in 2 or more directories

Hi, Is there any simple way to get the last modified file in a set of 2 or more directories? This should return one file only (not 1 file per directory) Thanks for your help (4 Replies)
Discussion started by: m69w
4 Replies

6. UNIX for Dummies Questions & Answers

remove all directories and sub-directories

Please could someone advise me the unix command to remove all directories and sub-directories with files within the directory structures. Thank you (6 Replies)
Discussion started by: venhart
6 Replies

7. UNIX for Dummies Questions & Answers

How to create shotcuts to the directories

Hi, I need your help in writing shortcuts to my directories. So that I can go into the directories with the help of shortcuts. For example: there is a directory called /home/java/webapps/project1 I want to give a shortcut as project1 . So whenever I have give cd project 1 from command line ... (3 Replies)
Discussion started by: TonySolarisAdmi
3 Replies

8. Shell Programming and Scripting

Want to Get List of All directories

:confused: Hi, Is there any one-lier through which I will be able to reach to last directory excluding all files only directrory and sub-directoris should be displayed from the current path. Thanks in advance (7 Replies)
Discussion started by: niceboykunal123
7 Replies

9. Shell Programming and Scripting

Script to find folders with spaces and end of files and directories

Hi I need a script that can search through a set of directories and can locate any file or directory that has a space at the end Filename(space) Foldername(space) I then need to remove that space within the script Hope someone can help thanks in advance Treds (8 Replies)
Discussion started by: treds
8 Replies

10. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

11. UNIX for Dummies Questions & Answers

wildcards in path

Is there some rule about using wildcards in path? Say I want to create a file, but one of the directories in the path is called 1433d.default and on different machines it will be called <some other string>.default touch ~/Library/Application/*.default/myfile In theory I thought that... (5 Replies)
Discussion started by: glev2005
5 Replies

12. Shell Programming and Scripting

How to list Matching Directories OR NULL w/o error message?

I want to be able to get all the directories in a path into a variable array, BUT if there ARE NO directories I want the Variable to be NULL and not echo any error message! If there ARE directories, this will get the list of the directories whose name begins with the string "20":... (6 Replies)
Discussion started by: pgorbas
6 Replies

13. Shell Programming and Scripting

Function to remove the directories from PATH variable

Hello, From the URL https://www.unix.com/shell-programming-scripting/121303-remove-path-path-environment-variable-2.html I got a function to remove the directories from a path. but looks like this isnt quite working.. i am also not able to post the comments in the thread as it is closed. ... (6 Replies)
Discussion started by: satishkumar432
6 Replies

14. Shell Programming and Scripting

Want to remove directories names 1 2 3 ...

Dear All, I have some list of directories names 1 2 3 .... n. Number can vary each time when I run some software to create these folders. When ever I wanted to run new case I have to remove all the sub-directories named 1 2 3 4 .... in case directory. How can I do it using rm -r command? ... (4 Replies)
Discussion started by: linuxUser_
4 Replies

15. Shell Programming and Scripting

Search for a file in all directories and place the file in that directory

Hi All, Daily I am getting the updated file. I have to search for this file in all directories and sub directories. If the file existed in a particular directory then move this updated file to that particular directory. If the file is not existed in any of the directories then place this... (4 Replies)
Discussion started by: ROCK_PLSQL
4 Replies