Recursive looping through files and directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Recursive looping through files and directories
# 1  
Old 07-21-2011
Recursive looping through files and directories

hi;
i need a script which will go to all directories and subdirectories and print the filenames as follow;
here i m printing only files listing in current directory
reason i m doing this is coz i want to perform some operations according to filename achieved so cant use find command;
Code:
#!/bin/bash
LOG_DIR="/home/fstl/testShell"
cd $LOG_DIR
for f in *
do
  filename=$f
  echo "$filename"
done

thnks;

Last edited by Franklin52; 07-21-2011 at 06:49 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-21-2011
Code:
find LOG_DIR -type f

# 3  
Old 07-21-2011
Hi
i need this variable somewhere;

filename=$f

so that i will directly perform an action on it/commands on it
so find wont do much.
# 4  
Old 07-21-2011
Code:
 
find LOG_DIR -type f | while read filename; do echo $filename; done

# 5  
Old 07-21-2011
thnks u so much..Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recursive search for files and copy to new directories

So I have extremely limited experience with shell scripting and I was hoping someone could point out a few commands I need to use in order to pull this off with a shell script like BASH or whatnot (this is on OS X). I need to search out for filenames with account numbers in the name itself... (3 Replies)
Discussion started by: flyawaymike
3 Replies

2. Shell Programming and Scripting

Looping for multiple directories

Hi experts, I am totally stuck with this. I run a looping "for" command for multiple directories, manually, I have done this : vfor dir in A B; do cp -p $dir/X.txt X-${dir}.txt done where A and B is directory name. However, I need to run for many directories. So I have tried this :... (7 Replies)
Discussion started by: guns
7 Replies

3. Shell Programming and Scripting

Logic needed to recursive looping in the script

Hello i have a requirement where in a file i will get string. The length could be from 1 to 20. if the string is less than 6 characters ( ex: ABCD) . i need to append 'X' on right hand side to make it 6 characters (ex: ABCDXX). if suppose i get the same string from the file as ABCDXX then i... (5 Replies)
Discussion started by: dsdev_123
5 Replies

4. Shell Programming and Scripting

Command to sort directories after a recursive find

find -type d -name "TC_*" | sort That's what I have so far... it finds the appropriate directories and then sorts them. But, when it comes to nested subdirectories, it only sorts relative to the first subdirectory. I want it to sort based on the directory at the end of the path. Does anyone know... (3 Replies)
Discussion started by: crimsondarkn
3 Replies

5. AIX

recursive archive directories and subdirectories

Hi everyone, Maybe this is simple question for many of you, but I get confused.:confused: How to archive a parent directory which contains some subdirectories and some files? I have searched this forum, there are some commands like tar,etc, I tried but can not be implemented in my system.... (6 Replies)
Discussion started by: wilsonSurya
6 Replies

6. Shell Programming and Scripting

Problem with looping the directories

Hi all, I have a directory which has many sub-directories. Now, I want to check the space of each dir and redirect the output in a file if space exceeds the limit. I have already done it, but the way I did is not very good. I just listed the directories and awked the last column to get the... (5 Replies)
Discussion started by: naw_deepak
5 Replies

7. Shell Programming and Scripting

Recursive call to find files and directories in Shell script from current path.

################################################################ Copy this script to your path from where you want to search for all the files and directories in subdirectories recursively. ################################################################# code starts here... (2 Replies)
Discussion started by: Ramit_Gupta
2 Replies

8. Shell Programming and Scripting

Script problem due to recursive directories Help please

Hello everyone , I am looking for a better solution then the one I have created for the my Task The task is: Create an automated script that will check for Uploads in a specified Directory and move them to another specified Directory if the files are completely uploaded. Files are FTP'd to... (2 Replies)
Discussion started by: robertmcol
2 Replies

9. UNIX for Advanced & Expert Users

recursive chmod that only affects directories?

The man page for chmod doesn't list a way to recursively change permissions on directories only, without affecting the files themselves. Let's say that I wanted to change the permissions on the current directory and all subdirectories. I know I can write a bash script that would do this using... (1 Reply)
Discussion started by: retrovertigo
1 Replies

10. UNIX for Dummies Questions & Answers

grep recursive directories

I am trying to locate a file or files with specific data in them. Problem is the file(s) could reside in any one of many directories. My question is. Is there a way of recursively greping directories for the file(s) with the data I am looking for. I have tried - 1. $HOME> grep 47518 | ls... (8 Replies)
Discussion started by: jagannatha
8 Replies
Login or Register to Ask a Question