Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
But find doesn't seem to want to delete folders...
The entire script is:
Code:
#!/bin/bash
root=$1
if [ -z $1 ]; then root=`pwd`; fi
compact_f()
{
find $fold -maxdepth 0 -type d -exec rsync -r {}/ $base \; -exec rm -fr {} \; 2> /dev/null
}
for ((year=2004; year < `date +%Y`; year++)); do
base=$root/$year
fold=$base.[0-9][0-9]*
compact_f
done
for ((j=1; j < `date +%m`; j++)); do
year=`date +%Y`
month=$j
if [ $month -lt 10 ]; then month=0$month; fi
base=$root/$year.$month
fold=$base.[0-9][0-9]*
compact_f
done
for ((k=1; k < `date +%d`; k++)); do
year=`date +%Y`
month=`date +%m`
day=$k
if [ $day -lt 10 ]; then day=0$day; fi
base=$root/$year.$month.$day
fold=$base\_[0-9][0-9].[0-9][0-9].[0-9][0-9]
compact_f
done
It takes my archive folders which are created like YYYY.MM.DD_HH.MM.SS when they are first generated. After the day is up, it compacts all of the folders for a particular day into one (YYYY.MM.DD), after the month is up it compacts all of the folders for that month into one (YYYY.MM), and the same for the year (YYYY).
It works pretty well, I'm just trying to speed it up a little. Any suggestions?
(the subfolder 2008.11.11_11.11.11 was not seen by rsync, just like you want)
With maxdepth=0, rsync is just called once, with "." as source dir. None of 2008.04* are arguments to rsync.
There is another problem too. maxdepth=1 returns "." as first entry.
With maxdepth=1, rsync will process all dirs twice: one with "." and again for each dir in "."
Is that what you want or I missed something ?
regards,
Last edited by marozsas; 04-16-2008 at 11:59 AM.
Reason: just to add tree output
I guess my idea wasn't so dumb after all. There is a sample in the find info page that uses -maxdepth 0. This setting tests files listed as arguments. For example: find filea fileb filec filed -maxdepth 0 -empty will test just the 3 files in the arguments and return if one is empty.
The example in the info find manual has a find command argument of xargs to supply the arguments.
A perl script modifies the result of the first find command and this is fed to "xargs find {} maxdepth 0 ...".
I found that my explanation did the same thing with -maxdepth 1 so it wasn't a good demonstration.
I created 4 files, two that were empty. I had 3 files listed in the find command: find filea fileb filec -maxdepth 0 -empty
After repeating this experiment with -maxdepth 1, I decided to stick with the example in the info file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.