Listing files older than 2 months


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing files older than 2 months
# 1  
Old 01-15-2002
Listing files older than 2 months

A script or command to list files older than 2 months in a specified directory and remove it.
# 2  
Old 01-15-2002
Using the find command is one way - check the man page as there are examples.

Just be careful about removing files older than 2 months as a system files are normally older than two months and could also be removed.

find ./ -name "*" -ctime +60 -exec rm {} \;
You can use ctime, atime or mtime

(Important - don't get the last part wrong as very bad things can happen!!! Try it some time on a test system.)
thehoghunter
# 3  
Old 01-16-2002
You should put some sort of qualifier in the -name option, like -name "*.logfile", depending on the naming scheme you're going for. If there isn't one, you can leave the -name "*" off altogether, as it will ignore any files beginning with "."... Unless that's what you're going for. It's also a good idea to simply move all the files to their own directory first, then examine them to make sure you aren't getting rid of anything important before removing them.
# 4  
Old 01-17-2002
I will create one file with timestamp two months back and
search for newer files.

eg.

#touch -t 0112310000 /xyz
#find / -newer /xyz -print -exec ls -ls {} \;

Refer manual pages of touch and find for mor info

Hope it helps

Regards

Sharad
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Listing files older than 30 days

Hi, Could someone help me that what the problem is in this code? #!/bin/sh FOLDER=/abc/datasource/checkstatus TIMESTAMP=$(date +%s) for filename in $(find $FOLDER -maxdepth 1 -type f -name "CHECK_STATUS*"); do f1=$($filename -Eo "{4}+") f2=$(date -d "$f1" +%s) if... (11 Replies)
Discussion started by: Home
11 Replies

2. Shell Programming and Scripting

Deleting files and directory's older than 3 months

I have a qnap TS259 that is running ubuntu. Have successfully setup back scripts that are initiated by cron. I would like to create a couple scrypts that would operate on the recycle bins for both drives. Just want to be able to run the script manually that would walk through both directories... (13 Replies)
Discussion started by: mackconsult
13 Replies

3. UNIX and Linux Applications

Firefox 10 keeps losing history older than 2 months

Can anyone explain why Firefox 10 keeps losing history older than 2 months? (1 Reply)
Discussion started by: cokedude
1 Replies

4. HP-UX

listing processes older than n days

Hello; trying to find processes older than n days, mostly user shells Tried the following code on 11.31 box: in this case older than 5 days UNIX95= ps -ef -o user,pid,ppid,cpu,etime,stime | grep "-" | awk '{print $2}' | xargs ps -ef|grep -v '?' |\ awk '$5 !~ ""' | awk '($5 ~ "$(date "+%b")")... (6 Replies)
Discussion started by: delphys
6 Replies

5. Shell Programming and Scripting

Command to Count the files which is Older than 3 months?

Hi Gurus the count of files in a particular Directory... ls -lrth | grep -c ^- can any one share the command to Count the files which is Older than 3 months So please help me out in this Thanks in Advance (2 Replies)
Discussion started by: SeenuGuddu
2 Replies

6. Shell Programming and Scripting

need a code for moving the log files older than 2 months

Hi Viewer, I need logic code for moving the logs files from one directory to another directory. source :/xxxxxx/ xxxxxx / xxxxxx / xxxxxx / log --- under log directory we have so many files from last two years Here I need to check the files older than two months and I need to move in... (5 Replies)
Discussion started by: munna_su
5 Replies

7. Shell Programming and Scripting

gzip files older than 1 months

Hello, I want to gzip files in a folder in bulk i.e. all files older than 1 month should be in *.gz format. Could you please suggest how this can be achieved. Thanks. Regards, Alok (1 Reply)
Discussion started by: alok1301
1 Replies

8. Shell Programming and Scripting

Listing processes that are a day older

Hi All, I am trying to automate some stuff to make my 'to-do-things' easier. I am in need for help regarding this. I have an output root 17187 3465 0 23:00:00 ? 0:01 Process1 root 4975 4974 0 May 12 ? 0:00 Process2 root 4042 16713 0 Jan 30 pts/22 0:00... (4 Replies)
Discussion started by: reddybs
4 Replies

9. Shell Programming and Scripting

Delete files older than 3 months.(read date from the name of the file)

Guys, My log files stored in the date format format below(log_20080714072942): TIMESTAMP=`date +%Y%m%d%H%M%S` LOG=/log/log_${TIMESTAMP}.log I'm looking for a shell script which deletes all files which is older than 3 months from today. Regards, Bhagat (3 Replies)
Discussion started by: bhagat.singh-j
3 Replies

10. UNIX for Dummies Questions & Answers

Find files older than 5 days and remove tem after listing

need help with this ... Find files older than 5 days and remove tem after listing list "test" file older than 5 days and then remove them (1 Reply)
Discussion started by: ypatel6871
1 Replies
Login or Register to Ask a Question