- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- delete old files
Operating System - Linux
1754134
Members
3287
Online
108811
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
тАО02-22-2008 07:36 AM
тАО02-22-2008 07:36 AM
delete old files
Hi,
is there any simple way to list files recursively in a directory and subdirectories and delete them.
i do not want to use find command as i dont know what to specify for -mtime.
Basic idea is if a file system is 100% i would need to delete files till it reaches 75% and i should delete oldest files in partition.
i tried the following.
1. ls -ltR -- doesnt give absolute parth
2. find . -name > list, then read the files from list and then do ls -l. this way i have absolute path, but now i'm not sure how to sort them based on date and time.
-C
is there any simple way to list files recursively in a directory and subdirectories and delete them.
i do not want to use find command as i dont know what to specify for -mtime.
Basic idea is if a file system is 100% i would need to delete files till it reaches 75% and i should delete oldest files in partition.
i tried the following.
1. ls -ltR -- doesnt give absolute parth
2. find . -name > list, then read the files from list and then do ls -l. this way i have absolute path, but now i'm not sure how to sort them based on date and time.
-C
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2008 09:42 AM
тАО02-22-2008 09:42 AM
Re: delete old files
Hi:
To find files recursively implies either using 'find' or rolling-your-own using Perl or C and with 'readdir()'.
Certainly I don't think you want to ignore the last modification time when choosing candidates for removal. After all, the largest file that will yield you significant space returns might be the most recent!
You could do:
# find /path -xdev -type f -mtime +7 -exec ls -l {} \+
...to see files that are older than 7-days since their last modification, or you could find and remove them with:
# find /path -xdev -type f -mtime +7 -exec rm {} \+
You might find it useful to present the list in descending size order:
# find /path -xdev -type f -mtime +7 -exec ls -l {} \+ | sort -k5,5 -nr
Regards!
...JRF...
To find files recursively implies either using 'find' or rolling-your-own using Perl or C and with 'readdir()'.
Certainly I don't think you want to ignore the last modification time when choosing candidates for removal. After all, the largest file that will yield you significant space returns might be the most recent!
You could do:
# find /path -xdev -type f -mtime +7 -exec ls -l {} \+
...to see files that are older than 7-days since their last modification, or you could find and remove them with:
# find /path -xdev -type f -mtime +7 -exec rm {} \+
You might find it useful to present the list in descending size order:
# find /path -xdev -type f -mtime +7 -exec ls -l {} \+ | sort -k5,5 -nr
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2008 09:54 AM
тАО02-22-2008 09:54 AM
Re: delete old files
Bonjour,
"but now i'm not sure how to sort them based on date and time"
Here is a general guideline :
A first approach is to filter your "ls -l" with something like "sort -k 6M,6M -k 7n,7n"
6M : 6th field is a month
7n : 7th field is a number (day of month)
It will do the job correctly ONLY if files are less than 6 month old. The problem is that when a file is less than 6 month old, ls outputs time in the 8th field. If file is older ls outputs year in the 8th field ... Not good for sorting !
So you should do the job in 2 times.
First work with files older than 6 months with the command "find" then filter your "ls -l" with "sort -k 8n,8n 6M,6M -k 7n,7n". For the find I suggest to use the option "! -newer" rather than "-mtime". For example :
touch -t 200708220000 /tmp/flag
find . ! -newer /tmp/flag
Will find all files older than August 22th 2007 00h00.
Second work with files youger than 6 months with the command "find" then filter with "sort 6M,6M -k 7n,7n"
A beat complicated, but it should work
Eric
"but now i'm not sure how to sort them based on date and time"
Here is a general guideline :
A first approach is to filter your "ls -l" with something like "sort -k 6M,6M -k 7n,7n"
6M : 6th field is a month
7n : 7th field is a number (day of month)
It will do the job correctly ONLY if files are less than 6 month old. The problem is that when a file is less than 6 month old, ls outputs time in the 8th field. If file is older ls outputs year in the 8th field ... Not good for sorting !
So you should do the job in 2 times.
First work with files older than 6 months with the command "find" then filter your "ls -l" with "sort -k 8n,8n 6M,6M -k 7n,7n". For the find I suggest to use the option "! -newer" rather than "-mtime". For example :
touch -t 200708220000 /tmp/flag
find . ! -newer /tmp/flag
Will find all files older than August 22th 2007 00h00.
Second work with files youger than 6 months with the command "find" then filter with "sort 6M,6M -k 7n,7n"
A beat complicated, but it should work
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2008 02:35 PM
тАО03-03-2008 02:35 PM
Re: delete old files
thanks
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP