Home | Articles | About | Contact | Forum |
Saturday, November 02, 2024



Lunarpages.com Web Hosting

Mailing List

E-mail:
By Joining the mailing list you will be notified of site updates.


Show Your Support For
This Site By Donating:











Audience: Sys Admins
Last Updated: 10/4/2011 11:23:17 PM
**All times are EST**





HOWTO - Delete Files Before a Certain Date in Linux

By Erik Rodriguez

Tags: bash delete command, xargs, /usr/bin/cut, /usr/bin/tr

This article provides methods for deleting all files before a certain date in Linux.

Method

Every now and then administrators find themselves in a bind where they need to delete files older than a certain date. This is not a big deal in small numbers, but when faced with a directory containing 120,000+ files it can be overwhelming. Don't worry, the following command will do it for you. You will simply need to adjust the date depending on what you want to do.

Be careful using these commands as their is no way to “undelete” files in Linux. You would need to restore from a backup.

Here is the command:

ls -la | grep May | /usr/bin/tr -s ' ' | /usr/bin/cut -d ' ' -f9 | xargs rm

That will list all files from May of the current year and delete them. Remember, Linux will not show the year of the file if it is the current year. You can use this command 12 times (once per month) and delete all files from each month. The following will list all files from 2010 and delete them:

ls -la | grep 2010 | /usr/bin/tr -s ' ' | /usr/bin/cut -d ' ' -f9 | xargs rm



Contact Us

If you found this information useful, click the +1 button



Your E-mail:


Subject:


Type verification image:
verification image, type it in the box

Message:


NOTE: this form DOES NOT e-mail this article, it sends feedback to the author.


TCP vs. UDP
Juniper SRX anti-spam filtering config
Windows Server 2008 Clustering Configuration
Windows 2008 R2 Network Load Balancing (NLB)
Extreme Networks: Downloading new software image
Juniper SRX save config to USB drive
Juniper SRX logout sessions
Extreme Networks Syslog Configuration
Command line drive mapping
Neoscale vs. Decru
Data Security vs. Data Protection
Juniper SRX Cluster Configuration
HOWTO - Create VLAN on Extreme Switch
Using a Non-local Colocation Facility
Linux Server Administration
IT Chop Shops
Flow Viewers: SFLOW, NetFLOW, and JFLOW
Exchange 2007 Back Pressure
IPtables open port for specific IP
Politics in IT Departments
HOWTO - Block Dropbox
Cisco IOS Cheat Sheet
Subnet Cheat Sheet
Design a DMZ Network
How DNS works
Firewall Configuration
Juniper SSG Firewalls
Server Management
Configuring VLANs
Runlevels in Linux
Server Clustering
SONET Networks
The Red Hat Network
Server Colocation
Complicated Linux Servers
Dark Fiber
Data Center Network Design
Firewall Types
Colocation Bandwidth






Copyright © 2002-2016 Skullbox.Net All Rights Reserved.
A division of Orlando Tech Works, LLC
By using this site you agree to its Terms and Conditions.
Contact Erik Rodriguez