Look at stat
for checking if the directory exists,
And mkdir
, to create a directory.
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> struct stat st = {0}; if (stat("/some/directory", &st) == -1) { mkdir("/some/directory", 0700); }
You can see the manual of these functions with the man 2 stat
and man 2 mkdir
commands.
Related Posts:
- How do I find all files containing specific text on Linux?
- How to extract C source code from .so file?
- How to change permissions for a folder and its subfolders/files in one step
- How to change permissions for a folder and its subfolders/files in one step
- Implementing shell in C and need help handling input/output redirection
- Read and write to binary files in C?
- Writing a simple shell in C using fork/execvp
- Implementation of multiple pipes in C
- configure: error: cannot run C compiled programs
- Can’t remove a directory in Unix
- Is there an alternative sleep function in C to milliseconds?
- C fopen vs open
- error : storage class specified for parameter
- Wait for user input in C?
- Difference between exec, execvp, execl, execv?
- cd into directory without having permission
- Meaning of directories on Unix and Unix like systems
- How to copy file preserving directory path in Linux?
- Bash: No such file or directory?
- What’s a .sh file?
- How can I symlink a file in Linux? [closed]
- Kill detached screen session [closed]
- Undefined reference to pthread_create in Linux
- Openssl : error “self signed certificate in certificate chain”
- How to get the url of the current svn repo?
- How to unmount a busy device
- How to unmount a busy device
- No space left on device
- How to perform grep operation on all files in a directory?
- What is the LD_PRELOAD trick?
- Amazon Linux: apt-get: command not found
- Pass a password to ssh in pure bash
- How can I exclude directories from grep -R?
- Docker can’t connect to docker daemon
- Need a good hex editor for Linux
- Pseudo-terminal will not be allocated because stdin is not a terminal
- Directory Inode vs Regular File Inode
- What does it mean to mount a file system in linux?
- What can cause a “Resource temporarily unavailable” on sock send() command
- Trying to use bash on Windows and got no installed distributions message
- “Unable to find remote helper for ‘https'” during git clone
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- -bash: fork: Cannot allocate memory
- Is there a “goto” statement in bash?
- Explanation of polkitd Unregistered Authentication Agent
- How can I get the list of files in a directory using C or C++?
- tar: Cowardly refusing to create an empty archive
- How can I delete a user in linux when the system says its currently used in a process
- Command to change the default home directory of a user
- PHP and mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
- How to grep and replace
- Where is the
header file on Linux? Why can’t I find ? - How to recursively download a folder via FTP on Linux
- httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName
- Why does “docker attach” hang?
- Retrieve last 100 lines logs
- What are various options / arguments for “./configure” in Linux
- CronJob not running
- Delete .DS_STORE files in current folder and all subfolders from command line on Mac
- bash sh – command not found
- How to configure WP filesystem access in Linux (Ubuntu Server)?
- Can’t upload media to my Raspberry Pi WordPress server
- My WordPress is giving me an 403 error when saving post/draft with specific words
- How do I prevent a folder from reappearing in my home directory?
- How to run a server on port 80 as a normal user on Linux?
- Copying a large directory tree locally? cp or rsync?
- Check if port is open or closed on a Linux server?
- Moving an already-running process to Screen
- When does `cron.daily` run?
- Permission denied (publickey). SSH from local Ubuntu to Amazon EC2 server
- How to run a command multiple times, using bash shell?
- LVM dangers and caveats
- How to reconnect to a disconnected ssh session
- Should I quit using Ifconfig?
- How to know from which yum repository a package has been installed?
- SSL Certificate Location on UNIX/Linux
- What is “-bash: !”: event not found”
- tar – Remove leading directory components on extraction
- Keeping a linux process running after I logout
- Force dig to resolve without using cache
- How to list Apache enabled modules?
- How to forcibly close a socket in TIME_WAIT?
- How to check if an RSA public / private key pair match
- Colors in bash after piping through less?
- How can I monitor hard disk load on Linux?
- Why does sudo command take long to execute?
- “POSSIBLE BREAK-IN ATTEMPT!” in /var/log/secure — what does this mean?
- How to display certain lines from a text file in Linux?
- What’s the reverse DNS command line utility?
- Can you have more than one ~/.ssh/config file?
- How to add a security group to a running EC2 Instance?
- How bad is it really to install Linux on one big partition?
- How do I extract login history?
- SSH from A through B to C, using private key on B [closed]
- Is it possible to reboot a Linux OS without rebooting the hardware?
- Does the “bs” option in “dd” really improve the speed?
- What solutions exist to allow the use of revision control for server configuration files? [closed]
- Is there a way to do a remote “ls” much like “scp” does a remote copy?
- Dump a linux process’s memory to file
- What is the difference between /sbin/nologin and /bin/false?