|
| |||
| Re: File Count On Mon, 12 Nov 2007 14:12:31 -0600, M wrote: > Is there a command that will simply give me a count of files in a given > directory? ls lists them and du gives me size of directory. I just want a > count. ls | wc -l > Its for a perl script I am working on. Sorry do not know how to do it in Perl language. |
| |||
| Re: File Count On 2007-11-12, M wrote: > > Is there a command that will simply give me a count of files in a given > directory? ls lists them and du gives me size of directory. I just want a > count. set -- * count=$# > Its for a perl script I am working on. This sort of thing is much easier in a shell script. -- Chris F.A. Johnson, author | <http://cfaj.freeshell.org> Shell Scripting Recipes: | My code in this post, if any, A Problem-Solution Approach | is released under the 2005, Apress | GNU General Public Licence |
| |||
| Re: File Count On Mon, 12 Nov 2007 20:17:09 +0000, Bit Twister wrote: > On Mon, 12 Nov 2007 14:12:31 -0600, M wrote: >> Is there a command that will simply give me a count of files in a given >> directory? ls lists them and du gives me size of directory. I just >> want a count. > > ls | wc -l > > >> Its for a perl script I am working on. > > Sorry do not know how to do it in Perl language. Be nice now, aliases of "ls" can botch *that*... /bin/ls -1 | wc -l |
| |||
| Re: File Count On Mon, 12 Nov 2007 17:10:37 -0600, Thomas P Brisco wrote: > On Mon, 12 Nov 2007 20:17:09 +0000, Bit Twister wrote: > >> On Mon, 12 Nov 2007 14:12:31 -0600, M wrote: >>> Is there a command that will simply give me a count of files in a given >>> directory? ls lists them and du gives me size of directory. I just >>> want a count. >> >> ls | wc -l >> >> >>> Its for a perl script I am working on. >> >> Sorry do not know how to do it in Perl language. > > Be nice now, aliases of "ls" can botch *that*... > > /bin/ls -1 | wc -l Small correction: that should have been /bin/ls | wc -l because "/bin/ls -l" is off by one, due to the "total" line it throws at the top of the list. |
| |||
| Re: File Count On 2007-11-12, Chris F.A. Johnson <cfajohnson******.com> wrote: > On 2007-11-12, M wrote: >> >> Is there a command that will simply give me a count of files in a given >> directory? ls lists them and du gives me size of directory. I just want a >> count. > > set -- * > count=$# I almost forget to do "echo $count" and thought I had nothing. ;-) |
| |||
| Re: File Count Mark South wrote: .... >>>ls | wc -l >>> >>>>Its for a perl script I am working on. >>>> >>>Sorry do not know how to do it in Perl language. >>> >>Be nice now, aliases of "ls" can botch *that*... >> >>/bin/ls -1 | wc -l > > Small correction: that should have been > > /bin/ls | wc -l > > because "/bin/ls -l" is off by one, due to the "total" line it throws at > the top of the list. /bin/ls -1 (as in /bin/ls -<the_numer_one>) forces single column output (the default for to a non-tty) is what was suggested, not /bin/ls -l (as in /bin/ls -<letter_ell>) as that lists the files *and* gives a total count. (There is a slight difference on my screen, but it is very hard to spot.) |
| |||
| Re: File Count On Tue, 13 Nov 2007 16:44:03 +0000, Robert Newson wrote: > Mark South wrote: > > ... >>>>ls | wc -l >>>> >>>>>Its for a perl script I am working on. >>>>> >>>>Sorry do not know how to do it in Perl language. >>>> >>>Be nice now, aliases of "ls" can botch *that*... >>> >>>/bin/ls -1 | wc -l >> >> Small correction: that should have been >> >> /bin/ls | wc -l >> >> because "/bin/ls -l" is off by one, due to the "total" line it throws at >> the top of the list. > > /bin/ls -1 (as in /bin/ls -<the_numer_one>) forces single column output (the > default for to a non-tty) is what was suggested, not /bin/ls -l (as in > /bin/ls -<letter_ell>) as that lists the files *and* gives a total count. > (There is a slight difference on my screen, but it is very hard to spot.) My apologies, in my font they are more or less indistinguishable :-) It should, as you point out, be unnecessary, because ls should write each element of its output on a new line when piped. Anyway, I need glasses or better fonts. Or maybe I have an excuse to buy a new monitor? Yeah! That must be the solution ;-) |
| |||
| Re: File Count M wrote: > Is there a command that will simply give me a count of files in a given > directory? ls lists them and du gives me size of directory. I just want a > count. > > Its for a perl script I am working on. > > M > > #! /usr/bin/perl -w use File::Find (); my $Count=0; sub wanted {(my @stat = lstat($_)) && -f _ && $Count++;} File::Find::find({wanted => \&wanted}, '.'); print "$Count\n"; exit; Doug |
| |||
| Re: File Count On 12 nov, 17:12, "M" <n...@spam.tonsjunkmail.com> wrote: > Is there a command that will simply give me a count of files in a given > directory? ls lists them and du gives me size of directory. I just want a > count. > > Its for a perl script I am working on. > > M Try: /bin/ls | wc -m Check, in wc help, the correct argument for words. |
| |||
| Re: File Count "M" <no@spam.tonsjunkmail.com> wrote: > Is there a command that will simply give me a count of files in a given > directory? ls lists them and du gives me size of directory. I just want a > count. > > Its for a perl script I am working on. $dir='/tmp/*'; print scalar map {$_} <${dir}>, "\n" Florian -- <http://www.florian-diesch.de/> ----------------------------------------------------------------------- ** Hi! I'm a signature virus! Copy me into your signature, please! ** ----------------------------------------------------------------------- |
| |||
| Re: File Count Mark South wrote: .... >>/bin/ls -1 (as in /bin/ls -<the_numer_one>) forces single column output (the >>default for to a non-tty) is what was suggested, not /bin/ls -l (as in >>/bin/ls -<letter_ell>) as that lists the files *and* gives a total count. >>(There is a slight difference on my screen, but it is very hard to spot.) > > My apologies, in my font they are more or less indistinguishable :-) > > It should, as you point out, be unnecessary, because ls should write each > element of its output on a new line when piped. But it *IS* useful to know just in cases ls is aliased to include things like -C (the last of -C and -1 (minus one) takes precedence). > Anyway, I need glasses or better fonts. Or maybe I have an excuse to buy > a new monitor? Yeah! That must be the solution ;-) ^_^ |
| |||
| Re: File Count eu.alug******.com wrote: .... > Try: > > /bin/ls | wc -m > Check, in wc help, the correct argument for words. Hmmm... $ man ls .... -w, --words print the word counts So I presume you mean -w. Ok let's try it: $ cd /win/c $ ls -F Config.sys* autoexec.bat* inspect.txt* os832217.bin* system.1st* DDCheck.txt* autoexec.dos* io.sys* recycled/ timer/ Matrox/ command.com* kpcms/ scandisk.log* tmp/ My Documents/ config.dos* msdos.sys* setupxlg.txt* utils/ Program Files/ detlog.txt* nc/ suhdlog.---* windows/ Wanadoo/ dist.txt* netlog.txt* suhdlog.dat* $ ls | wc -l 29 $ ls -1 | wc -l 29 $ ls -l | wc -l 30 $ ls | wc -w 31 [The 2nd line is "ls minus one pipe...", the 3rd is "ls minus ell pipe..."] Oops...the directory "Program Files" is 2 [space separated] words, as is the directory "My Documents". |
| |||
| Re: File Count On Tue, 13 Nov 2007 10:52:15 -0800, eu.alug******.com wrote: > On 12 nov, 17:12, "M" <n...@spam.tonsjunkmail.com> wrote: >> Is there a command that will simply give me a count of files in a given >> directory? ls lists them and du gives me size of directory. I just want a >> count. >> >> Its for a perl script I am working on. > > Try: > > /bin/ls | wc -m > Check, in wc help, the correct argument for words. ITYM: ls | wc -l Jonesy -- Marvin L Jones | jonz | W3DHJ | linux 38.24N 104.55W | @ config.com | Jonesy | OS/2 *** Killfiling google posts: <http://jonz.net/ng.htm> |
| |||
| Re: File Count Allodoxaphobia wrote: > On Tue, 13 Nov 2007 10:52:15 -0800, eu.alug******.com wrote: >> On 12 nov, 17:12, "M" <n...@spam.tonsjunkmail.com> wrote: >>> Is there a command that will simply give me a count of files in a given >>> directory? ls lists them and du gives me size of directory. I just want a >>> count. >>> >>> Its for a perl script I am working on. >> Try: >> >> /bin/ls | wc -m >> Check, in wc help, the correct argument for words. > > ITYM: ls | wc -l > > Jonesy $ mkdir /tmp/tmp $ cd /tmp/tmp $ touch 'a a' $ /bin/ls | wc 1 2 4 Neither wc -l or wc -w works if you have files with white space. |
| Bookmarks |
| Thread Tools | |
| |
| | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| File count in WExplorer incorrect | Skip Bisconer | Windows XP | 2 | 10-01-2007 12:10 AM |
| WORD COUNT | TDT Consulting | Microsoft Office | 2 | 07-09-2007 11:11 PM |
| word count | VanessaLou | Microsoft OneNote | 1 | 03-04-2007 03:15 AM |
| Inaccurate File and Byte Count in File Explorer: a bug? | Shawnews | Windows XP | 10 | 02-26-2007 08:00 PM |
| File count wrong in folder | C.Wilder | Windows XP | 4 | 01-27-2007 12:00 AM |
| New To Technology Questions? | Do You Need Help with Your Computer or Device? | Do You Need Help with this site? |