- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- perl ..with date
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 04:55 AM
10-05-2006 04:55 AM
i need help in writing the perl script which checks whether a directory exists or not and read the files in a directory and sort the files according to the date they are created
Thanks in Advance
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 05:23 AM
10-05-2006 05:23 AM
Re: perl ..with date
- creation date is of no means at a UNIX like system and not recorded anyway
- why perl?
- for modification time you can use in a shell something like this, to get the latest m-time first:
d=/path/to/dir
[ -d $d ] && ls -t $d
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 06:21 AM
10-05-2006 06:21 AM
Re: perl ..with date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 06:34 AM
10-05-2006 06:34 AM
Re: perl ..with date
#!/usr/contrib/bin/perl
$dir="/path/to/dir/";
if (-d $dir)
{
system("ls -1t $dir");
}
;-)
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 06:52 AM
10-05-2006 06:52 AM
Re: perl ..with date
Like that?
BTW You didn't specify
- if you wanted to sort ascending or descending
- if the directory should be descended in
- if files starting with a "." should be included
Alternate way, descending and reversing the sort:
use File::Find;
my @files;
find(sub{-f&&push@files,$File::Find::name},$dir);
@files = sort { -C $b <=> -C $a } @files;
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 06:55 AM
10-05-2006 06:55 AM
Re: perl ..with date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 07:31 AM
10-05-2006 07:31 AM
Re: perl ..with date
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 08:12 AM
10-05-2006 08:12 AM
Re: perl ..with date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 08:48 AM
10-05-2006 08:48 AM
Re: perl ..with date
For modification time sorting, just use -M
Sort, newest last:
my@files=sort{-M$b<=>-M$a}glob"dir/*"';
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 08:56 AM
10-05-2006 08:56 AM
Re: perl ..with date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 09:47 AM
10-05-2006 09:47 AM
Re: perl ..with date
(swap $a and $b in the sort)
see
# perldoc -f sort
Enjoy, Have FUN! H.Merijn [ don't forget to rate the answers ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2006 12:43 AM
10-06-2006 12:43 AM
Re: perl ..with date
I think the terseness has a few drawbacks.
First afaik Perl is using the csh globbing mechanism when either
This means that if you have many, or long named files (caveat long paths) in the directory your script may be susceptible to exhaust the No. of chars limited by the OS (e.g. getconf ARG_MAX).
Besides the single asteriks would not expand the "hidden" dot files.
To include them as well (without also catching the current and parent dir) you would have to use some arcane shell globbing pattern like such if you want to stick with glob() (or cast it through a Perl grep()).
$ perl -e 'printf"%d files in /tmp\n",scalar@{[glob"/tmp/* /tmp/.[!.]*"]}'
290 files in /tmp
For large amounts of files or long paths you are probably better off with additional opendir(), readdir(), closedir().
If you need to recurse into subdirs as well combine those in a Find::File callback.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2006 12:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2006 01:23 AM
10-06-2006 01:23 AM