Skip to ContentSkip to Footer
Start of content
- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- delete old files
General
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Latin America
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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.
End of content
United States
Hewlett Packard Enterprise International
Communities
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP