- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl script for cleaning dir
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
Discussions
Discussions
Discussions
Forums
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
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
тАО05-14-2004 06:52 PM
тАО05-14-2004 06:52 PM
Perl script for cleaning dir
Please help me with perl-scripting.
So I need to write a script, which:
1. Sort all files in given directory by date.
2. Clean all old files except the 200 newest.
But this script must be in good performance, I mean not to use system("rm ...") to invoke shell every time to remove every file.
Good solutions will be pointed good :))
Regards...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2004 03:16 AM
тАО05-15-2004 03:16 AM
Re: Perl script for cleaning dir
ls -1tr | awk 'NR>200 {print}' |xargs rm
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2004 07:58 AM
тАО05-15-2004 07:58 AM
Re: Perl script for cleaning dir
Cannot beat that in speed and simplicity I guess :)
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2004 01:12 AM
тАО05-17-2004 01:12 AM
Re: Perl script for cleaning dir
I like your script, but I think he would need to leave out the "r" arg in the ls command to keep the 200 newest. (The "t" arg already sorts by latest first...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2004 01:35 AM
тАО05-17-2004 01:35 AM
Re: Perl script for cleaning dir
this is an example of "ls -lt", "ls -lct" and "ls -lut":
# ls -lt|more
total 31722
-rw-r--r-- 1 root root 7 May 14 11:11 wtmp.stat
-rw-r--r-- 1 root root 53 May 14 11:11 wtmp.out
-rw-rw-rw- 1 root sys 10675 May 14 09:00 vpart6_pm.txt
-rw-rw-rw- 1 root sys 10336 May 14 09:00 vpart5_pm.txt
-rw-rw-rw- 1 root sys 11776 May 14 09:00 vpart3_pm.txt
-rw-rw-rw- 1 root sys 37817 May 14 08:58 vpart1_pm.txt
-rw-r--r-- 1 root root 99 May 14 08:57 sys.tst_systest
drwxr-xr-x 2 root root 96 May 14 08:52 .A
-r--r--r-- 1 root root 0 May 14 08:52 llbdbase.dat
drwx------ 2 root root 96 May 14 08:52 .AgentSockets
-rw------- 1 root root 464 May 14 08:45 portmap.file
-rw------- 1 root root 2004 May 14 08:45 rpcbind.file
-rw-r--r-- 1 root root 4 May 14 08:11 btmp.stat
-rw-r--r-- 1 root root 39 May 14 08:11 btmp.out
-rwxrwxrwx 1 root sys 1456 May 10 10:31 dah
-rw-rw-rw- 1 root sys 665 May 10 09:42 PATH_b4switch
-rw-rw-rw- 1 root sys 1667 Apr 27 08:25 machineinfo.dbs
-rw------- 1 root sys 0 Apr 27 08:25 shcmachineerr.log
-rw------- 1 root sys 0 Apr 27 08:25 shcmachineuser.log
-rw-rw-rw- 1 root sys 199907 Apr 26 14:48 sysinfo.sh
-rw-rw-rw- 1 root sys 250 Apr 26 10:49 SED1
-rw-rw-rw- 1 root sys 138 Apr 26 10:49 FILE.bck
# ls -lut|more
total 31722
lrwxrwxrwx 1 root sys 7 May 17 09:20 hdhdhd -> opc_tmp
lrwxrwxrwx 1 root sys 3 May 17 09:20 hjk -> fgh
-rw-r--r-- 1 root root 53 May 14 11:11 wtmp.out
-rw-r--r-- 1 root root 7 May 14 11:11 wtmp.stat
-rw-rw-rw- 1 root sys 19063 May 14 11:10 ioscan_full_system.txt
-rw-rw-rw- 1 root sys 10675 May 14 09:01 vpart6_pm.txt
-rw-rw-rw- 1 root sys 10336 May 14 09:01 vpart5_pm.txt
-rw-rw-rw- 1 root sys 11776 May 14 09:01 vpart3_pm.txt
-rw-rw-rw- 1 root sys 37817 May 14 09:01 vpart1_pm.txt
-rw-r--r-- 1 root root 99 May 14 08:57 sys.tst_systest
-r--r--r-- 1 root root 0 May 14 08:52 llbdbase.dat
-r--r--r-- 1 root sys 1019 May 14 08:51 install.vars
-rw------- 1 root root 2004 May 14 08:45 rpcbind.file
-rw------- 1 root root 464 May 14 08:45 portmap.file
-rw-r--r-- 1 root root 39 May 14 08:11 btmp.out
-rw-r--r-- 1 root root 4 May 14 08:11 btmp.stat
-rwxrwxrwx 1 root sys 1456 May 10 10:32 dah
drwxr-xr-x 3 root bin 96 May 10 09:45 pam_krb5
drwxrwxrwx 2 oracle dba 96 May 10 09:45 .oracle
drwxrwxrwx 3 root sys 1024 May 10 09:45 dsinstall
drwxrwxrwx 2 root fsr 1024 May 10 09:45 rnd
drwxrwxrwx 2 root sys 1024 May 10 09:45 pr015
# ls -lct|more
total 31722
-rw-r--r-- 1 root root 53 May 14 11:11 wtmp.out
-rw-r--r-- 1 root root 7 May 14 11:11 wtmp.stat
-rw-rw-rw- 1 root sys 10675 May 14 09:00 vpart6_pm.txt
-rw-rw-rw- 1 root sys 10336 May 14 09:00 vpart5_pm.txt
-rw-rw-rw- 1 root sys 11776 May 14 09:00 vpart3_pm.txt
-rw-rw-rw- 1 root sys 37817 May 14 08:58 vpart1_pm.txt
-rw-r--r-- 1 root root 99 May 14 08:57 sys.tst_systest
drwxr-xr-x 2 root root 96 May 14 08:52 .A
-r--r--r-- 1 root root 0 May 14 08:52 llbdbase.dat
drwx------ 2 root root 96 May 14 08:52 .AgentSockets
-rw------- 1 root root 2004 May 14 08:45 rpcbind.file
-rw------- 1 root root 464 May 14 08:45 portmap.file
-rw-r--r-- 1 root root 4 May 14 08:11 btmp.stat
-rw-r--r-- 1 root root 39 May 14 08:11 btmp.out
-rwxrwxrwx 1 root sys 1456 May 10 10:31 dah
-rw-rw-rw- 1 root sys 665 May 10 09:42 PATH_b4switch
-rw-rw-rw- 1 root sys 1667 Apr 27 08:25 machineinfo.dbs
-rw------- 1 root sys 0 Apr 27 08:25 shcmachineuser.log
-rw------- 1 root sys 0 Apr 27 08:25 shcmachineerr.log
-rwxr-x--x 1 root sys 20051 Apr 26 14:49 instSysInfo
-rwxr-x--x 1 root sys 11118 Apr 26 14:49 unSysInfo
-r--r--r-- 1 root sys 6087 Apr 26 14:49 sched.models
note the differences.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2004 01:47 AM
тАО05-17-2004 01:47 AM
Re: Perl script for cleaning dir
M Script start time minus file modification time, in days.
A Same for access time.
C Same for inode change time (Unix, may differ for other platforms)
So use -M as in my snippet for modification time, and change to -C for change time, and -A for access time
# perl -e'@f=sort{-M$a<=>-M$b}<*>;@f<=200&&exit;splice@f,0,200;unlink@f'
# perl -e'@f=sort{-C$a<=>-C$b}<*>;@f<=200&&exit;splice@f,0,200;unlink@f'
# perl -e'@f=sort{-A$a<=>-A$b}<*>;@f<=200&&exit;splice@f,0,200;unlink@f'
Enjoy, Have FUN! H.Merijn