how to create new dir fro a file list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to create new dir fro a file list
# 1  
Old 09-11-2006
how to create new dir fro a file list

Hi,

What will be the best way to do the follwing:
i have a file calld dir.list
/cav
/cav/brif
/usr/main
/cat

i want to run a script that will take each of the item in the file and create a new dir in a location that i'll choose

it nee to do mkdir cav
mkdir cav
cd cav
mkdir brif
......

thanks
# 2  
Old 09-11-2006
I guess you need something like this:

Code:
for directory in `cat directories.txt`
do
    mkdir directory;
done

# 3  
Old 09-11-2006
Try:
Code:
#! /bin/ksh

curdir=`pwd`

while read path; do
if [[ ! -d $curdir$path ]]; then
mkdir -p $curdir$path
fi
done < dirlist

Note: Above code is as per your given sample which has a "/" at the begining of each line.

Regards,
Tayyab
# 4  
Old 09-12-2006
Well what i need is multiple creat for dir

i need to create the all path

/cav/usr/mmm/t

i need to create /cav
after that create the /cav/usr
and then /cav/usr/mmm

how can i do that from a script that will read the dir to creates from a file that will look like that:
/cav/usr
/benny/ddd/t
/usr/clear
/cacac/hhttt/to
.....


Thanks a Mil
# 5  
Old 09-12-2006
Have you tried to use shereenmotor's script? Does it do what you want? If it does not, then can you explain where it is failing?
# 6  
Old 09-12-2006
something like this, maybe?

awk '{print "mkdir "$1}' file | sh
# 7  
Old 09-12-2006
A solution that doesn't need the combined horsepower of awk and a new shell is probably more efficient.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script fro file check and load the trail file

Hi, Im going to use shell script for load the data into DB. First i need to read the trail file(csv file has two columns with comma separated ) like file name trail1024(last 4 digitsMMDD). In this trail file 27 entries will have like below,I need to read first csv file name and get the 4... (1 Reply)
Discussion started by: krajasekhar.v
1 Replies

2. UNIX for Dummies Questions & Answers

How do I create a tar file for only dir and its subdir structures??

How do I create a tar file for only dir and its subdir structures?? (4 Replies)
Discussion started by: vx04
4 Replies

3. Shell Programming and Scripting

Unable to list particular file in dir.

Hi i am trying to list all the file starting with CSA.CHENAISCP* i am using below command to do that ls -lrt | grep CSA.CHENAISCP*however i am getting below error. 0403-027 The parameter list is too long.please suggest me some alternative way. scriptor (3 Replies)
Discussion started by: scriptor
3 Replies

4. Red Hat

How to create a command to enter into a dir?

Hi all, I want to create a command for entering into a specific dir. for eg if i want to go to /var/spool/postfix/pid at any point if i enter a command suppose "sp" in the command line it should take me to /var/spool/postfix/pid thanks (2 Replies)
Discussion started by: technoman
2 Replies

5. Shell Programming and Scripting

Create file Dir and Sub Dir same time

Hi Guys , I want create files Dire and Sub Dire. as same time using variable. EX: x1="/hk/Pt/put/NC/R1.txt" x2="/hk/pt/Put/Ot/NC/RN.txt" And i want delete all after done with my script. Thanks (2 Replies)
Discussion started by: pareshkp
2 Replies

6. Shell Programming and Scripting

how to list of file in home dir ?

I want to print all list of file in the home dir of the user in $i with full bath an owner and group and permissions (1 Reply)
Discussion started by: testman84
1 Replies

7. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

8. UNIX for Dummies Questions & Answers

Copying dir (and sub dir) file names from ftp server to txt file in diff server

Hey all, i want to copy only the file names from an ftp server (directory and all sub directory) to a text file in another server (non ftp), i.e. i want to recursively move through directories and copy only the names to a text file. any help is appreciated...thank you in advance (1 Reply)
Discussion started by: deking
1 Replies

9. Shell Programming and Scripting

List file in Dir and then match

Hi ALL, I am making a script that search all then worldwriteable dir in documentroot.I have manage to find all the dir now i want to match each file extension in worldwriteable against a list of array which contain file like php html etc,if i find any file then print dirname. Dont see to get any... (8 Replies)
Discussion started by: aliahsan81
8 Replies

10. UNIX for Dummies Questions & Answers

Searching list of entries in file for actual files in dir

Hi all, I have a file entries.txt that contains a number of entries all on seperate lines e.g. test1 test2 test3 test4 Then in a directory called /TestFiles I have a number of files that could contain the above text in the file name e.g. qwertytest1.csv qwertytest2.csv... (2 Replies)
Discussion started by: not4google
2 Replies
Login or Register to Ask a Question