Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Automating creation of directories

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-10-2012
sharone sharone is offline
Registered User
 
Join Date: Feb 2012
Last Activity: 10 February 2012, 1:30 PM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Automating creation of directories

I have a top-level directory called work and I would like to create subdirectories work1 work2... under this directory. Also I would like to create subdirectory under work1 -- test, work2 -- test etc., Can I automate this using a command-line script?


Code:
work 
|_work 1
    |_test
|_work 2
    |_test 
|_work 3 
    |_test

Sponsored Links
    #2  
Old Unix and Linux 02-10-2012
zaxxon's Unix or Linux Image
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 3 July 2015, 9:38 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,308
Thanks: 135
Thanked 468 Times in 422 Posts
Check the -p -switch of the mkdir -command. Instead of feeding a script in a while/read loop with a directory structure, you could just write the same with this command. Should be the same amount of typing. Is this homework?
Sponsored Links
    #3  
Old Unix and Linux 02-11-2012
chihung chihung is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 31 July 2012, 10:08 PM EDT
Location: Singapore
Posts: 191
Thanks: 3
Thanked 46 Times in 45 Posts
you can use shell braces to let shell to expand all the arguments. suppose you want to create w1/t1 w1/t2 w2/t1 w2/t2 w3/t1 w3/t3 directories


Code:
mkdir -p {w1,w2,w3}/{t1,t2}

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Symbolic link creation between 2 directories on different machines Amit Kulkarni HP-UX 3 01-05-2012 03:48 AM
List directories with given string, sort by creation date Siva SQL UNIX for Dummies Questions & Answers 3 10-27-2011 05:44 AM
Creation of multiple directories rajeshnatarajan Shell Programming and Scripting 4 05-11-2010 06:35 AM
Script for parsing directories one level and finding directories older than n days ejianu Shell Programming and Scripting 5 08-26-2009 11:24 AM
Automating creation of sub-domains??? elduderino UNIX for Dummies Questions & Answers 0 07-11-2008 06:02 PM



All times are GMT -4. The time now is 10:42 PM.