nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Shell scripting loop through folders in directory

This is a discussion on Shell scripting loop through folders in directory within the Shell scripting forums, part of the Development/Scripting category; Hi, How do I UNIX / Linux shell scripting to loop through folders in directory? I would like to go ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 20-02-2009, 01:59 AM
raj's Avatar
raj raj is offline
Senior Member
User
 
Join Date: Jun 2005
Location: Hyderabad
OS: Fedora, Debian Linux
Posts: 307
Thanks: 42
Thanked 8 Times in 8 Posts
Rep Power: 6
raj will become famous soon enough raj will become famous soon enough
Default Shell scripting loop through folders in directory

Hi,

How do I UNIX / Linux shell scripting to loop through folders in directory? I would like to go though all files in my folder in a directory and process those files one by one.

TIA
__________________
Raj
Linux rulz.
I have never turned back in my life ; I shall not do so today.. haha
Reply With Quote
  #2 (permalink)  
Old 20-02-2009, 05:37 AM
Junior Member
User
 
Join Date: Feb 2009
OS: Debian
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
ravisola is on a distinguished road
Default

Hi Raj,

Did you try using something like

#ls -lR

The 'R' switch does a recursive listing
# ls --help|grep '\-R'
-R, --recursive list subdirectories recursively

You can then build a logic of your own to process the files. So for eg a command like

#ls -lR mydir

will list all the folders within mydir recursively. The folders are usually followed with the number of files and then the file listings and so on.
Reply With Quote
  #3 (permalink)  
Old 20-02-2009, 04:22 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

You can use for loop or find command for the same. See our FAQ:
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Learning Shell Scripting ricc Shell scripting 5 02-04-2009 03:11 PM
Shell for loop to determine whether it is a file or a directory tusk222 Shell scripting 1 29-11-2008 12:23 AM
shell scripting with SMTP Tinku Shell scripting 2 22-10-2008 10:42 AM
need help on shell scripting rahul_sayz Shell scripting 1 08-12-2007 10:37 AM
Shell script to restructure folders recursively kalt Shell scripting 2 26-10-2007 12:47 AM


All times are GMT +5.5. The time now is 04:32 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38