I am learning Unix online and i came across this question to create a hierarchical structure. I have created the directories using mkdir
command but I am stuck while creating the files inside directory.
My command for creating directories is
mkdir -p mydir/{colors/{basic,blended},shape,animals/{mammals,reptiles}}
Best Answer
Here's two ways to do it. There's more, but the concept would be the same: either extending what you have, or iterating over a list and breaking each list item into parts.
Long way to do it
There's nothing special that needs to be done with
touch
. Simply extend the same arguments that you had formkdir
command to include files.Short way
If you observe, all of your directories have files to create. Thus what we can do is create list of items( effectively a bash array ) and iterate over them, with using
mkdir
with suffix removal and thentouch
. Like this:Side note: if you have spaces in any file or directory name, ensure that you single or double quote those items, e.g.:
See also.