Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

To find how much files are there in a bash shell directory using ls and wc commands

my professor have gave an assignment to write a shell script to find how many files are there in the current directory using ls and wc. Additionally wants to print a message if it is empty.
i have tried referring to the man pages for help but couldn’t work.3

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here Using wc -l is better as it will count the lines and help with miscellaneous names:

#! /bin/bash
files=`ls | wc -l`
if [ $files == 0 ] 
then
   echo "Directory is empty"
else
   echo "No of files = " $files
fi
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading