LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 11-03-2010, 09:22 AM   #1
ryme27
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Rep: Reputation: 0
Little Bash Script help


The script should list the disk storage occupied by each immediate subdirectory of a given argument or the current directory with the subdirectory names sorted in ABC order.
Also, list the name of the subdirectory with the highest disk usage along with its storage size.
If more than one subdirectory has the same highest disk usage, list any one of those subdirectories. Include meaningful brief comments.

This is what i have so far. When i use the head for some reason it wont show the name of the largest directory but the tail shows the name of the smallest and size. Any Help PLS?




Code:
# Display the Directories #


function list {
echo Disk space use (in KB) for each subdirectory
du --max-depth=1
}

fuction first {
echo Largest File
list | sort -n -r | head -n 1
 }

function last {
echo Smallest File
list | sort -n -r | tail -n 1
}
 
Old 11-03-2010, 10:30 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Please show your whole script. What is the list command? An alias?
 
Old 11-03-2010, 11:49 AM   #3
ee437
LQ Newbie
 
Registered: Oct 2010
Location: Wisconsin, USA
Distribution: Slackware
Posts: 12

Rep: Reputation: 4
i don't know if this is helpful, but, did you copy and paste the code?

function is spelled incorrectly -- fuction -- in the "first" function.

Last edited by ee437; 11-03-2010 at 12:02 PM.
 
Old 11-04-2010, 06:30 AM   #4
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Rep: Reputation: 31
Quote:
Originally Posted by ryme27 View Post
This is what i have so far. When i use the head for some reason it wont show the name of the largest directory but the tail shows the name of the smallest and size. Any Help PLS?
Yes - Your du includes the '.' directory (the entire contents of the current working directory). The head command will list the first line that matches (thus the total of your current directly) your tail will echo the last line that matches (thus matching the smallest directory). As your . directly will always be bigger than all the directories contained within it, it will always be the first match. There's a bunch of solutions to this (using head -2 is probabyl the easiest). I'm sure du has options to ignore parent as well
 
  


Reply



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
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 08:37 AM
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 07:01 PM

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

All times are GMT -5. The time now is 04:20 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