Count and print number of directory
Let us now code a program which will Count as well as print the number of directory in a desired path like in a folder c or a desired root.
But, before doing that we should be aware what a directory is? A directory is a location for storing files on your computer. In other words, a directory is a file system cataloging structure which contains references to other computer files. Directories are known as folders.
#!/bin/bash (bash copy) if [ $# -lt 1 ]; then echo "Usage: $0 dir" exit 1 fi if [ -d $1 ]; then for i in `ls $1`; do if [ -d $i ]; then ent=`ls $1"/"$i | wc -w` echo -n "No of entities in " tput bold echo -n "'$i'" tput sgr0 echo " sub-directory are: "$ent fi done else echo "Given Location either is not a directory or is not readable" fi
For more programs in shell, visit our Shell Coder Archives
All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without prior written permission of website admin, except in case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme