Find files created on weekend,monthend,quarteley etc
Hi ALL
I have 365 files created in a folder on daily basis.. its a daily cron created for the backup. Now i would like to group the files created in end of week ,end of month etc in to a seperate folder . can any one help me to to find the files using 'find' command to extract those files Thanks Sujith |
For what I know you can only find your files based on the modification time and not on the creation time. At least not with linux e*fs. I'm not sure with other filesystems though. Still there are other possible ways to find the files. Some of these are by:
(a) depending on the average time a backup process goes - if it's just quick, you can base it from the modification time (b) the filename of the file - are there dates added to the file? (c) or the contents of the files - If dates are included inside the files, maybe the first lines can help |
Is there a naming convention for the file names which includes the date somehow?
|
Yaa each days backup ended with time stamp like "20080313.tar.gz"
i need to get the find or xargs command syntax for listing files created on 7 th day of weeks last day of month etc.. Quote:
|
for each 7th day of the month do you mean something like this:
Code:
year=2008 You can use time(), date(), mktime() and strtotime() in php but i don't know how to do that in perl. You can use the external command date but only for only the current time or else you'll have to go alternating your clock and that won't be good. |
Well, xargs is not suitable here, but you can read the output of find into a while loop, and perform some operations on each file to determine which ones you want to handle.
Please provide examples of full file names. |
Here's an example shell script which will identify files from the end of week and end of month. Note that a date can be BOTH at the end of the week, AND at the end of the month. When you modify this script to do something with the files, make sure you take that into account.
Code:
#!/bin/bash Save this into a file called myscript.sh, chmod 755 that file, and run it using the full path, and pass the names of files to process as parameters, e.g. if you create the file in your HOME directory, called myscript.sh: Code:
chmod 755 ~/myscript |
Code:
is_end_of_month () { http://www.theregister.co.uk/2008/02...ttack_ballmer/ |
Quote:
|
Hi
The full file name is like mysqldump_20080309.tar.gz mysqldump_20080310.tar.gz mysqldump_20080311.tar.gz mysqldump_20080311.tar.gz mysqldump_20080313.tar.gz I need to move the above files into another folder ie created on each weekends (sunday),end day of month etc.. ie for segrating weekend backups,monthly backup etc Thanks Sujith Quote:
|
OK, I can't help myself.
Change the functions like this: Code:
is_end_of_month () { |
Quote:
I'm constantly amazed how some things that seem they should be easy in fact cause great difficulty. Different countries had adopted the Gregorian calendar during different years. Different states in the US on different dates as well. If you have a database that records historic events, that needs to be taken into account. Have you ever heard of leap-seconds? Due to tidal forces, the rotation of the earth slows down over time. Every few years a second is added before the New Year. However, there are two dates in the year when might be added. And the US wants to not do this for the standard atomic clock. I think the argument is to count the seconds from the base time and let the clients do the adjusting. Funny thing is since 2000, the earth's has started rotating faster! No one knows why. ( At least according to the Wikipedia article on Leap Seconds ) I applied the updates last month and one of them was for a 30 minute adjustment for the time in Venezuela. Their dictator is obviously the center of the Universe! It reminded me of the movie "Banana's" where it was declared that underwear should be worn on the outside of the pants. As I understand it, there is only one timezone in all of China! I wonder if it is called "CPCT"? |
Quote:
|
I see this as a classroom assignment for use of 'date' command. For details see 'info date'. Putting everything inside 'find' is just classroom sadism.
Code:
#!/bin/bash |
Quote:
|
this command doesn't reset the time right?:
Code:
date +%a -d $1-$2-$3 |
If you use:
date +%a -d "$day/$month/$year" This will display the day of the week on that date. I changed the variable names to indicate what they represent. Code:
day=10 month=12 year=2007 Your form uses the year for the first variable: Code:
day=10 month=12 year=2007 |
Thanks I know what you mean. In order for the script to work, you'll also need to know what weekday name of a specific date. So I thought of the external date command and looked for it's syntax and I found none and that is why i referred to other functions in php or perl. I should have looked a little bit further in date's options. my mistake again :p.
|
Quote:
The date command can be used to set the system date, but only if you use the -s (or --set) option, and have sufficient privileges to do it (i.e. you are root). You should read the date manual page (enter terminal, type "man date"). Manual pages look a little confusing at first, but they all follow more or less the same format, and once you have a little experience reading them, you will be able to answer this sort of question for ourself with ease, and a lot more quickly than by asking others. To my mind, the really nice thing about manual pages is that they are arranged like a tabloid news story. The first line tries to encapsulate the general gist of the page (i.e. a one line summary of that the subject of the page is), then there's a short overview description and so o, getting more and more detailed towards the end of the page. Most manual pages have the same main sections, which are printed in CAPTIALS at the start of a line. If your manual browser is set up as most are, using less as a pager, you can search for a section, like OPTIONS easily, just by hitting / and then typing Code:
^OPT The ^ means "start of line" in less searches. |
There is also the info manual which does include examples. It really helps to see an example that has a format argument.
|
i did read the manual page of date .. i always do that since i'd prefer and find it quicker to do 'man date' than 'date --help' .. i just have not looked good enough though. btw we can also have our own way to look for the days of the week without depending on 'date'.. i know a way to do this and it's not really big.. if i'll have the time.. i'll build the script.. just for fun :)
Quote:
Edit: to make things clearer i just looked at these: Code:
date [OPTION]... [+FORMAT] Code:
-d, --date=STRING |
'info date' info is much more complete than 'man date'
|
All times are GMT -5. The time now is 06:02 AM. |