Try mkdir -p
:
mkdir -p foo
Note that this will also create any intermediate directories that don’t exist; for instance,
mkdir -p foo/bar/baz
will create directories foo
, foo/bar
, and foo/bar/baz
if they don’t exist.
Some implementation like GNU mkdir
include mkdir --parents
as a more readable alias, but this is not specified in POSIX/Single Unix Specification and not available on many common platforms like macOS, various BSDs, and various commercial Unixes, so it should be avoided.
If you want an error when parent directories don’t exist, and want to create the directory if it doesn’t exist, then you can test
for the existence of the directory first:
[ -d foo ] || mkdir foo
Related Posts:
- How to mkdir only if a directory does not already exist?
- How do I split a string on a delimiter in Bash?
- What is the $? (dollar question mark) variable in shell scripting?
- Meaning of “! -S” in shell script
- “No such file or directory” but it exists
- Ubuntu says “bash: ./program Permission denied” [closed]
- Should I put #! (shebang) in Python scripts, and what form should it take?
- Should I put #! (shebang) in Python scripts, and what form should it take?
- How do I copy a folder from remote to local using scp?
- How to concatenate string variables in Bash
- -bash: syntax error near unexpected token `)’
- An example of how to use getopts in bash
- How to delete from a text file, all lines that contain a specific string?
- How do I iterate over a range of numbers defined by variables in Bash?
- How to set ssh timeout?
- commands not found on zsh
- sudo: apt-get: command not found
- How do I iterate over a range of numbers defined by variables in Bash?
- Why do people write #!/usr/bin/env python on the first line of a Python script?
- Using find to locate files that match one of multiple patterns
- “unary operator expected” error in Bash if condition
- What does “-ne” mean in bash?
- How can I declare and use Boolean variables in a shell script?
- Is there a Python equivalent to the ‘which’ command
- How can I declare and use Boolean variables in a shell script?
- How to generate random number in Bash?
- How to check if a variable is set in Bash?
- “[ ]” vs. “[[ ]]” in Bash shell
- How do I split a string on a delimiter in Bash?
- Who can access a file with octal permissions “000” on Linux/UNIX?
- How can I compare numbers in Bash?
- What does the line “#!/bin/sh” mean in a UNIX shell script?
- Open and write data to text file using Bash?
- How do I set a variable to the output of a command in Bash?
- python getoutput() equivalent in subprocess
- Meaning of $? (dollar question mark) in shell scripts
- Is there a TRY CATCH command in Bash
- dquote> result of a execution a program in linux shell
- Using sudo with Python script
- how to fix the issue “Command /bin/sh failed with exit code 1” in iphone
- Run a string as a command within a Bash script
- conditional binary operator expected in shell script
- Block Comments in a Shell Script
- Shell script not running, command not found
- How to get a shell environment variable in a makefile?
- What are the uses of the exec command in shell scripts?
- using rot13 and tr command for having an encrypted email address
- Shell Script: Execute a python program from within a shell script
- sed whole word search and replace
- How do I know the script file name in a Bash script?
- What is the difference between double and single square brackets in bash?
- What is “-bash: !”: event not found”
- What’s the difference betwen the single dash and double dash flags on shell commands?
- How to let ‘cp’ command don’t fire an error when source file does not exist?
- How to use execvp()
- How to execute a program or call a system command?
- How can I sandbox Python in pure Python?
- How to run a PowerShell script
- In the shell, what does ” 2>&1 ” mean?
- How do I parse command line arguments in Bash?
- ‘\r’: command not found – .bashrc / .bash_profile [duplicate]
- How can I recursively find all files in current and subfolders based on wildcard matching?
- How can I check if a directory exists in a Bash shell script?
- Shell command to tar directory excluding certain files/folders
- How does “cat << EOF" work in bash?
- How do I compare two string variables in an ‘if’ statement in Bash?
- How can I count all the lines of code in a directory recursively?
- How can I kill a process by name instead of PID, on Linux?
- Which characters need to be escaped when using Bash?
- Shell: How to call one shell script from another shell script?
- ./configure : /bin/sh^M : bad interpreter
- Choosing a Windows automation scripting language. AutoIt vs Autohotkey
- get “ERROR: Can’t get master address from ZooKeeper; znode data == null” when using Hbase shell
- How to read a file into a variable in shell?
- Implementing shell in C and need help handling input/output redirection
- How to count lines in a document?
- What does `set -x` do?
- How to specify the private SSH-key to use when executing shell command on Git?
- Writing a simple shell in C using fork/execvp
- Speed up rsync with Simultaneous/Concurrent File Transfers?
- Multi-dimensional arrays in Bash
- Implementation of multiple pipes in C
- Variable interpolation in the shell
- chmod: changing permissions of ‘my_script.sh’: Operation not permitted
- What’s the meaning of the parameter -e for bash shell command line?
- What does set -e mean in a bash script?
- What does set -e mean in a bash script?
- Check existence of input argument in a Bash shell script
- Difference between a script and a program?
- Python Login Script; Usernames and Passwords in a separate file
- source command not found in sh shell
- Difference between sh and Bash
- Why am I getting Permission Denied when trying to push a Sqlite file to my rooted Android device?
- Why can’t I print to terminal with my python script?
- How to parse XML in Bash?
- Error handling in Bash
- Best practice for exiting batch file?
- How to run command as user who has /usr/sbin/nologin as Shell?
- Why use Chef/Puppet over shell scripts?
- How do I join two named pipes into single input stream in linux