LinuxQuestions.org
Visit Jeremy's Blog.
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 10-21-2010, 10:08 AM   #1
blck_kenzo
LQ Newbie
 
Registered: Nov 2007
Posts: 15

Rep: Reputation: 0
Show the number of file on folder.


Hi all,

My folder have some files and I want to show the number of files on folder at "Total file on folder: "
Ex: Monday folder have six files and it will show "Total file on folder : 6" when I run a script.

This is my code :

#!/bin/sh

if [ -d /home/kenzo/Monday/ ] && {
echo "Monday"
ls -l /home/kenzo/Monday/
};then
echo "================================================= ==="
echo "Total file on folder: "

else
echo -e "Folder of Monday not find."
echo "================================================= ==="
fi
exit 0

Is it possible, pls intruct me how to do it.
Thanks !
 
Old 10-21-2010, 10:14 AM   #2
thornlord
LQ Newbie
 
Registered: Feb 2007
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by blck_kenzo View Post
Hi all,

My folder have some files and I want to show the number of files on folder at "Total file on folder: "
Ex: Monday folder have six files and it will show "Total file on folder : 6" when I run a script.

This is my code :

#!/bin/sh

if [ -d /home/kenzo/Monday/ ] && {
echo "Monday"
ls -l /home/kenzo/Monday/
};then
echo "================================================= ==="
echo "Total file on folder: "

else
echo -e "Folder of Monday not find."
echo "================================================= ==="
fi
exit 0

Is it possible, pls intruct me how to do it.
Thanks !
An ugly way to get the number is to do a
echo "The number of files in this folder is `ls -1|wc -l`"

Which displays:
The number of files in this folder is 87
 
Old 10-21-2010, 10:29 AM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Quote:
Originally Posted by blck_kenzo View Post
Hi all,

My folder have some files and I want to show the number of files on folder at "Total file on folder: "
Ex: Monday folder have six files and it will show "Total file on folder : 6" when I run a script.

This is my code :

#!/bin/sh

if [ -d /home/kenzo/Monday/ ] && {
echo "Monday"
ls -l /home/kenzo/Monday/
};then
echo "================================================= ==="
echo "Total file on folder: "

else
echo -e "Folder of Monday not find."
echo "================================================= ==="
fi
exit 0

Is it possible, pls intruct me how to do it.
Thanks !
Hi,

the following will print the number of files (!) in the folder; directories will not be counted.
Code:
find /path/to/folder -maxdepth 1 -type f -print |wc -l
Hope this helps.
 
  


Reply


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
find the number of files in a folder swift2008 Programming 5 10-25-2010 04:22 AM
terminal shows folder but file browser does not show folder biharibong Debian 2 01-21-2009 01:58 PM
how to show file path in folder browser? mhg Debian 2 10-24-2008 11:48 AM
Samba Folder does not show proper file size in windows Rustylinux Linux - Server 1 08-30-2007 11:18 AM
folder doesn't show icon thumbnails ender42 Ubuntu 4 08-06-2006 07:20 PM


All times are GMT -5. The time now is 04:32 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