Slackware This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-09-2013, 07:13 PM
|
#1
|
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 2,487
Rep:
|
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.
Last edited by stf92; 01-09-2013 at 07:32 PM.
|
|
|
|
01-09-2013, 07:32 PM
|
#2
|
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 2,487
Original Poster
Rep:
|
Thinking it over again, I came with
It worked.
|
|
|
|
01-10-2013, 12:54 AM
|
#3
|
|
Member
Registered: Mar 2011
Distribution: Ubuntu 12.04 with KXStudio, MATE & Compiz
Posts: 46
Rep:
|
Did it?
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.
|
|
|
|
01-10-2013, 02:43 AM
|
#4
|
|
Member
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 239
Rep:
|
I'd use something like this:
Code:
find . -type d -name ".*" -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \;
|
|
|
|
01-10-2013, 03:41 AM
|
#5
|
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 2,487
Original Poster
Rep:
|
Quote:
Originally Posted by Thad E Ginataom
Did it?
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.
|
|
|
|
01-10-2013, 04:47 AM
|
#6
|
|
Senior Member
Registered: May 2008
Posts: 2,843
|
Quote:
Originally Posted by kabamaru
I'd use something like this:
Code:
find . -type d -name ".*" -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \;
|
Just a word of caution for anyone reading this:
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.
Last edited by GazL; 01-10-2013 at 05:02 AM.
|
|
|
|
01-16-2013, 06:48 AM
|
#7
|
|
Member
Registered: Mar 2011
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.
|
|
|
|
01-16-2013, 09:07 PM
|
#8
|
|
Member
Registered: May 2008
Location: Republic of Texas
Posts: 55
Rep:
|
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
... just my 2c-worth
Last edited by perbh; 01-18-2013 at 12:06 AM.
|
|
|
1 members found this post helpful.
|
01-17-2013, 01:10 AM
|
#9
|
|
Member
Registered: Mar 2011
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.
Sorry... OT to the thread [Blush]
|
|
|
|
01-17-2013, 07:35 AM
|
#10
|
|
Member
Registered: Dec 2012
Location: Tampa, FL
Distribution: Slackware, FreeBSD, CentOS
Posts: 37
Rep: 
|
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.
Last edited by wstewart; 01-17-2013 at 07:56 AM.
|
|
|
|
01-18-2013, 12:06 PM
|
#11
|
|
Moderator
Registered: May 2001
Posts: 24,790
|
Quote:
Originally Posted by wstewart
I'm sure there's a simpler way to go about doing it.
|
Not only that, see the 'rm' and 'find' commands above, but http://mywiki.wooledge.org/ParsingLs to start with...
|
|
|
|
01-18-2013, 12:35 PM
|
#12
|
|
Member
Registered: May 2010
Posts: 338
Rep: 
|
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.
|
|
|
1 members found this post helpful.
|
01-19-2013, 11:47 AM
|
#13
|
|
Member
Registered: Mar 2011
Distribution: Ubuntu 12.04 with KXStudio, MATE & Compiz
Posts: 46
Rep:
|
I have never before answered any of your posts --- so perhaps you'll not mind me agreeing that
Quote:
|
there's a simpler way to go about doing it.
|
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:15 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|