Quote:
My best suggestion is to always stage that in a command line first to validate that you get what you desire. Don't just jump in and assume the .zip extension works, try it out and also transfer that file to a destination system where you wish to re-read it. Or whichever extension you end up choosing. Note that there used to be a -z flag for tar, and it probably still accepts it but ignores it silently. It might be useful for you to check the version of tar you have, check the manual page for the tar you have and verify that it will work in the manners I'm describing. |
UPDATE...Ok I got it partially working. Here is the code again:
Code:
#! /bin/bash Code:
Compressing folders Jan to Jun 01062017 01042017 01032017 01012017 01022017 01052017 which of course nothing should have been compressed. Any help is highly appreciated! |
-mtime 182 finds files modified exactly 182 days ago. Since there is not an option +mtime your results are not valid.
-mtime n (n*24 hours) +n for greater than n, -n for less than n, n for exactly n. If you want to go by mtime you will need to specify a range but you need to calculate the days based upon the current date. If today was 12/31 then something like the following would find files between Jan 1 - Jun 30 (I did not calculate exact days...) -mtime +182 –mtime -365 You can find files based upon the file name using wildcard expansion. Although it isn't pretty and others might have a better idea. find . -maxdepth 1 -name "0[0-6]*" To specify a year find . -maxdepth 1 -name "0[0-6]??YYYY" Would find all files/directories in the current working directory from Jan - Jun assuming they were named MMDDYYYY. For July-August find . -maxdepth 1 -name "0[7-9]*" For Sept-Dec find . -maxdepth 1 -name "1[0-2]*" July-Dec would need 3 commands i.e two to create append the tar file and a separate command to compress. I know that some of these commands can be confusing and in most cases you can find decent help and examples. |
Too confusing to me. I came up with a better idea. How can I compress folders( named like 01012017,02012017,etc ) based only on the first 2 digits (the month)?
Like for instance to only compress folders where the range is from 01****** to 06****** |
Would this work?
Code:
echo "Compressing folders Jan to Jun "; find . "01*" ! "06*" | xargs tar -zcvf /dir1/dir2/dir3/TESTING/JanJun${YEAR}.tar.gz;; |
Quote:
|
This is the code I used:
Code:
echo "Compressing folders Jan to Jun "; find . "01*" ! "06*" | xargs tar -zcvf /dir/dir/dir/TESTING/JanJun${YEAR}.tar.gz;; Code:
Compressing folders Jan to Jun |
There's a syntax error in your find command. I know there are shortcuts; however I always use:
Code:
find . -name "01*" This would either be six find commands, one for each month, or using a -since or date qualifier to capture the files since your last backup. Once again, I know there are highly particular requirements. I'm remembering that this is to back up information you've generated on the behalf of a company you work for in some manner. Personally I'd reorganize files once they'd been backed up. Make my backup and then move the backed up files to an "old" sub-directory or something similar. If things are so restricted that you cannot move files, such as you're not allowed to move files, and this company is so very highly specific about everything, then I question whether or not you should be keeping any copies. I've worked as a contractor for highly restrictive employers, such as government contractors, and you're not supposed to take any IP out of their shop at all. Not allowed. Then again, the security restrictions were sufficient such that if I tried to take out a drive of any type, it would be a problem, let alone bring in anything capable of storage. If this is a commercial company, or something more serious such as aviation or power grid, things like that where once again they have protected systems. Same thing. I would not be keeping any personal records. This "sounds" as if you're generating status reports and you wish to keep a copy. So ... keep a copy on another system, this laptop you mention, and back that up however best works for you. |
As stated you have to specify each month which can be done using or. Not tested but should work.
Code:
find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*"\) |
I tried this code and nothing returns but I do not want to use OR, I want to pick the folders from Jan(01*) to Jun(06*):
Code:
echo "Compressing folders Jan to Jun "; find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*"\) | xargs tar -zcvf /dir/dir/dir/TESTING/JanJun${YEAR}.tar.gz;; Code:
echo "Compressing folders Jan to Jun "; find . -type d "01*" ! "06*" | xargs tar -zcvf /dir/dir/dir/TESTING/JanJun${YEAR}.tar.gz;; Quote:
|
In my previously post there was not a space between the last " and \ i.e. "06*"\) vs "06*" \) which caused a syntax error.
Code:
$ ls Code:
find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*" \) Code:
find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*" \) | xargs tar -zcvf testme.tgz Code:
tar -tf testme.tgz |
After placing .xlsx files in the months of '02', '01' and '06' it appears that the code below works:
Code:
find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*" \) |
I just think everything is possible
|
All times are GMT -5. The time now is 01:10 PM. |