LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Show the number of file on folder. (https://www.linuxquestions.org/questions/linux-newbie-8/show-the-number-of-file-on-folder-839552/)

blck_kenzo 10-21-2010 09:08 AM

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 !

thornlord 10-21-2010 09:14 AM

Quote:

Originally Posted by blck_kenzo (Post 4134803)
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

crts 10-21-2010 09:29 AM

Quote:

Originally Posted by blck_kenzo (Post 4134803)
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.


All times are GMT -5. The time now is 01:09 AM.