Sponsored Content
Full Discussion: Loop through directory names
Top Forums UNIX for Dummies Questions & Answers Loop through directory names Post 302837305 by Corona688 on Thursday 25th of July 2013 01:27:10 PM
Old 07-25-2013
* will match directory and file names alike, so you can handle it exactly the same way.

30,000 files may easily be too many to fit into *, however. You could use ls with a read loop instead. Just beware that variables you change inside the 'while read' loop will not be affected outside the loop, because of the pipe.

Code:
for DIR in *
do
        [ -d "$DIR" ] || continue # Skip non-directories

        ls $DIR | while read FILE
        do
                do_something_to "$DIR/$FILE"
        done
done

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Use of $ in directory names

I have a TAR (compressed) file that I uncompressed using the following command $ tar xvf uagent.tar It created a directory structure as follows <root>/arcagent/UAGENT/reloc/$UAGENT_HOME/ How do I access files under the $UAGENT_HOME? Every time I do change directory command, the OS... (3 Replies)
Discussion started by: pkappaz
3 Replies

2. Shell Programming and Scripting

File Names in a Variable in a loop

Hi All , I am having confusion in a shell script. Please guide me. I need to get multiple files (number of files vary time to time, file names are separated by '|') using FTP get from the remote server. Actually, i call the FTP function in a loop. At the last step, i need to move all the get... (3 Replies)
Discussion started by: spkandy
3 Replies

3. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

4. UNIX for Dummies Questions & Answers

How to display only Owner and directory/sub directory names under particular root

hai, I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc". (here "oasitqtc" is the owner of the directory or sub directory.) i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies

5. UNIX for Dummies Questions & Answers

Loop through directory and extract sub directory names

I am trying to loop through folders and extract the name of the lowest level subfolder I was running the script below, it returns /bb/bin/prd/newyork /bb/bin/prd/london /bb/bin/prd/tokyo I really want newyork london tokyo I couldn't find a standard variable for the lowest level... (1 Reply)
Discussion started by: personalt
1 Replies

6. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Writing a loop to changing the names of files in a directory

Hi, I would like to write a loop to change the names of files in a directory. The files are called data1.txt through data1000.txt. I'd like to change their names to a1.txt through a1000.txt. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

8. Shell Programming and Scripting

How to make dynamic variable names for use in while loop?

i=0 while do sizesfor0=`cat 16 | grep 'pickSize' -A 1 | grep '_sz' | cut -d'_' -f1` sizesfor0=${sizesfor0//id=\"lll/:} IFS=: array0=( $sizesfor0 ) echo ${array0} i=$(( $i + 1 )) done So, right now I have two variables in the while statement above sizesfor0 and array0 The... (1 Reply)
Discussion started by: phpchick
1 Replies

9. Shell Programming and Scripting

Print file names in a loop

OS : RHEL 6.1 Shell : Bash I have lots of files in /tmp/stage directory as show below. Using a loop, I need to print all the filenames in this directory except those ending with a number. How can I do this ? # pwd /tmp/stage # # # ls -l * -rw-r--r--. 1 root root 0 Oct 7 18:38 stmt1... (2 Replies)
Discussion started by: kraljic
2 Replies

10. Shell Programming and Scripting

Using nested for loop to iterate over file names

I'm trying to grab a list of file names from a directory, then process those files 5 at a time. In the link below. Instead of using files I'm using the files array which contains 15 strings starting with AAA. So I'm trying to assign $fileset 5 of the strings at a time to pass to a command. So... (4 Replies)
Discussion started by: zBernie
4 Replies
REPORTER-PRINT(1)						 LIBREPORT MANUAL						 REPORTER-PRINT(1)

NAME
reporter-print - Prints problem information to standard output or FILE. SYNOPSIS
reporter-print [-v] [-d DIR] [-o FILE] [-a yes/no] [-r] DESCRIPTION
The tool reads problem directory DIR and prints its text representation to stdout or to a specified FILE. Integration with ABRT events reporter-print can be used as a reporter, to allow users to report problems by writing them to a file. Example: EVENT=report reporter-print -o "${Log_File:-/tmp/abrt.log}" OPTIONS
-d DIR Path to problem directory. -v Be more verbose. Can be given multiple times. -o FILE Output file -a yes/no If -o FILE is specified, controls whether FILE is appended to, or overwritten. (default: no) -r Add a record to reported_to in DIR which specifies that this problem was reported. Some tools use this to differentiate between problems which were and weren't yet reported. Output format The output is designed to be machine-parsable. The elements which have only one line are printed in the form NAME:<whitespace>VALUE Elements which have more than one line are printed in the form NAME: :LINE1 :LINE2 :LINE3 Output may contain empty lines for better readability. AUTHORS
o ABRT team LIBREPORT 2.1.11 06/18/2014 REPORTER-PRINT(1)
All times are GMT -4. The time now is 10:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy