Last active
February 18, 2025 19:11
-
-
Save dusanbrankov/b062830e221d759d7abf19b320a12a43 to your computer and use it in GitHub Desktop.
Bash function to create directories and files in one command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create directories and files in one command | |
# | |
# Example: | |
# mkf dir1/file1.{txt,doc,html} dir1/dir2/file2.{txt,doc,html} | |
# | |
# Result: | |
# dir1/ | |
# ├── dir2 | |
# │ ├── file2.doc | |
# │ ├── file2.html | |
# │ └── file2.txt | |
# ├── file1.doc | |
# ├── file1.html | |
# └── file1.txt | |
mkf() { | |
for f in "$@"; do | |
[[ $f =~ / ]] && mkdir -p "${f%/*}" | |
done | |
touch "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment