Automating creation of directories | Unix Linux Forums | Shell Programming and Scripting

  Go Back    

Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Automating creation of directories

Shell Programming and Scripting

Closed Thread    
Thread Tools Search this Thread Display Modes
Old 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?

|_work 1
|_work 2
|_work 3 

Sponsored Links
Old 02-10-2012
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
Join Date: Sep 2007
Last Activity: 27 February 2015, 4:52 AM EST
Location: St. Gallen, Switzerland
Posts: 6,256
Thanks: 127
Thanked 455 Times in 414 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
Old 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

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

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 04:48 AM
List directories with given string, sort by creation date Siva SQL UNIX for Dummies Questions & Answers 3 10-27-2011 06:44 AM
Creation of multiple directories rajeshnatarajan Shell Programming and Scripting 4 05-11-2010 07:35 AM
Script for parsing directories one level and finding directories older than n days ejianu Shell Programming and Scripting 5 08-26-2009 12:24 PM
Automating creation of sub-domains??? elduderino UNIX for Dummies Questions & Answers 0 07-11-2008 07:02 PM

All times are GMT -4. The time now is 02:51 AM.