Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-20-2014, 11:59 AM   #1
LQ Newbie
Registered: Jul 2014
Posts: 7

Rep: Reputation: Disabled
Delete files with time stamp

Hi Team,

I have directory where my application logs will be written. And I have many files in that directory.

I have delete the files that are having time stamp as 2013. Can you please help me for that.

Thanks in advance.
Old 08-20-2014, 12:15 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,986
Blog Entries: 14

Rep: Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187
Run command to see the files first:
ls -l |grep " 2013 "
Be sure the files you see are only those with 2013 in the date field. (i.e. make sure there aren't any that have 2013 with spaces in the file name itself).

One sure of the above:
rm $(ls -l |grep " 2013 " |awk '{print $NF}')

The awk above tells it just to print the last field which is the filename without the rest of the information you saw in the original ls -l.
1 members found this post helpful.
Old 08-20-2014, 11:57 PM   #3
Registered: Sep 2011
Posts: 81

Rep: Reputation: Disabled
Thanks a works.

Old 08-21-2014, 06:42 AM   #4
LQ Newbie
Registered: Jul 2014
Location: West Michigan
Posts: 29

Rep: Reputation: Disabled
This bash script deletes all files where the modified time is older than 30 days in the given DIRECTORY.

# Aug 8, 2014. Remove old log files from given directory. 
# Usage: logclean DIR
if [ $# -eq 0 ]; then
        echo "Usage: $0 DIR"
        exit 1
if [ ! -e $1 ]; then
        echo "ERROR: directory '$1' does not exist"
        exit 1
if [ ! -d $1 ]; then
        echo "ERROR: '$1' is not a directory"
        exit 1
# Look for "err*.txt" files over 30 days old
files=`find $1 -iname err*.txt -mtime +30 -print`
for f in $files
        echo "Deleting $f..."
        rm $f


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to delete log files based on Time Stamp sarathicse Linux - Newbie 5 10-25-2012 12:50 PM
time stamp of files ZAMO Linux - General 1 12-17-2008 05:45 AM
Archiving files using a time stamp. HunterColt22 Programming 3 06-11-2007 01:29 AM
Time stamp in Samba is 11 hours behind time stamp in Linux Linh Linux - General 3 09-04-2003 12:44 PM
Remove files by time stamp evione Linux - Newbie 1 07-15-2003 09:35 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration