For web-development practice I'm using a LAMP stack, on Ubuntu 17.10. For this I'm creating directories within /var/www
, each directory is named after a project.
To create a subdirectory I use the terminal and:
david@Ed:/var/www/html$ mkdir projectName
david@Ed:/var/www/html$ cd projectName
david@Ed:/var/www/html/projectName$ mkdir css img js
david@Ed:/var/www/html/projectName$ touch index.html
david@Ed:/var/www/html/projectName$ ls
css img index.html js
This works. And, in all honesty, is far from arduous. But, is there a means by which I can simplify this?
I'm aware that:
mkdir -p projectName/css
Will create both the css
, and the parent projectName
, directory (if that parent doesn't already exist), but it still leaves the requirement of creating the other two directories and the index.html
file (again, this is not particularly arduous but feels like it should be unnecessary).
Ideally I'd like that the command mkdir <projectName>
when run in the /var/www
directory would create the <projectName>
directory with the css
, img
, js
directories and the index.html
document (that document ideally containing the skeleton of a valid html document*). However I accept that abusing the mkdir
command would likely lead to unforeseen/predictable edge-cases and consequences, so probably the best compromise is a script of some kind.
With the above in mind, I created the following (naive/simple) script:
#!/bin/bash
mkdir $@
cd $@
mkdir css img js
touch index.html
I call the above script as follows:
./createDir.sh projectName
This works but is less than ideal; the problems:
- the created
index.html
has a type ofplain text document (text/plain)
, rather than the expectedHTML document (text/html)
, and of course - has none of the structure of an HTML document (as outlined in the single footnote), because I didn't add any content (and haven't yet found a way of creating said content in a script).
Also, somewhat predictably, both the css
and js
directories would also – ideally – be created with documents (project.css
and project.js
) intact.
So, is there a means by which I can create – with the use of a script, or otherwise – a directory with its subdirectories and documents?
*. As a rudimentary example:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="js/project.js"></script>
<link href="css/project.css" rel="stylesheet" />
</head>
<body></body>
</html>