LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-04-2008, 12:00 PM   #1
disruptive
Member
 
Registered: Dec 2005
Posts: 76

Rep: Reputation: 15
scripting, number of subdirectories in a subdirectory


I have a number of questions:

1. How do I calculate the number of sub-directories within a particular directory, such that I can loop through all of those directories and perform some action.

2. With a file of data containing two columns, how would I pull out the last column, last row data into a variable?

Thanks
 
Old 06-04-2008, 02:42 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 76
  1. You can do “find -type d” to get all directories.
  2. You can do this a few ways. Here it is in awk:
    Code:
    awk '{a = $2};END{print a}'
 
Old 06-04-2008, 04:33 PM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,432

Rep: Reputation: 203Reputation: 203Reputation: 203
yes well, if you know the depth you can do,

Code:
for dir in */*/   # the trailing / means dir, try it with ls */
do
   (cd $dir; pwd) # in a subshell so the cd is forgotten
done
or as osor said
Code:
find . -type d |
while read dir; do
   (cd $dir; pwd)
done
count is simple: find . -type d -print | wc -l

Last edited by bigearsbilly; 06-04-2008 at 04:35 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] shell scripting: How can I increment a file by number dv502 Programming 11 08-27-2010 08:43 AM
bash scripting : printing variable with the number within $i amdGTintel Programming 2 01-18-2007 01:30 AM
where is my subdirectory blotch Linux - Newbie 22 06-18-2005 11:43 AM
Shell Scripting: How to pick lines out of files by line number. Louie55 Programming 3 03-22-2005 06:18 PM
Bash Scripting (subdirectories) bendeco13 Linux - General 4 10-07-2004 12:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration