Sponsored Content
Full Discussion: PERL count files in a dir
Top Forums Shell Programming and Scripting PERL count files in a dir Post 302332056 by Asteroid on Wednesday 8th of July 2009 04:40:54 AM
Old 07-08-2009
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

command to count files in dir

hi plz let me know the command to count the files in directory. thanks in advance -Bali Reddy (4 Replies)
Discussion started by: balireddy_77
4 Replies

2. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

3. Shell Programming and Scripting

moving files from a dir in one machine to a dir in another machines

Hi, I am a unix newbie.I need to write a shell script to move my oracle READ WRITE datafiles from one serevr to another. I need to move it from /u01/oradata/W1KK/.. to /u01/oradata/W2KK, /u02/oradata/W1KK/.. to /u02/oradata/W2KK. That is, I actaully am moving my datafiles from one database to... (2 Replies)
Discussion started by: mathews
2 Replies

4. Shell Programming and Scripting

count of Files with Dir Name

Can someone please guide me how I can get a single line for each directory: ls -ltrR|awk '/(\.\/)()*/ { print $0;d=$0;n=0;} /^-*/ { n=n+1; print d,n } ' What I'm trying to get is webconsole: 23 logs: 34 logd: 344 Regards, BB (3 Replies)
Discussion started by: busyboy
3 Replies

5. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

6. Shell Programming and Scripting

count files in dir except one

Hi I need to count files in current directory, except file abc.txt, if it exists I have such script: FILES_COUNT=$(find * -name "*" | wc -l) but it counts all files. I need to exclude abc.txt (5 Replies)
Discussion started by: optik77
5 Replies

7. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

8. Shell Programming and Scripting

PERL - Copying ONLY files from one dir to another

I'm writing a Perl script which has its 1st step as to copy files from one directory to another directory. The Source directory has got files with extension, without extension, directories etc. But I want to copy ONLY files with no extension. The files with extensions and directories should not get... (2 Replies)
Discussion started by: jhamaks
2 Replies

9. UNIX for Beginners Questions & Answers

Finding Files with Perl on a Hidden Dir?

Greetings! Been a while since I futzed around with Perl, and came upon a minor headscratcher for the community ;) Here's the basic code which I'm trying to make tick over:#!/usr/bin/perl use strict; use warnings; use diagnostics; print " starting "; while (-e "~/.somedir/testFile")... (9 Replies)
Discussion started by: LinQ
9 Replies

10. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies
Period(3)						User Contributed Perl Documentation						 Period(3)

NAME
Time::Period - A Perl module to deal with time periods. SYNOPSIS
"use Time::Period;" "$result = inPeriod($time, $period);" DESCRIPTION
The inPeriod function determines if a given time falls within a given period. inPeriod returns 1 if the time does fall within the given period, 0 if not, and -1 if inPeriod detects a malformed time or period. The time is specified as per the "time()" function, which is assumed to be the number of non-leap seconds since January 1, 1970. The period is specified as a string which adheres to the format sub-period[, sub-period...] or the string "none" or whitespace. The string "none" is not case sensitive. If the period is blank, then any time period is assumed because the time period has not been restricted. In that case, inPeriod returns 1. If the period is "none", then no time period applies and inPeriod returns 0. A sub-period is of the form scale {range [range ...]} [scale {range [range ...]}] Scale must be one of nine different scales (or their equivalent codes): Scale | Scale | Valid Range Values | Code | *******|*******|************************************************ year | yr | n where n is an integer 0<=n<=99 or n>=1970 month | mo | 1-12 or jan, feb, mar, apr, may, jun, jul, | | aug, sep, oct, nov, dec week | wk | 1-6 yday | yd | 1-365 mday | md | 1-31 wday | wd | 1-7 or su, mo, tu, we, th, fr, sa hour | hr | 0-23 or 12am 1am-11am 12noon 12pm 1pm-11pm minute | min | 0-59 second | sec | 0-59 The same scale type may be specified multiple times. Additional scales simply extend the range defined by previous scales of the same type. The range for a given scale must be a valid value in the form of v or v-v For the range specification v-v, if the second value is larger than the first value, the range wraps around unless the scale specification is year. Year does not wrap because the year is never really reset, it just increments. Ignoring that fact has lead to the dreaded year 2000 nightmare. When the year rolls over from 99 to 00, it has really rolled over a century, not gone back a century. inPeriod supports the dangerous two digit year notation because it is so rampant. However, inPeriod converts the two digit notation to four digits by prepending the first two digits from the current year. In the case of 99-1972, the 99 is translated to whatever current century it is (probably 20th), and then range 99-1972 is treated as 1972-1999. If it were the 21st century, then the range would be 1972-2099. Anyway, if v-v is 9-2 and the scale is month, September, October, November, December, January, and February are the months that the range specifies. If v-v is 2-9, then the valid months are February, March, April, May, Jun, July, August, and September. 9-2 is the same as Sep-Feb. v isn't a point in time. In the context of the hour scale, 9 specifies the time period from 9:00:00 am to 9:59:59 am. This is what most people would call 9-10. In other words, v is discrete in its time scale. 9 changes to 10 when 9:59:59 changes to 10:00:00, but it is 9 from 9:00:00 to 9:59:59. Just before 9:00:00, v was 8. Note that whitespace can be anywhere and case is not important. Note also that scales must be specified either in long form (year, month, week, etc.) or in code form (yr, mo, wk, etc.). Scale forms may be mixed in a period statement. Furthermore, when using letters to specify ranges, only the first two for week days or the first three for months are significant. January is a valid specification for jan, and Sunday is a valid specification for su. Sun is also valid for su. PERIOD EXAMPLES To specify a time period from Monday through Friday, 9am to 5pm, use a period such as wd {Mon-Fri} hr {9am-4pm} When specifing a range by using -, it is best to think of - as meaning through. It is 9am through 4pm, which is just before 5pm. To specify a time period from Monday through Friday, 9am to 5pm on Monday, Wednesday, and Friday, and 9am to 3pm on Tuesday and Thursday, use a period such as wd {Mon Wed Fri} hr {9am-4pm}, wd{Tue Thu} hr {9am-2pm} To specify a time period that extends Mon-Fri 9am-5pm, but alternates weeks in a month, use a period such as wk {1 3 5} wd {Mon Wed Fri} hr {9am-4pm} Or how about a period that specifies winter? mo {Nov-Feb} This is equivalent to the previous example: mo {Jan-Feb Nov-Dec} As is mo {jan feb nov dec} And this is too: mo {Jan Feb}, mo {Nov Dec} Wait! So is this: mo {Jan Feb} mo {Nov Dec} To specify a period that describes every other half-hour, use something like minute { 0-29 } To specify the morning, use hour { 12am-11am } Remember, 11am is not 11:00:00am, but rather 11:00:00am - 11:59:59am. Hmmmm, 5 second blocks could be a fun period... sec {0-4 10-14 20-24 30-34 40-44 50-54} To specify every first half-hour on alternating week days, and the second half-hour the rest of the week, use the period wd {1 3 5 7} min {0-29}, wd {2 4 6} min {30-59} VERSION
1.20 HISTORY
Version 1.20 ------------ - Added the ability to specify no time period. Version 1.13 ------------ - Cleaned up the error checking code. Version 1.12 ------------ - Updated email and web space information. Version 1.11 ------------ - Minor bug fix in 1.10. Version 1.10 ------------ - Released. AUTHOR
Patrick Ryan <pgryan@geocities.com> COPYRIGHT
Copyright (c) 1997 Patrick Ryan. All rights reserved. This Perl module uses the conditions given by Perl. This module may only be distributed and or modified under the conditions given by Perl. DATE
August 26, 1997 SOURCE
This distribution can be found at http://www.geocities.com/SiliconValley/Lakes/8456/ or http://www.perl.com/CPAN/modules/by-module/Time/ perl v5.12.1 1997-08-27 Period(3)
All times are GMT -4. The time now is 06:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy