- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: remove files according to date format
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
тАО04-12-2008 01:32 AM
тАО04-12-2008 01:32 AM
Can anyone tell me, how to remove files from a directry according to the date format?..like in a directry hundreds of log files is being created and I want to delete the files been created two days befor.
Its a 11.23ia64 version
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2008 01:48 AM
тАО04-12-2008 01:48 AM
Re: remove files according to date format
If not, you can only remove files that were modified 2 (or more if you want) days ago.
This would be like:
find path-to-dir -mtime 2 -exec rm -f {} +
If you only want to remove files with a specific name:
find path-to-dir/file-name-pattern ...
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2008 01:53 AM
тАО04-12-2008 01:53 AM
Re: remove files according to date format
try something like:
DIR=/data/export
find $DIR -xdev -type f -mtime +2 -name '*.dmp' -exec rm -f {}+
Also have a look to thread below:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1218419
hope this helps!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2008 04:54 AM
тАО04-12-2008 04:54 AM
SolutionIt is important to understand that Unix does not maintain a "creation" timestamp for files.
Rather, there is a last modified ('mtime') that represents the last time a file's contents was updated. Thus, after the first instantiation of a file, its 'mtime' can be said to represent a creation moment, but any modifcation thereafter causes the knowledge of the first to be lost.
The 'stat()' structure contains an 'mtime' for the last modification; an 'atime' for the last access timestamp; and a 'ctime' for the last change in a file's inode (permissions, ownership, name).
Use 'find' to locate and remove your files. Use its '-xdev' argument to prevent 'find' from crossing mountpoints. This is very important if you are examining the '/' directory. Use '-type f' to limit your selection to FILES and not directories and files. The '-mtime +2' selects files that have been modified 2-DAYS ago or earlier. With 'find' the concept of a "day" is a 24-hour unit and granularily is to the second (60*60*24=86400).
# find /path -xdev -type f -mtime +2 -exec rm {} \+
If you want to limit the above selection to only files whose name ends in ".log", simply amend this to:
# find /path -xdev -type f -mtime +2 -name "*.log" -exec rm {} \+
Notice that we double quote the wildcard "*.log" so that 'find' evaluates the argument and your shell doesn't expand "*.log" and build a 'find' command with multiple '-name' arguments --- an error.
With the above pointers in mind, please read the 'find' manpages for more information.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2008 02:48 AM
тАО04-15-2008 02:48 AM
Re: remove files according to date format
> touch -t 04131200 file1 (Apr 13 1200)
> touch -t 04151200 file2 (Apr 15 1200)
> touch -t 04151200 file3 ( " )
> ll file*
-rw-rw-rw- 1 root sys 0 Apr 13 12:00 file1
-rw-rw-rw- 1 root sys 0 Apr 15 12:00 file2
-rw-rw-rw- 1 root sys 0 Apr 15 12:00 file3
> find . -type f -name "*il*" -newer file1
./file2
./file3
> find . -type f -name "*ile*" -newer file1 -exec ls -l {} \;
-rw-rw-rw- 1 root sys 0 Apr 15 12:00 ./file2
-rw-rw-rw- 1 root sys 0 Apr 15 12:00 ./file3
use *log instead of "*ile*" and rm instead of ls for removing. User -xdev for the FS.
Here I use rm -i (inter active for test)
> find . -type f -name "*ile*" -newer file1 -exec rm -i {} \>
./file2: ? (y/n) n
./file3: ? (y/n) n
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2008 02:53 AM
тАО04-17-2008 02:53 AM
Re: remove files according to date format
I got that,
find . ! -newer /ref_file -exec rm {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2008 03:42 AM
тАО04-17-2008 03:42 AM
Re: remove files according to date format
find . ! -newer ref_file -exec rm {} +
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2008 01:06 PM
тАО09-18-2008 01:06 PM
Re: remove files according to date format
thanks.