#!/bin/bash # Shell script to find the number of files present in the current # directory without using WC command. # NOTE/TIP: # If allowed to use WC command then it should be as follows: # ls | wc -l # ------------------------------------------------------------------------- # Copyright (c) 2005 nixCraft project # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- FILE="/tmp/count.txt" echo -n "Enter directory name : " read dname ls $dname > $FILE echo "No of files in directory : $(grep [^*$] $FILE -c)" rm -f $FILE
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- 10 Greatest Open Source Software Of 2009
- My 10 UNIX Command Line Mistakes
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our email newsletter to make sure you don't miss a single tip/tricks.
- Download Script
- Email this to a friend
- Rss Feed
- Last Updated: 10/14/09
{ 3 comments… read them below or add one }
lol, rm -f $FILE ?
The wc line in the comment should be:
ls | wc -l
(with a lower case l, not uppercase as you have it shown)
It is lower case. Look at how the word “shell” is spelled a little higher.