Shell - How to iterate through all the files in a directory?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell - How to iterate through all the files in a directory?
# 1  
Old 03-19-2009
Shell - How to iterate through all the files in a directory?

Hi,

I have a directory call Test, which contains files "a", b", "c", etc. I want to go through all of the files inside Test and remove any empty file. How would I do that with shell csh?

So far I got...

Code:
#!/bin/csh

if (($#argv == 0) || ($#argv > 1)) then
   echo "no argument or too many"
   exit 1
else 
   if (-d $argv[1]) then              # the argument is a directory
      ..........

# 2  
Old 03-19-2009
use the find command. check your man page.
# 3  
Old 03-19-2009
Nvm. I figured it out. I needed to put all the files into an array and do a while loop.

Last edited by teiji; 03-20-2009 at 01:01 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving Files one directory to another directory shell script

Hi, Could you please assist how to move the gz files which are older than the 90 days from one folder to another folder ,before that it need to check the file system named "nfs" if size is less than 90 or not. If size is above 90 then it shouldn't perform file move and exit the script throwing... (4 Replies)
Discussion started by: venkat918
4 Replies

2. Shell Programming and Scripting

Shell Scripting on files in directory

Hi, The requirement is below: There are 5 files in a unix directory and i need to pick up latest file from the directory that i can do like this ls -lrt | tail -1 and this file can be processed. now the actual requirement is some times what will happen the second third...on files i.e(ls -lrt... (4 Replies)
Discussion started by: prawinmca
4 Replies

3. Shell Programming and Scripting

How to check whether directory has files in it or not in shell script?

hi, I am having script in which i want to check if directory has any file in it or not. If directory contains a single or more files then and only then it should proceed to further operations... P.S.: Directory might have thousand number of files. so there might be chance of getting error... (4 Replies)
Discussion started by: VSom007
4 Replies

4. Shell Programming and Scripting

Shell : deleting only first 2 files in a directory

I have 4 files in a directory and want to delete only first 2 files only.. $ ls -ltr total 640 -rw-r--r-- 1 user other 148779 Oct 12 10:50 file1.xls -rw-r--r-- 1 user other 148779 Oct 12 10:50 file2.xls -rw-r--r-- 1 user other 148779 Oct 12 10:50 file3.xls... (4 Replies)
Discussion started by: giridhar276
4 Replies

5. Shell Programming and Scripting

Help for shell scripts for moving all files from one directory to another

Hi , Can you please check this code .I am getting the follwing error while executing the script. Please help me out. #rm /tmp/$$ #!/bin/ksh dir_one="/usr/bin/sou" dir_two="usr/bin/sou/temp" for files in $dir_one/*.txt do ... (31 Replies)
Discussion started by: soumyamishra
31 Replies

6. Shell Programming and Scripting

Need script to count specific word and iterate over number of files.

Hi Experts, I want to know the count of specific word in a file. I have almost 600+ files. So I want to loop thru each file and get the count of the specific word. Please help me on achieving this... Many thanks (2 Replies)
Discussion started by: elamurugu
2 Replies

7. UNIX for Dummies Questions & Answers

Bourne shell viewing files in directory

Hi, I have a program that get a directory name from the user, then the program should go through one by one of the file, asking the user whether to move it to another folder. I tried to list the time of the file one by one. But it seems like it doesn't work. The code is as follow: check() {... (10 Replies)
Discussion started by: mInGzaiii
10 Replies

8. Shell Programming and Scripting

How do i iterate thru each line of a file in shell scripting?

Hi All, I need to execute some commands on each line of a file. How do i iterate thru each line of a file? In detail: First i will have to go to the first line of the file and execute a series of commands on it and then take the second line of the file, execute a series of steps and so... (2 Replies)
Discussion started by: Ravi Varma
2 Replies

9. Shell Programming and Scripting

iterate sed over files

Greetings. I'm having a time of it with this file. I'm trying to do a script that will take two command line inputs, string1 and string2 and use sed to change the text over files in the current directory. This is what I have so far. It appears to work a little, it does create the... (3 Replies)
Discussion started by: rdanda
3 Replies

10. Shell Programming and Scripting

shell script: deleting files from a directory

i have the following problem: use shell script: Two directories have to be searched for files havin the same name. then delete these files from one of these directories. the directory names have to be accepted as command line arguments. what i have done till now is: 1. run a loop... (1 Reply)
Discussion started by: onlyc
1 Replies
Login or Register to Ask a Question