LinuxQuestions.org
Register a domain and help support LQ
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

Reply
 
Search this Thread
Old 09-03-2006, 04:49 AM   #1
yeahflow
LQ Newbie
 
Registered: Sep 2006
Posts: 2

Rep: Reputation: 0
Directory file size script


Hello fellow scripters

Its been a while and my skills are a bit rusty to say the least. I need a script tha will display the file name of the smallest file and the largest file in a specified directory. Also the average filesize of the directory??

I know the method of figuring out the min and max of int/double values. I just dont know the commands to retrieve the information i need.

I also need to incorporate if the user chooses the -R option the ability to scann the directory tree recursively??

Thanks people...I'd appreciate any help on this.
 
Old 09-03-2006, 08:10 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,990
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
Hello and welcome to LQ, hope you like it here.

tha will display the file name of the smallest file and the largest file in a specified directory. Also the average filesize of the directory?? I know the method of figuring out the min and max of int/double values. I just dont know the commands to retrieve the information i need. I also need to incorporate if the user chooses the -R option the ability to scann the directory tree recursively??
If this is part of a homework assignment then please read the LQ Rules about that. If this is not a homework question and your skills are not nonexistant, then you should post what you got already so we can build on that. Also note that if you have a question it helps asking for it properly, especially if your skills are nonexistant and would like other people to do your work for you. You don't have to say "please" but at least using the right phrasing and a question mark should help.
 
Old 09-03-2006, 06:07 PM   #3
yeahflow
LQ Newbie
 
Registered: Sep 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Relax my friend...I fear that you are paranoid and slightly uptight. You could have used that energy to actually respond to the question....

But to ease your stress...Here is what I have/know so far.

I know that ls -l | awk '{print $5}' will print the file size for all files and that i can even to a arithmetic expression to figure out the sum off all sizes...which maybe useful if i can then get the total number of files and divide by this to evaluate the average.

I know that du and wc -c will also give me file sizes...

My only issue is how I could get each file size one at a time (from first to last) so I can then do a comparison to see if it is the current min or max size. Can do this in a for loop until there are no more files to check.

I hope this is now to your satisfaction.

Cheers

Last edited by yeahflow; 09-03-2006 at 06:08 PM.
 
Old 09-03-2006, 06:18 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,965
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
I'd suggest looking into ls -1S, in combination with the commands
head and tail. Happy reading.

And the question does *distinctly* smack of homework.



Cheers,
Tink
 
Old 09-03-2006, 07:29 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,990
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
Can do this in a for loop until there are no more files to check.
Sure can do this.


I'd suggest looking into ls -1S, in combination with the commands head and tail.
Hmm. I wonder how I could break that :-]
 
  


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
Script to delete files with 0k file size in a directory justgiver Linux - Newbie 4 01-28-2008 04:56 AM
Apache2 Directory Browsing File Size Limitations... BillyGalbreath Linux - Software 0 06-23-2006 06:54 PM
i want to print all the files in a directory and the file size in a same line naveen245 Programming 3 12-06-2005 08:22 AM
Help with file size script jpc82 Programming 10 04-01-2004 04:55 AM
How to list total file size of a directory phil1076 Linux - General 3 12-18-2003 03:47 PM


All times are GMT -5. The time now is 12:14 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration