Simple Script to create folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Script to create folders
# 1  
Old 10-10-2009
Simple Script to create folders

Hi

I want to write a small script that will create folders named from `AAAA' all the way to `ZZZZ'.

That is:
`AAAA'
`AAAB'
`AAAC'
...
`AABA'
`AABB'
`AABC'
...
`ABAA'
`ABAB'
`ABAC'
...
`ABBA'
...
`ZZZZ'

Any ideas?
# 2  
Old 10-10-2009
Example for bash
Code:
for i in {A..Z}{A..Z}{A..Z}{A..Z};do mkdir $i;done

# 3  
Old 10-10-2009
Quote:
Originally Posted by danmero
Example for bash
Code:
for i in {A..Z}{A..Z}{A..Z}{A..Z};do mkdir $i;done

Sorry I'm a complete novice and may have done something wrong. I tried exactly what you had written above. It only seems to create a folder title `{A..Z}{A..Z}{A..Z}{A..Z}'.

Update
I realized it would be easier to do this with numbers (the names of the folders don't matter to me as long as they're sequential), so I wrote this:
Code:
for ((i = 0; i <= 9; i++))
do
  for((j = 0; j <= 9; j++))
  do
    for((k = 0; k <= 9; k++))
    do
      for((l = 0; l <= 9; l++))
      do
        for((m = 1; m <= 9; m++))
        do
          mkdir "$i$j$k$l$m" #This will create the folders
        done
      done
    done
  done
done


Last edited by ksk; 10-10-2009 at 01:52 AM..
# 4  
Old 10-10-2009
Hi.

The solution from danmero works perfectly (in bash, ksh and in csh).

If you want to use numbers, this would be quicker I tbink:

Code:
printf "%04d\n" $(seq 0 9999) | xargs -I{} mkdir {}

(you should - but may not - have seq on your system!)

Why do you have five for loops? If hope you have 100,000 free inodes!

Last edited by Scott; 10-10-2009 at 09:32 AM..
# 5  
Old 10-10-2009
Code:
$ cat filename.pl
for (AAAA..ZZZZ)  {
    mkdir $_;    
}

The above perl script will do, store and run it as
Code:
$ perl filename.pl

Or run from your command line itself.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Urgent- shell script to create sub folders

Hi All, Could any one help me with a shell script which will create different sub folders in a folder and of which the sub folders names should be taken from a text file. Thanks (1 Reply)
Discussion started by: chetansingh23
1 Replies

2. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

3. Shell Programming and Scripting

Create simple script

Dear all, I have a directory named A and some subdirectories named B, C, D with .xml files. I want to use the following command to strip the file. sed -re ':start s/<*>//g; /</ {N; b start}' file.xml > file.xml At the same time, I want to remove the blank lines using sed '/^$/d' How can... (6 Replies)
Discussion started by: corfuitl
6 Replies

4. UNIX for Dummies Questions & Answers

script to create folders

hi again, having an issue with the code here because it doesnt work :D can someone point what and how to change, please. #!/bin/bash #create directory mylabs, inside create 6 directories named by user. DIR1="$1" DIR2="$2" if ; then echo -n " there is a folder named mylabs, what... (1 Reply)
Discussion started by: me.
1 Replies

5. Shell Programming and Scripting

How to create a simple copy script?

Guys I want to do this: copy: /var/router/system1/config/backup/install.put /var/router/system2/config/backup/install.put /var/router/system3/config/backup/install.put /var/router/system4/config/backup/install.put into: /var/router/system1/config/install.dat... (22 Replies)
Discussion started by: DallasT
22 Replies

6. Shell Programming and Scripting

Need to create a simple script using MD5, SSH...

Hi all, I am brand new to these forums and I am a brand new UNIX Administartor. Don't know any scripting yet :wall:, and would like to learn as my boss is slowly letting me understand everything about being a Sys/*Nix Admin. He created this script which I am trying to replicate because I lost it... (54 Replies)
Discussion started by: zixzix01
54 Replies

7. Solaris

How to create a simple background script on Solaris

I have a local account for a unix server. The idle timeout for the account is around 10 mins. I have to login to the server multiple times during the day. Is there a way to increase the idle timeout or may be a script that I can run on background so it is not idle. Something like echo date every 9... (3 Replies)
Discussion started by: vinaysa
3 Replies

8. Shell Programming and Scripting

Create A Simple GUI For Shell Script

Hi all! Im wondering if its possible to create a GUI for a shell script I just got done writing as the people that will be using it dont like the command line all to well. Just something simple with radio buttons to select options, maybe a text field to enter a location to save the file generated... (1 Reply)
Discussion started by: Grizzly
1 Replies

9. Shell Programming and Scripting

Need to create a script to show what files in what folders

Hi everyone, I'm stuck with this scenario where our system creates files every night and puts them in several folders according from whom it came from. I have managed to create a script which will list the folders in one column and the files that are in them in another column, now my problem... (6 Replies)
Discussion started by: kumaran21
6 Replies

10. Shell Programming and Scripting

Modifying simple commands to create a script

Can anyone direct me to a resource that explains scripting in simple terms? I have visited many sites and browsed this forum and have yet to find simple explanations. (8 Replies)
Discussion started by: rocinante
8 Replies
Login or Register to Ask a Question