Review your favorite Linux distribution.
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 09-22-2008, 10:20 AM   #1
Registered: Aug 2007
Posts: 346

Rep: Reputation: 31
Non programmer looking for push...

ok, I do know my web skills (cf, php, etc.) but not on the shell side. Bsaically I have a nightly backup that get's pulled from our co-lo locally. Each start of the new month I take the 1st of the month, move it to a monthly folder for archiving and remove the rest. I would like to automate this as there are 200+ files, but looking for how/where to start.

The file name strucuture is, server.backup.yyyymmdd.tar.gz. I can't simply say find *01* as it will screw up stating January, so if anyone can say yea, just do this one or 2 lines, or say, look at these commands I can start on this.

Thanks as always.
Old 09-22-2008, 10:49 AM   #2
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
Assuming that years always take 4 digits, months always take 2 digits, and days always take 2 digits:
 ls <directory to search> | grep -E ".*[0-9]{4}[0-9]{2}01.*"
ls <directory to search> | grep "01.tar.gz"
That should give you a list of the files you want. You can store them in a variable from there and then loop over them to move them to the directory you want.

You could create a script that takes a directory path (destination) as input and then moves all the files you want and removes all others.
Old 09-22-2008, 12:50 PM   #3
Registered: Aug 2007
Posts: 346

Original Poster
Rep: Reputation: 31
Perfect, I started with a shell script 101, and after the "hello world" I knew it would be a while.

Thanks much.
Old 09-22-2008, 06:50 PM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,396

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
With a name format like that, they will sort naturally, so at the start or end of the mth, use



So to get the first use

ls|sort|head -1


ls|sort|tail -1

PS these might help:

Last edited by chrism01; 09-22-2008 at 06:51 PM.


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
Obex Push thoyyib Linux - Software 2 05-10-2006 08:12 AM
Programmer to Programmer ( Long Story Of A GUI ) mdoubledragon Programming 1 10-13-2005 05:41 PM
Push installation balpeck Linux - Networking 1 09-21-2003 09:30 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:57 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