LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-20-2014, 12:59 PM   #1
linux_student_007
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, 01:15 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,577
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
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-21-2014, 12:57 AM   #3
ravi_nandula
Member
 
Registered: Sep 2011
Posts: 81

Rep: Reputation: Disabled
Thanks a lot...it works.

Thanks
 
Old 08-21-2014, 07:42 AM   #4
bulrush15
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.

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


Reply


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 01:50 PM
time stamp of files ZAMO Linux - General 1 12-17-2008 06:45 AM
Archiving files using a time stamp. HunterColt22 Programming 3 06-11-2007 02:29 AM
Time stamp in Samba is 11 hours behind time stamp in Linux Linh Linux - General 3 09-04-2003 01:44 PM
Remove files by time stamp evione Linux - Newbie 1 07-15-2003 10:35 AM


All times are GMT -5. The time now is 09:53 AM.

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