LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices



Reply
 
Search this Thread
Old 01-09-2013, 08:13 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,268

Rep: Reputation: 49
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 08:32 PM.
 
Old 01-09-2013, 08:32 PM   #2
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,268

Original Poster
Rep: Reputation: 49
Thinking it over again, I came with
Code:
$ rm -r .[0-z]*
It worked.
 
Old 01-10-2013, 01:54 AM   #3
Thad E Ginataom
Member
 
Registered: Mar 2011
Distribution: Ubuntu 12.04 with KXStudio, MATE & Compiz
Posts: 46

Rep: Reputation: 7
Quote:
It worked.
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.
 
Old 01-10-2013, 03:43 AM   #4
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 133Reputation: 133
I'd use something like this:

Code:
find . -type d -name ".*" -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \;
 
Old 01-10-2013, 04:41 AM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,268

Original Poster
Rep: Reputation: 49
Quote:
Originally Posted by Thad E Ginataom View Post
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.
 
Old 01-10-2013, 05:47 AM   #6
GazL
Senior Member
 
Registered: May 2008
Posts: 3,502

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
Quote:
Originally Posted by kabamaru View Post
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 06:02 AM.
 
Old 01-16-2013, 07:48 AM   #7
Thad E Ginataom
Member
 
Registered: Mar 2011
Distribution: Ubuntu 12.04 with KXStudio, MATE & Compiz
Posts: 46

Rep: Reputation: 7
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.
 
Old 01-16-2013, 10:07 PM   #8
perbh
Member
 
Registered: May 2008
Location: Republic of Texas
Posts: 261

Rep: Reputation: 40
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 01:06 AM.
 
1 members found this post helpful.
Old 01-17-2013, 02:10 AM   #9
Thad E Ginataom
Member
 
Registered: Mar 2011
Distribution: Ubuntu 12.04 with KXStudio, MATE & Compiz
Posts: 46

Rep: Reputation: 7
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]
 
Old 01-17-2013, 08:35 AM   #10
wstewart
Member
 
Registered: Dec 2012
Location: Tampa, FL
Distribution: Slackware, FreeBSD, CentOS
Posts: 41

Rep: Reputation: 1
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 08:56 AM.
 
Old 01-18-2013, 01:06 PM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,679
Blog Entries: 54

Rep: Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955
Quote:
Originally Posted by wstewart View Post
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...
 
Old 01-18-2013, 01:35 PM   #12
qweasd
Member
 
Registered: May 2010
Posts: 484

Rep: Reputation: Disabled
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.
Old 01-19-2013, 12:47 PM   #13
Thad E Ginataom
Member
 
Registered: Mar 2011
Distribution: Ubuntu 12.04 with KXStudio, MATE & Compiz
Posts: 46

Rep: Reputation: 7
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] rename HIDDEN files recursively mrmnemo Linux - Software 26 09-17-2012 06:20 AM
[SOLVED] recursively cp all directories, files and hidden files WildDrake! Linux - Newbie 9 05-18-2010 05:39 PM
recursively making directories will.flanagan Linux - Newbie 10 04-27-2009 07:18 PM
chmod directories recursively mfilippa Linux - Newbie 3 04-17-2006 08:24 PM
Copying hidden files recursively? mrd Linux - General 1 09-30-2005 08:51 AM


All times are GMT -5. The time now is 01:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration