Results 1 to 6 of 6
Ok, here's a toughie...
Code:
tar --after-date="$START_TIME" -cf "my-archive.tar" my-folder/*?[!*.reg]
Because of the --after-date thing, this ommits a lot of files, but it still includes the directories they were in, ...
- 03-05-2008 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 6
shell script... exclude empty directories
Ok, here's a toughie...
Because of the --after-date thing, this ommits a lot of files, but it still includes the directories they were in, which means I'm left with lots of empty directories in my archive. Any ideas how to get rid of them? I don't mind breaking this statement up into more than one.Code:tar --after-date="$START_TIME" -cf "my-archive.tar" my-folder/*?[!*.reg]
-Nathan
- 03-05-2008 #2
First, would you please explain what you mean by this?
In the famous words of Inigo Montoya, I do not think it means what you think it means.Code:*?[!*.reg]
--
Bill
Old age and treachery will overcome youth and skill.
- 03-05-2008 #3Just Joined!
- Join Date
- Mar 2008
- Posts
- 6
- 03-05-2008 #4Just Joined!
- Join Date
- Mar 2008
- Posts
- 6
Oh, and I might get shot down for admitting this, but I don't quite understand why it works this way. Although I'm very happy that it does. And I'll make sure I understand it before it becomes important.
- 03-05-2008 #5Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
No.
Use the bash man page when in doubt. Concretely, for this case, search for "Pathname Expansion". There, you can read this (amongst many other useful things):
Look at the bolds.
Originally Posted by bash man page
So, as a sample, this command:
Would list all the files whose name has at least one character (because of the ?, which doesn't match the null string), and doesn't end on one of these characters (the commas are just separators): *, . (dot), r, e OR g.Code:ls -d *?[!*.reg]
The reason why .reg files are not listed, is just because they end in "g", which is a side effect. But that is not the intended effect, and might render your backups completely useless if it left out some other important files ended in one of those characters.
So, no, your regexp doesn't work.
Here you have some examples to illustrate what I said:
Note however, that this is an extended syntax, and as the man page says, it only works if you have the bash shell option extglob turned on.$ ls
dir flix.reg kiss* p pepe pepe. p_output_10 p_output_4 p_output_7 r reg
$ ls *?[!*.reg]
p_output_10 p_output_4 p_output_7
ls *.?(reg)
flix.reg pepe.
$ ls *.!(reg)
pepe.
$ ls *!(reg)
flix.reg kiss* p pepe pepe. p_output_10 p_output_4 p_output_7
dir:
r:
reg:
$ ls !(*.reg)
kiss* p pepe pepe. p_output_10 p_output_4 p_output_7
dir:
r:
reg:
You can turn it on by doing "shopt -s extglob". Its not persistent, so, put it into your bashrc and bash_profile files if you intent to use this regularly (or just include it in your script).
- 03-06-2008 #6Just Joined!
- Join Date
- Mar 2008
- Posts
- 6
Ah, ok thanks. I just got that off the internet somewhere. Can't remember where. Looks like I need to rewrite it.
I knew that [] matches any of the characters, but I guess I just assumed something about the syntax made this different.
I don't suppose I needed to make my second post! You already knew that I didn't understand. I'll have a go myself, then come back if I get stuck... unless writing it all for me is your idea of fun


Reply With Quote
