Visit Our UNIX and Linux User Community

Looping through the directory

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looping through the directory
# 1  
Old 11-22-2006
Question Looping through the directory

I have to write a KSH script to loop through the directory and transfer all the files through FTP. The source machine is the Network shared drive and the files in the directory needs to be FTPied to the UNIX server.

For eg. Directory (Datasource)
+ Directory1
+ Directory2

How to loop through the above directory structure.

Please help me out.

# 2  
Old 11-22-2006
can anybody help me out on this.
# 3  
Old 11-22-2006
Please read the rules of the forum Smilie

Looping through the directory -- does that mean all the files to be transferred starting from a specific directory ???

If that is the requirement, use find command to list all the files that are to be transferred and build a ftp script for that.

this could be done on the run and no multiple manual intervention would be needed.

With the available list of selected files,
prepare ftp commands like

put file1
put file2

this is just a pointer Smilie

hope this helps Smilie
# 4  
Old 11-22-2006
Perhaps there is something useful in the FAQs?
# 5  
Old 11-22-2006
I had written the script to transfer the files through FTP. So I wanted to know about how to loop through the directory.

Can anybody help me with an example script.

# 6  
Old 11-22-2006
TEMP1=`ls -1 >$MYDIR/temp1`

for i in `cat $TEMP`
        echo $i  # file name which resides in $MYDIR directory
        echo " you can do something with files"
        bla bla bla

I think this the code you are looking for
if not ...pls post your code, we try to give the solution..

# 7  
Old 11-23-2006
Yesterday the scripts which I had got is not working. Can anybody help me out with some examples.

Previous Thread | Next Thread
Test Your Knowledge in Computers #273
Difficulty: Easy
In December 1939, Turing solved the essential part of the naval indicator system, which was easier and less complex than the indicator systems used by the other services.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping through entire directory and count unique values

Hello, I`m a complete newbie to coding, please help with this problem. I have multiple files in a directory, I have to loop through the contents of each file and extract number of unique isoforms in that file. Each file is tab delimited and only the line with the first parent (column 3)... (1 Reply)
Discussion started by: ritakadm
1 Replies

2. Shell Programming and Scripting

Looping inside directories based on a file which contains file directory list

Hi All, Please help. I have got a file which contains a listing of a file and some directories after it, one by one. I am calling this file xyz.txt here file1 dir1 dir2 dir3 dir4 file2 dir5 dir6 dir7 dir8 file3 dir9 dir10 dir11 dir12 (6 Replies)
Discussion started by: Piyush Jakra
6 Replies

3. Shell Programming and Scripting


Hi evryone i need a help . i have a file xcv.the content is : accelerate i want a script which will run 1000 times in loop and changing the value to accelerate to acceler in 1st loop and in 2nd loop it will be again accelerate and so on . (6 Replies)
Discussion started by: Aditya.Gurgaon
6 Replies

4. Shell Programming and Scripting

running a looping script for all files in directory

I have three different linux command scripts that I run for 20+ files in one directory. it goes like this FIRST SCRIPT: grep 'something' -w file > newfile1 . . . grep 'something -w file > newfile20 then I take all these 'newfileN' and run this: awk 'BEGIN {... (20 Replies)
Discussion started by: labrazil
20 Replies

5. Shell Programming and Scripting


Hi, Now I have written a script which sorts the records in the file and splits them according to some condition. Now, I need to modify the script so that it reads all the files one after the other and does the sorting & splitting. Pls help me in reading all the files in a directory and... (8 Replies)
Discussion started by: Sunitha_edi82
8 Replies

6. Shell Programming and Scripting

looping thru filenames in a directory

Hi, i am very new to UNIX, i am trying to loop thru the files in a directory. I got the filenames into a variable using $files=`ls` Here $files will contain <filename1> <filename2> <filename3> I want to get one filename at a time and append it to some some text. forexample, ... (1 Reply)
Discussion started by: silas.john
1 Replies

7. Shell Programming and Scripting

help on looping using if/for or while

Hello, where can I get usefull information on the use of looping with for , if and while with extensive examples. Also use of variables in scripts (1 Reply)
Discussion started by: sam4now
1 Replies

8. Shell Programming and Scripting

for looping

I run into a issue when I try to do sorting of the following with ascending order, one round of for looping seems not working, anyone knows how to use shell or perl? $array = (5,0,3,2,7,9,8) (2 Replies)
Discussion started by: ccp
2 Replies

9. Shell Programming and Scripting

rm files in a directory, looping, counting, then exit

I am trying to write a script that will look for a file in a directory, then remove it. I need it to loop until it has removed a certain number of files. Is it better to do a repeat or to list each file in a pattern? Files will be numbered like RAF.01.*, RAF.02.*, etc. Thanks, James (6 Replies)
Discussion started by: JporterFDX
6 Replies

10. UNIX for Dummies Questions & Answers

Help with looping

Hi, Actually I have a file which consists data . for eg names. Then I want my sql query to read this file and produce the output. Currently I am using this FOR EG : FILENAME is NAMES for i in `cat NAMES` { sqlplus -s $CONNECTID << EOF spool rooh set heading off select... (1 Reply)
Discussion started by: rooh
1 Replies

Featured Tech Videos