Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Automating creation of directories

Shell Programming and Scripting


Closed    
 
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: 23 November 2016, 10:12 AM EST
Location: St. Gallen, Switzerland
Posts: 6,504
Thanks: 162
Thanked 533 Times in 466 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

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 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 07:48 AM.