Unix Create Directory Structures

How to create directory structure in Unix?

#!/bin/sh

<<COMMENT1 

This script can run from its saved location as ./scriptname.sh foldername it will create a folder structure based off of foldername in the Users Home directory, adjust to suit your needs also remember to chmod u+x

COMMENT1

mkdir -p ~/$1/copy

mkdir -p ~/$1/layers

mkdir -p ~/$1/stock
 

Notes:

Make a Directory

To make a directory, use the mkdir (make directory) command. Enter: 

mkdir  directory

This will make a directory with the name you specify.

To make a directory for your chemistry papers and assignments, enter: 

mkdir Chemistry

This makes the directory named Chemistry. If you begin your directory names with a capital letter, they are easier to distinguish from your file names.
 

Further notes:

Creating Directories

mkdir (make directory)

You can make a subdirectory of your home directory for your own data files. To make a subdirectory called unixtraining in your current working directory type:

% mkdir unixtraining 

To see the directory you have just created, type:

% ls

You can also make a hidden directory if you want to. Use a dot as the first character of the directory name for it to be hidden.
 

Creating down a path

Surprisingly often you want to create a directory but not directly at your current position in the directory tree. Suppose I am in my home directory and I want to create directories to hold some files for two courses but in

~/documents/2013/IT/training/Unix/

The first course is an introduction to Linux, second an introduction to Solaris. I can create these directories like this:

% mkdir ~/documents/2013/IT/training/Unix/Linux

and

% mkdir ~/documents/2013/IT/training/Unix/Solaris

Naturally, you don't have to specify the complete path from ~, but I have done so here for clarity.
 

Creating a whole path:

mkdir -p

Perhaps less often you want to create not a single directory but rather a directory subtree - that is a directory and directories beneath it. Suppose I am in my home directory and I want to create directories to hold some files for two courses: Redhat for Beginners and Advanced Redhat. We can do this with the -p option on the mkdir command.
 

Here is the command to create the first directory:

% mkdir -p ~/documents/2013/IT/training/Unix/Linux/Redhat/beginners/
 

This creates the two directories we require in one go. We can then issue the command

% mkdir ~/documents/2013/IT/training/Unix/Linux/Redhat/advanced

Notice the difference between these two.

Unix

See Also
About Directories

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.