deleting *all* in current directory (bash)
While I am not really a newb any more, this question seems newbie-ish to me so here it goes...
In a directory, if one types, "rm -rf *", everything is removed ... except for directories and files beginning with ".". If one types "rm -rf ." again, one gets an error message and as before, directories and files beginning with "." are not deleted. Short of a kludge involving sub-shells and the use of find, is there a good simple safe way to have the effect of "rm -rf" in the current directory *plus* the removal of files beginning with "."? Thank you. |
First of all, I don't recommend the direct use of `rm`. I think it's a dangerous tool that should be avoided in favour of a good command line trash application, like trashy or trash-cli.
That said, you're looking for some expansion. Using `ls` instead of `rm` for copy-pasta safety: Code:
ls {.,}* |
If you're using Bash:
shopt -s dotglob ensures that the * glob will subsequently match both unhidden and hidden files. |
I have similar trouble with this particular situation muh damn self.
I check my shit with Code:
echo rm ... Just sayin' |
don't use rm for this, use find
Code:
# mkdir -p test/test |
* .??*
Yes, be careful with this (I just accidentally deleted my .bashrc in experimenting with this)!
For quick simplicity, I add/use: .??* Tho/but that will not get -single_letter- 'hidden' files, like .a To check if there's any such [1letter dot-files], I then do: ls -d .? Take a few minutes to look into the -d and how `echo` acts 'like' a `ls -d` An important point here is to NOT 'hit' [match in `rm`] . and .. (the current dir and it's 'parent') Getting a bit more 'theoretical' here, note how .?* works (-different- than in grep/regex!) ? matches any one character; * any zero or more; . a dot itself echo .?* |
I tend to use:
rm -rf .[a-zA-Z0-9]* or just rm -rf .[a-z]* |
just:
Code:
cd .. |
Oh, it helps to ReallyRead#1:redface:
Quote:
(I was about to suggest: cd ..; rm -fir $OLDPWD; mkdir $OLDPWD; cd $OLDPWD but then realized that 'esoterically theoretical' != 'good simple safe' :D ) OP, can you please use ThreadTools at top, to mark this thread as "[SOLVED]". Thanks! |
use " srm" it may or may not be installed but the source is on sourceforge
https://sourceforge.net/projects/srm/files/ BUT as always use CAUTION |
Code:
alias rm="rm -i" |
Wow, not as simple a question as I had thought. Thank you, everyone, for the replies.
Now at some point, when I feel brave, to pick which method to try first. ;) |
Quote:
|
Quote:
Code:
rm -r .[^.]* ..?* * |
that is why i like " srm "
Code:
srm -h example Code:
:~> srm -sr * |
Quote:
|
I like Post #7 ; the sort of definitive thing I'd use for eg getting rid of 'impossibly named' files ;)
Of course, you might want to make a note of the ownerships+perms before deleting it ... |
Quote:
|
All times are GMT -5. The time now is 09:29 AM. |