rm: Recursively erasing all hidden directories but not the other ones?
What's said. Bear in mind this is a weird question and, as such, I could not find references in either LQ or google.
|
Thinking it over again, I came with
Code:
$ rm -r .[0-z]* |
Quote:
But what else did it do? How many files did it rm as well as directories? Was that what you really wanted? Executing that command in a home directory, for instance, could be disastrous. |
I'd use something like this:
Code:
find . -type d -name ".*" -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \; |
Quote:
From here I started the mail client and it downloaded all of the mail from my ISP sever. But now user1 settings had no importance to me. .bashhistory, .vimrc (I have vim's settings in a global vimrc) and so on. The only thing important were some big trees in /home/user1. So, in this dir I had the .* files and dirs, and the big directories, not hidden I wanted to preserve. Then I executed 'rm -r .[0-z]*' from /home/user1. |
Quote:
That -mindepth 1 option is VERY IMPORTANT as otherwise it'll process the '.' (current directory) In these sorts of situations I always prefer to use explicit paths rather than relative ones as it is a little less accident prone. find /home/gazl -name '.*' ...... wouldn't be nearly as accident prone if one were to forget the "-mindepth 1" option or be in the wrong CWD.. edit: Actually, having just tried it on /tmp/something it's not quite as bad as I thought, as it will result in a "rm: cannot remove directory: '.'", but it clearly shows that it tried to remove it so its still something to be wary of. |
find is the tool of choice for all but the simplest such tasks. We can also play safe by using -ls, -print, or even -exec ls -r '{}' \; to be sure about what find is finding, before inserting the actual command. The -r option to rm, of course, adds an extra level of danger. When one has to use rm with highly dangerous wildcards, there is always the -i option.
|
I am always surprised of the number of people that regard /home/$USER as a holy grail and even put it on a separate filesystem. Ok, if you run only _one_ distro, I can see the point - if you have more - absolutely not. Dot-files should not be common between distros - let /home be part of the root filesystem (with all its dot-files for each user - even if there is only one) and make a big filesystem for your private files. For myself, I typically use around 20 gigs for each distro and its root filesystem, a small partition (#1) for grub-legacy where I chainload to each distro which has its own bootloader on the root partition, and keep one big partition for my private files. This way, anything OS-dependent (which the dot-files are) are kept where they belong - under the OS. Also, it means you can replace one distro with another without touching your private files. The downside is that each time you install a new distro - you have to go through the setup (generating dot-files) to make it look the way you want - however, as far as _I_ am concerned, that is a small price to pay.
These days it's common to have Documents, Pictures, Music, etc in your home directory - what I do is to make links to where I keep my private files - keeping them private across distros. For example, my big private partition is called '/disk', then I make links like so: Code:
dirs="Documents,Downloads,Music,Pictures,Public,Templates,Videos" |
I can add my 2c to yours.
Since I "returned" to the *nix fold a couple of years ago, I found that the number of .something files has hugely increased since my Unix green-screen days, and also that some of the stuff that gets stored in the home directory, such as mail files, wine, etc, can get rather large. Added to which, I want to be able to access Thunderbird, for instance, from multiple versions/distros, and I want settings and data for Firefox to be the same (yes, these days, FF sync does a good job) just to name two programs. Thus, in my mind, the concept of $HOME as a place where one "lives" is now outdated and has a become a place where configuration files are kept --- and, where these configuration files are cross-version, links do the job just fine. I actually have two big file systems, one called Library (of the human, rather than the development, kind) and one called Data where all the other shared stuff goes. Library is available to the rest of the family on the net, Data is not. Old habits have made me still have a separate /home, but, in future, I'll take your advice and not even do that. Sorry... OT to the thread [Blush] |
Provided you are using the same version of ls as I am, you could use
for i in $(ls -al|grep -vE '\s\./$|\s\.\./$'|grep -e '\/$'|awk '{print $9}'); do rm -r $i;done But I'm sure there's a simpler way to go about doing it. |
Quote:
|
I don't think the notion of $HOME as the place where one "lives" is dead. Not for me, at least,
not on my laptop. Data, configuration, and odd things like dosbox environment all belong there, IMHO. What drives me bananas is the glut of .whatevers littering the place. I really like ~/.config/ and I wish more developers used it. |
I have never before answered any of your posts --- so perhaps you'll not mind me agreeing that
Quote:
|
All times are GMT -5. The time now is 02:29 AM. |