how many files are in a directory?
i would like to know ot find out how many files are in a directory?
is there away to do this without using >ls | wc -w the reason why is because i don't want to count folders that may be in the directory. Another one i woul like to find out about is how list a directory and only return the file that has been modified? |
Re: how many files are in a directory?
Quote:
Code:
ls -l | grep -v ^d | grep -v ^total | wc -l |
There is usually several ways to do the same thing.
echo $(( `ls | wc -l` - `ls -d */`| wc -l )) This subtracts the number of directories from the total. |
Re: how many files are in a directory?
Quote:
you could also use a list of md5sums and make a script to run md5sum on all the files and only list those with different md5sums... it's just a thought... |
Quote:
BTW, there's a small typo in your commands, the little thinggy that makes the shell execute the command, i forgot what it's called... anyways, you accidentally placed it after the second ls but it goes after the second wc: Code:
echo $(( `ls | wc -l` - `ls -d */ | wc -l` )) |
I like that command ls -l | grep -v ^d | grep -v ^total | wc -l
To make this easier for use later edit your .bash_profile in your home directory. Add a line like this to the bottom alias lsnfo="ls -l | grep -v ^d | grep -v ^total | wc -l" lsfo short for list number files only Logout then back in. Now in the terminal type lsnfo on the command line it will run the command ' ls -l | grep -v ^d | grep -v ^total | wc -l ' Thanks for the command there win32sux. Brian1 |
Quote:
|
thank you all for your replies
|
Just in case the original poster was interested, these commands don't include hidden files. If you need to take that into account use -a option to ls.
|
You could also use the find command if you are interested in counting files in subfolders. You also have the ability to search based on modification or access time.
|
All times are GMT -5. The time now is 06:16 PM. |