If I run touch non/existing/folder/my-file.txt
, touch complains about non-existing folders.
Can I create these folders on the same command, similar to mkdir -p
?
If I run touch non/existing/folder/my-file.txt
, touch complains about non-existing folders.
Can I create these folders on the same command, similar to mkdir -p
?
No, but you can write a script that does that:
# new.sh
for file; do
[[ $file =~ ((.+\/)*)(.+) ]] && mkdir -p "${BASH_REMATCH[2]}"
touch $file
done
Then run: ./new.sh non/existing/folder/my-file.txt possibly/other/files.txt