|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
PERL count files in a dir
Hi Guys, I need to count files in a dir which were updated yesterday. ls -lth | grep -i 'Jul 7' | wc -l The dir holds files of last 15 days and total count is as 2067476. Is it efficient to count the files using perl? I have developed the following perl script making use of system(). Can anybody coment, any other way without using system() Code:
#!/usr/bin/perl @months = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec); ($sec,$min,$hour,$monthday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $month =$months[$mon]; ############################################# # ls -lth | grep -i 'Jul 7' | wc -l ############################################# $command = "ls -lth | grep -i '" . $month . " " . $monthday -1 . "' | wc -l"; $count = system($command); print "$count \n"; Thank you Regards @Asteroid |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
I would avoid at any price to call system from a perl script. Here's a quick try Code:
perl -e 'opendir (DIR, $ARGV[0]) ; @count = readdir(DIR); $count = @count; print $count-2,"\n"' /path/to/your/directory ---------- Post updated at 11:27 ---------- Previous update was at 11:25 ---------- Edit: added the -2 in order not to count "." and ".." |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thx blitzer for the reply, what if I want to count files updated ona specfic date. I mean, I don't want to count all the files in the directory. I want to count files updated/created on a specfic date (say today 08-07-2009). An equivalent in bash is some thing like this: Code:
ls -lth | grep 'Jul 8' | wc -l This is how I can count files, updated on 8th july 2009 (using bash) Thank you. |
|
#4
|
|||
|
|||
|
Your question has been answered on another forum
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Modify a perl script to find and count | richsark | Shell Programming and Scripting | 4 | 04-01-2009 02:02 PM |
| Perl - Count occurences | TimHortons | Shell Programming and Scripting | 22 | 01-31-2009 12:30 AM |
| Perl/shell script count the lines | pistachio | UNIX for Dummies Questions & Answers | 3 | 09-24-2008 04:26 PM |
| grep all records in a file and get a word count -perl | meghana | Shell Programming and Scripting | 4 | 02-13-2008 09:06 PM |
| hw can i count the number of character in a file by perl | trupti_rinku | Shell Programming and Scripting | 1 | 10-31-2006 06:27 AM |
|
|