- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: single command to delete the different file by...
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
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
тАО10-28-2009 11:52 PM
тАО10-28-2009 11:52 PM
single command to delete the different file by moth wise
Anybody know the single command to delete the different file by moth wise in HPUNIX.
For example i want to delete file created in January 2009
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2009 12:04 AM
тАО10-29-2009 12:04 AM
Re: single command to delete the different file by moth wise
>>Anybody know the single command to delete the different file by moth wise in HPUNIX.
For example i want to delete file created in January 2009<<
Yes , You can , But many ways to do.
find command, "man find"
Example:-
DESTDIR="/abcd"
find $DESTDIR -mtime +5 -exec ll {} \
Above command will find files create last five last and list
you can change ll (to) rm will delete , before you run command check with listing than proceed delete
HTH,
Johnson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2009 12:08 AM
тАО10-29-2009 12:08 AM
Re: single command to delete the different file by moth wise
cd /abc
ll |grep -i Jan
Once confirmed "you change the ll to rm"
to delete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2009 01:05 AM
тАО10-29-2009 01:05 AM
Re: single command to delete the different file by moth wise
>>Anybody know the single command to delete the different file by moth wise in HPUNIX.
- What is moth wise ? not sure what you are looking for. pls provide more data.
-Why not use regular expressions:
Suppose you have some differen files say 5 files, aa1 aa2 aa3 aa4 aa5 and you want to delete 5 files , but not these aa1a aa6 aa7 etc.
List:
# ls -l aa[1-5]
Delete:
# rm aa[1-5]
Hth,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2009 01:08 AM
тАО10-29-2009 01:08 AM
Re: single command to delete the different file by moth wise
You can't. Unix doesn't track creation, only modification. So if you want to delete files last modified in Jan, you can.
If you want to delete anything last modified in Jan or before, you can use the -mtime +N, where you have to count the number of days from today to Jan 31.
Or you can set up a reference file with touch(1) and use ! -newer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2009 02:03 AM
тАО10-29-2009 02:03 AM
Re: single command to delete the different file by moth wise
Well, you can use mtime function with find command to delete files based on file inode modification time:
You can find and delete files whose time stamps are within a certain age range, or compare them to a reference file time stamp as mentioned above,
ex:
-Files modified in the last 24 hours:
find /dir -mtime -1 -print
- Files modified in last 7 days: ( 7 *24 hrs)
# find /dir -mtime -7 -exec ls -l {} \;
-find files that were last modified 60 days ago under /dir, use
# find /dir -type f -mtime -60 -exec ls-l {} \;
- Delete files that were last modified 60 days ago, under /dir, use
# find /dir -type f -mtime -60 -exec rm {} \;
Also check out few link:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?&threadId=485287
You can also use: -newer option:
http://docs.hp.com/en/B9106-90007/find.1.html
-newer[tv1[tv2]] file
True if the indicated time value (tv1) of the current file is newer than the indicated time value (tv2) of file. The time values tv1 and tv2 are each selected from the set of characters:
# find /dir -newer ref_file -exec ls -l {} \;
# it will print files more recent than the ref_file
Per your question:
>>For example i want to delete file created in January 2009
Current month is Oct09. so you may use (-240 days in mtime). However this will be true only if the files created in january , and has not been modified since then:
- to check:
# find /dir -type f -mtime -240 -exec ls -l {} \;
- To delete:
# find /dir -type f -mtime -240 -exec rm {} \;
Hth,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 01:55 AM
тАО10-30-2009 01:55 AM
Re: single command to delete the different file by moth wise
really strange question by an expert in this area!
It's possible to delete files per month based on the modified date but to get more help you should provide more detail about what you want really to do.
Rgds,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-25-2009 01:24 AM
тАО11-25-2009 01:24 AM
Re: single command to delete the different file by moth wise
please, since people spent time to provide you help, please, spent your time to assign points:
http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1387538
Rgds,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-25-2009 07:15 AM
тАО11-25-2009 07:15 AM
Re: single command to delete the different file by moth wise
For example,
$mtime = (lstat($file))[9]
You can derive the range of timestamps which constitute January 2009 using the timegm() or timelocal() functions found in the Time::Local module.
timelocal($sec,$min,$hour,$mday,$mon,$year);
So the first second in January 2009 in your local time zone is:
use Time::Local;
$jan09begin = timelocal(0,0,0,1,0,109);
And the last second in January 2009:
use Time::Local;
$jan09end = timelocal(59,59,23,31,0,109);
You can then compare these numbers with the time obtained from lstat() to determine whether a file's timestamp falls within that range.
Note that Jan..Dec = (0..11) and the year is based in 1900, the same as the gmtime() and localtime() functions.
I'm not sure if it'll croak on February 29 in a non-leap-year and the like, you'll have to try it out.
So probably the most UNIX-y way to do this would be to write the Perl script as a filter, so that you could do:
find . -type f -print | timein 200901 | xargs rm
And maybe command line arguments to specify mtime, atime, or ctime.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-25-2009 07:20 AM
тАО11-25-2009 07:20 AM
Re: single command to delete the different file by moth wise
$feb09end = timelocal(0,0,0,1,2,109) - 1;
This also means you don't have to code in the whole "Thirty days hath September..." rhyme, and the every four years but not every 400 leap year rule.