LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 05-17-2013, 05:29 PM   #1
hugheskc@yahoo.com
LQ Newbie
 
Registered: May 2013
Posts: 2

Rep: Reputation: Disabled
Smile list pwd sub-directories that have *.lst files


I need a script that will do the fallowing:

Start with the PWD and find a sub-directory with a *.lst file in it and count the number of *.lst
files and sum their bytes. then output the files, bytes, and directory sorted from smallest
two largest number of files. In the below example the ad directory has 20 files that consume
4.8m of disk space.

NOTE: The admin sub-directory tree does not have any *.lst files in it. That is why
it is not in the output even though it is a sub-directory to the PWD.

files bytes directory
-------- ----- -----------------------------
20 4.8m /app/oracle/agent11g/ldap/schema/ad/
220 32m /app/oracle/agent11g/ldap/schema/oid/
350 483m /app/oracle/agent11g/plsql/
428 572m /product/11.2.0.2.3/bin
560 1032m /diag/SEAPRRS/RPT
 
Old 05-17-2013, 06:38 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,658

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by hugheskc@yahoo.com View Post
I need a script that will do the fallowing:

Start with the PWD and find a sub-directory with a *.lst file in it and count the number of *.lst
files and sum their bytes. then output the files, bytes, and directory sorted from smallest
two largest number of files. In the below example the ad directory has 20 files that consume
4.8m of disk space.

NOTE: The admin sub-directory tree does not have any *.lst files in it. That is why
it is not in the output even though it is a sub-directory to the PWD.

files bytes directory
-------- ----- -----------------------------
20 4.8m /app/oracle/agent11g/ldap/schema/ad/
220 32m /app/oracle/agent11g/ldap/schema/oid/
350 483m /app/oracle/agent11g/plsql/
428 572m /product/11.2.0.2.3/bin
560 1032m /diag/SEAPRRS/RPT
We'll be glad to help...so post what you've written/tried so far, and tell us where you're stuck. But this isn't the place to come to have your homework done for you.
 
2 members found this post helpful.
Old 05-17-2013, 06:38 PM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,
Quote:
Originally Posted by hugheskc@yahoo.com View Post
I need a script that will do the fallowing:
<snip>
ok, how far did you get in writing it. Are you stuck somewhere? Having a specific problem?

Cheers,

Evo2.
 
1 members found this post helpful.
Old 05-17-2013, 07:10 PM   #4
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
I'll give you a few hints.

The find command can find directories. It can also find files matching a pattern like *.lst

The wc command can be used to count items in a list.

The sort command can be used to sort a list.

The du command can total up file sizes.

Lists can be processed with a "while read" loop, like I showed you in answering your other post:
Code:
#!/bin/bash
find . -maxdepth 1 -mindepth 1 -type d | while read -r file
do
du -sh "$file"
done
Good luck! We're here to help.
 
Old 05-19-2013, 10:33 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate. Please, follow discussion in your other thread: http://www.linuxquestions.org/questi...ed-4175462409/. Moreover take in mind that you can change (improve) the content of your posts using the EDIT button in the lower-right corner of the post itself.
 
  


Closed Thread



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
List directories and number of files inside them. arizonagroovejet Linux - General 4 03-20-2011 10:33 AM
system call to know the files and directories in pwd ( alternative to ls command ) vlrk Linux - Newbie 1 03-03-2010 06:30 PM
how to list the number of files in serveral sub-directories cy163 Linux - Newbie 2 05-16-2009 11:29 AM
List all files in multiple directories haiders Linux - Newbie 6 05-10-2007 12:05 PM
Getting a list of directories with certain files inside... Banacek Linux - Newbie 7 11-27-2006 05:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:36 PM.

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
Open Source Consulting | Domain Registration