LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 12-23-2013, 09:15 PM   #1
mr.cracker
Member
 
Registered: May 2012
Posts: 58

Rep: Reputation: Disabled
answer for shell program


Shell script to count and report the number of entries present in each sub directory mentioned in their path which is supplied as a command line?

can anyone give the answer fot this shell program..it's. for my university practical. exam please help me
 
Old 12-23-2013, 11:08 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
People would love to help you on points where you're stuck, but do not expect a readymade script here... please!

However, let's know what work/research you've done so far on your own and mention that where are you stuck. Also explain your question little more for clear understanding.
 
Old 12-23-2013, 11:31 PM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,363

Rep: Reputation: 135Reputation: 135
Hope this will work for you. Just pass the directory as argument to the script.
Quote:
for dir in $(ls -dR $1*/*/)
do
echo "$dir has $(ls $dir | wc -l) entries"
done
 
Old 12-24-2013, 03:43 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
That will fail on directories and files which have names including whitespace characters: space, tab and newline.
 
Old 12-24-2013, 04:58 AM   #5
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,363

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by catkin View Post
That will fail on directories and files which have names including whitespace characters: space, tab and newline.
Hi Catkin, I just gave a hint. It also count upto 2 level of hierarchy only.

Last edited by divyashree; 12-24-2013 at 05:00 AM.
 
Old 12-24-2013, 08:51 AM   #6
mr.cracker
Member
 
Registered: May 2012
Posts: 58

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by catkin View Post
That will fail on directories and files which have names including whitespace characters: space, tab and newline.
Then Can u help me to do it. i don't have that much time to study shell script. i know basics but advanced i dont know.
it's for my exam. can u give a working program with full logic. it will be a great help for me.
 
Old 12-24-2013, 09:38 AM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,454

Rep: Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052
Quote:
Originally Posted by mr.cracker View Post
Then Can u help me to do it. i don't have that much time to study shell script. i know basics but advanced i dont know.
it's for my exam. can u give a working program with full logic. it will be a great help for me.
No

You signed up for the class, we did not. Presumably you went to the lessons that taught you the basics of how to do this, use those lessons to do your own work. If you did not go to class, it's your own fault that you don't know how to do this. If you did go but did not listen, it's your own fault that you don't know how to do this. If you did go and did listen but did not understand, then you should have gone to the professor for assistance LONG ago. If you did go to class did listen, did seek out help from the professor, and still do not understand, then perhaps this isn't the right field for you, and your grade should probably reflect that.

We will provide assistance and guidance, but we will not do your homework for you.
 
  


Reply

Tags
shell


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] fax program with selective auto answer? mark_alfred Linux - Software 2 01-14-2013 02:00 PM
shell script to answer our questions loveulinux Linux - Newbie 10 09-24-2011 03:52 AM
[SOLVED] script help (Case & IF statement syntax), easy to answer if you know shell scripting. casperpache Linux - Newbie 12 05-09-2011 07:18 AM
what should i answer when the program ask me like this? cainiao Linux - Newbie 1 08-11-2004 12:35 PM


All times are GMT -5. The time now is 11:25 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration