[SOLVED] rm: Recursively erasing all hidden directories but not the other ones?
SlackwareThis Forum is for the discussion of Slackware Linux.
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 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.
It was like this: user1 (me) started X and the GUI was in some way corrupted. It was not X, as /etc/Xorg.0.log showed. I then created user2, copied two .* file from /home/user1 which I cared about, and started X as user2. At least now I could use the GUI.
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.
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.
Distribution: Ubuntu 12.04 with KXStudio, MATE & Compiz
Posts: 46
Rep:
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"
# as root:host:~ # mkdir -m 0777 /disk/{$dirs}
# as user, from my home:host:~ $ for d in $(echo $dirs | tr ',' ' '); do rmdir $d; ln -s /disk/$d $d; done
Distribution: Ubuntu 12.04 with KXStudio, MATE & Compiz
Posts: 46
Rep:
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.