Register
It is currently Thu Dec 18, 2014 6:47 pm

I need a simple script asap.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Thu Nov 01, 2007 4:10 am   

Joined: Thu Oct 11, 2007 4:08 am
Posts: 2
Ineed a script that lists the number of objects(ordinary files, directories, special files, etc) from the directory indicated as a parameter.
Objects.sh [directory]

For example:

Your directory contains:
16 ordinary files
35 directories

Pls as soon as possible. I have a test right now. Thank you.


Top
 Profile  
 PostPosted: Thu Nov 01, 2007 7:47 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Very simple, I suggest you learn the 'find' command as it's very useful.
Note that this is not written in a robust way, for example if no paramter (directory) is supplied it'll just choke lots of errors.

#!/bin/bash
# Objects.sh <directory>

echo -n "regular files: "
find $1 -maxdepth 1 -type f | wc -l

echo -n "directories: "
find $1 -maxdepth 1 -type d | wc -l

echo -n "block (buffered) special: "
find $1 -maxdepth 1 -type b | wc -l

echo -n "character (unbuffered) special: "
find $1 -maxdepth 1 -type c | wc -l

echo -n "named pipes: "
find $1 -maxdepth 1 -type p | wc -l

echo -n "symbolic links: "
find $1 -maxdepth 1 -type l | wc -l

echo -n "sockets: "
find $1 -maxdepth 1 -type s | wc -l


Top
 Profile  
 PostPosted: Thu Nov 08, 2007 11:15 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 673
Location: Des Moines, Iowa
Next time I suggest you study for your test.......
Note to everyone, please don't answer homework questions....... you can point them in the right direction, but don't do the work for them. It teaches them nothing.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP