You are not logged in.
Pages: 1
Hopefully someone can explain to me exactly how the wildcard works before I hose my system.
Consider these case as user not root.
Ok if I am cleaning a directory I may run this
rm -rf *
and as my finger comes off the enter key I fear it will see the .. directory and flush my entire home directory, but of course it doesn't. In fact it doesn't remove any hidden files, those starting with a dot.
So I think maybe the wildcard cannot start with a dot, but this isn't the case because if were to run
rm -rf .*
It would wipe out the .. directory. I haven't actually run that but I know it tries with 'rm .*' but cant because it is a directory.
So could someone please clarify how wildcard is working?
Offline
Not that I can give an explanation, but 'rm -rf .*' would only delete all the files and dirs which start with a dot; but would do nothing to ../ (I just tried
Offline
Cool that seems to be explained by man rm.
--preserve-root being the default setting, that is nice to know. But I still am wondering about the dot for wildcard.
Offline
Well enough googling got the answer wouldn't you know.
The default shell setting does not expand to files begining with a dot,
$ shopt dotglob
dotglob off
but the shell option can be changed
$ shopt -s dotglob
$ shopt dotglob
dotglob on
Now 'rm *' or 'cp *' or whatever will expand * to regular files and .* files.
Offline
$ shopt dotglob
dotglob off
$ rm -rfv .*
rm: cannot remove directory `.'
rm: cannot remove directory `..'
$ shopt -s dotglob
$ shopt dotglob
dotglob on
$ rm -rfv .*
rm: cannot remove directory `.'
rm: cannot remove directory `..'
$ rm -rfv *
removed `file3'
I'm not sure why it can't delete '.' or '..' I guess that it's a protection code inside rm or something, because I can remove the dir using other shell, so the first shell will be in a non existent directory
you should use rm -rf .[^.]*
$ ls -a
. .. .a ...a .b
$ rm -rfv .[^.]*
removed `.a'
removed `.b'
or if you have files with several dots
$ rm -rfv .*[^.]*
removed `.a'
removed `...a'
removed `.b'
the [^.] thing mach all character that aren't a dot
Last edited by noalwin (2008-05-17 23:05:03)
Offline
I for one am always confused with these things. (one reason I use mc)
A bit more typing, but 'find -mindepth 1 -maxdepth 1' will match what you want.
find . -mindepth 1 -maxdepth 1 -print0 | xargs -0 rm -rf
Offline
I for one am always confused with these things. (one reason I use mc)
A bit more typing, but 'find -mindepth 1 -maxdepth 1' will match what you want.find . -mindepth 1 -maxdepth 1 -print0 | xargs -0 rm -rf
I think that
find . -mindepth 1 -maxdepth 1 -delete
it's simpler and more efficient
Offline
Pages: 1