Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-27-2008, 05:54 AM   #1
LQ Newbie
Registered: Jun 2007
Posts: 3

Rep: Reputation: 0
check file oldness

I have a backup script:
##export day=$(date +%a)
##if [ $day = "Sat" ] || [ $day = "Sat" ]; then
##   rm -f /backup/*

export date=$(date +%T-%Y-%m-%d)
tar cvf - /srv | gzip > /backup/srv-$date.tar.gz
Now it.s deleting old files in saturdays, but how to make it, that it.s deleting only files older then seven days?
Old 02-27-2008, 12:28 PM   #2
LQ Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 75
Moved: This thread is more suitable in the Programming Forum and has been moved accordingly to help your thread/question get the exposure it deserves.
Old 02-27-2008, 01:20 PM   #3
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You can use find to narrow down the "oldness" and then delete the files it comes up with.
Old 02-27-2008, 02:28 PM   #4
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 36
find /path/to/files -mtime +7 -type f -exec rm -f {} \;
Old 02-27-2008, 04:52 PM   #5
LQ Newbie
Registered: Jun 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks a lot jim. It.s works and that, what i needed!!!


backup, script

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
How to write crontab to check file size and all file in a directory? modpriest Linux - Newbie 1 02-14-2008 06:48 AM
Check to see if a file has a certain character in it krock923 Programming 2 11-25-2004 03:30 PM
samba file check steve_d555 Linux - Networking 5 04-12-2004 02:17 PM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM
check file in use pangfai Linux - Networking 1 07-09-2002 01:29 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:02 AM.

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