Skip to content

Instantly share code, notes, and snippets.

@dusanbrankov
Last active February 18, 2025 19:11
Show Gist options
  • Save dusanbrankov/b062830e221d759d7abf19b320a12a43 to your computer and use it in GitHub Desktop.
Save dusanbrankov/b062830e221d759d7abf19b320a12a43 to your computer and use it in GitHub Desktop.
Bash function to create directories and files in one command
# 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