The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > Linux
.
google unix.com



Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare date from db2 table to yesterday's Unix system date sasaliasim Shell Programming and Scripting 9 12-01-2008 11:37 PM
How to list files that were added or modified on a certain date? thoughts UNIX for Dummies Questions & Answers 8 02-20-2008 01:44 AM
Create a list of files that were modified after a given date. rkka UNIX for Dummies Questions & Answers 4 01-22-2008 05:12 AM
Last Modified Date cengiz Shell Programming and Scripting 12 06-28-2005 03:05 AM
compare date of files on different nodes isacs UNIX for Advanced & Expert Users 3 03-12-2002 02:11 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-19-2007
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
compare files in the system with last modified date

HI,

I have some files in my Linux machine that are very old and occupy a HUGe amount of space. I am trying to delete these files from the system so that it will be easy for me to add some files. I would like to know if this can done through a Perl or a shell script.

What i want to do is i want to compare the files with the current date stamp and list all the files that are were untouched for more than TWO years.

Please can some whe help me on how this can be done.

I am new to Linux and need Guidance on this.

Thanks,
Sandeep
  #2 (permalink)  
Old 10-19-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
man test

Code:
     file1 -nt file2
                   True if file1 exists and is newer than file2.

     file1 -ot file2
                   True if file1 exists and is older than file2.
So if you have a file with your cutoff timestamp you can compare others such:

Code:
if test $candidate-file -ot $cutoff-file
then
     echo $candidate-file
fi
  #3 (permalink)  
Old 10-19-2007
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
Hi Porter,

The script you have given is probably if i know the filename, but in my case i don't know the names of all the files( thats were the problem lies)....I need to find files that have not been changed from past two years by compariing them with respect to the last modified date. Also i am starter to shell scripting so please help me with the complete code. I really appreciate you time to look into this thread.Thanks so much.

Please let me know your thoughts.

Thanks,
Sandeep
  #4 (permalink)  
Old 10-19-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
try

find directory ! -newer candidate | xargs ls -ld

when that is showing you the correct files

replace "ls -ld" with "rm"

Note, it is your responsiblity to have the appropriate backups. Do not attempt this if you don't know what you are doing.
  #5 (permalink)  
Old 01-15-2008
eXedon eXedon is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 3
Thumbs up

Quote:
Originally Posted by porter View Post
man test

Code:
     file1 -nt file2
                   True if file1 exists and is newer than file2.

     file1 -ot file2
                   True if file1 exists and is older than file2.
So if you have a file with your cutoff timestamp you can compare others such:

Code:
if test $candidate-file -ot $cutoff-file
then
     echo $candidate-file
fi
confirm
  #6 (permalink)  
Old 10-19-2007
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
HI porter,

I am bit confused with your inputs. can you just leme know how this can be written in a shell script.

THanks for your time

Sandeep
  #7 (permalink)  
Old 10-19-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Code:
#!/bin/sh
find directory ! -newer cutoff-file | xargs ls -ld
where directory is the path to the directory you want to clean
cutoff-file is the path to a file which has the filestamp you want to compare with.
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0