- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: script to move files by month
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 12:14 AM
тАО03-26-2007 12:14 AM
I am working on a script that will move and comppress files that are from 3 months ago.
what I need is a solution to find all files in a directory that are from say december which is 3 months previous. I know find and mtime will identify all files from 90days however this may not capture all files.
any help would be great
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 12:21 AM
тАО03-26-2007 12:21 AM
Re: script to move files by month
Something like:
touch ref_file mmddyy, etc.
find /start_dir ! -newer ref_file
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 12:24 AM
тАО03-26-2007 12:24 AM
Re: script to move files by month
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 12:25 AM
тАО03-26-2007 12:25 AM
Re: script to move files by month
> I know find and mtime will identify all files from 90days however this may not capture all files.
Why not? The 'find' options offer '-mtime' as well as '-newer'. With '-mtime' you have the ability to specify exactly, greater than or less than. With '-newer' you can specify ranges of time by creating two reference files and comparing greater than one and not greater than the second.
Of course, limit all of your 'find' selections to files only ('-type f') and don't cross mountpoints ('-xdev').
See the 'find' manpages for more information.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 12:25 AM
тАО03-26-2007 12:25 AM
Re: script to move files by month
how can I make the script determine all files from december?
Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 12:30 AM
тАО03-26-2007 12:30 AM
SolutionThere is no such thing in Unix as a creation date, only a modification date that coincidently equals a creation timestamp because there was one and only one instantiation.
That said, this should work sufficiently well:
# touch -mt 200612010000 /tmp/ref1
# touch -mt 200612312359 /tmp/ref2
# find /path -xdev -type f -newer /tmp/ref1 -a ! -newer /tmp/ref2
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2007 10:44 PM
тАО04-02-2007 10:44 PM
Re: script to move files by month
Basically I have a directory with 3 months of data in, at month 4 I have to cat the files to one large file and gzip, then when a file is required I have the code that extracts the data and recreates the original file ( Thanks JRF )
The problem I am having is determining how to create the archive file archive.mprcout.<0701> ie:
would I be best to setup a load of variables to determine the month
date=`date +%m`
if [ $date -eq 04 ] ; then
date=01
elif [ $date -eq 05 ] ; then
date=02
etc
etc
then the time stamp on the files will eqaul a letter string ie Jan therefore to match all files with Jan and concatenate to archive.mprcout.<0701> I would:
date=`date +%m`
if [ $date -eq 04 ] ; then
date=01
month=Jan
elif [ $date -eq 05 ] ; then
date=02
month=feb
etc
etc
again is there a simpler method to achieve this>
many thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2007 11:32 PM
тАО04-02-2007 11:32 PM
Re: script to move files by month
The alternative is to subtract and if zero or less re-add 12.
(Or add 8 (12-4) and subtract 12 when gt 12)
$ current=05
$ let backup=$current+12-4
$# yes, you can use +8, but this is more clear.
$ echo $backup
13
$ let backup=$backup%12
$ echo $backup
1
$ zbackup=$(printf "%02d" $backup)
$ echo $zbackup
01
I suppose you can also use typeset to force the formatting.
Personnaly i would use proper date math (perl?) and not muck with the year/month transitions myself
Also... you may want to consider to retain your refrence files in a fixed location such that you know what was done last. Then recalculate just 1 endpoint, and mv ref2 ref1.
Finally.. what if magically a 5 month old file shows up? Do you want it captured? In the current cycle seperate. If it can go to the current cycle then just use olde reference file, not the newer.
Regards
Hein van den Heuvel
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2007 02:04 AM
тАО04-03-2007 02:04 AM
Re: script to move files by month
$ WINDOW=3
$ YEAR=$(date +%Y)
$ let MONTH=$(date +%m)-$WINDOW
$ if [ $MONTH -le 1 ]; then let MONTH=$MONTH+12; let YEAR=$YEAR-1; fi
$ typeset -Z2 ZMONTH=$MONTH
$ NAME=${YEAR}${MONTH}
$ echo $NAME
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2007 11:17 PM
тАО04-03-2007 11:17 PM
Re: script to move files by month
>> $ if [ $MONTH -le 1 ];
That should of course be -lt 1
Regards,
Hein.
[ 0 point for this ]