next up previous contents
Next: Delete Up: Basic Directory Commands Previous: List   Contents

Create

To create a subdirectory within the current (default) directory use mkdir (make directory) e.g.:-

mkdir work
creates a work directory below the current directory. An alternative way to create a directory is to use the copy command cp with the -r option e.g.:-
cp -r d1 d2
This copies the contents of the directory d1 (including the entire subtree of directories it contains) into directory d2 preserving the directory structure. If d2 does not exist it is created and used as the top level directory for the subtree. If d2 does exit then the directory d2/d1 is created and used as the top level. This is very powerful and must be used with caution, it is better for the beginner to create d2 and then just copy one directory at a time e.g.:-
cp d1/* d2
A classic mistake with cp -r is to have d2 as a directory within the subtree supported by d1, such a copy can loop until all disk space has been exhausted!



P.D. Gronbech (IT Staff) 2015-10-02