LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 05-16-2014, 11:53 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
Deleting all hidden directories in ~/.


Hi: I'm trying to delete all hidden directories in my home directory. This seems an easy task but all my efforts are vain. Any suggestion?
 
Old 05-16-2014, 12:03 PM   #2
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
rm -r .*

don't work ?

more proper way could be

rm -r .*/*
rmdir .*

rmdir won't delete folders if they have anything in them

never needed to do this tbh
 
Old 05-16-2014, 12:04 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
It seems 'rm -r .*' works. Though I don't have a cue what's really to be erased. With normal files, I can always do, say 'ls y*' and see the output. Then, just replacing ls by rm I possitively know exactly what will be erased.
 
Old 05-16-2014, 12:07 PM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Code:
ls -d .*
will list all the directories/files starting with a period, sometimes called hidden directories/files.

Code:
rm -Ri `ls -d .*`
Will delete all hidden directories/files, but prompt you for every deletion as well. Delete only what you wish.

Last edited by szboardstretcher; 05-16-2014 at 12:48 PM.
 
1 members found this post helpful.
Old 05-16-2014, 12:08 PM   #5
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware64 15.0 (started with 13.37). Testing -current in a spare partition.
Posts: 928

Rep: Reputation: 515Reputation: 515Reputation: 515Reputation: 515Reputation: 515Reputation: 515
Try
find ~ -type d -mount -maxdepth 1 -name .\* -ok echo {} \;

if it's all right with echo then you can replace by the dangerous rm -rf

The -mount option doesn't descend into other files systems.
 
Old 05-16-2014, 12:24 PM   #6
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
Quote:
Originally Posted by stf92 View Post
It seems 'rm -r .*' works. Though I don't have a cue what's really to be erased. With normal files, I can always do, say 'ls y*' and see the output. Then, just replacing ls by rm I possitively know exactly what will be erased.
try

echo .*

"*" is for globbing, a shell thing (i think this is called shell expansion, not sure)
think of it as half arsed regex
bdw unlike regex, shell doesn't take "." as any char, "?" means any char in shell

ignore . (this directory) and .. (parent directory) since you can't remove a dir that is in use (you are in it)

PS don't use -f with rm, it's rare when you really have to use it
also as always, take care when not sure 'cuz ".." can give you headaches (weird links also)

Last edited by genss; 05-16-2014 at 12:31 PM.
 
1 members found this post helpful.
Old 05-16-2014, 12:26 PM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Quote:
Originally Posted by szboardstretcher View Post
Code:
ls -d .*
will list all the directories starting with a period,
No it won't. "-d" doesn't do what you think it does. It will list any files or directories in the current directory starting with a '.'
 
1 members found this post helpful.
Old 05-16-2014, 12:32 PM   #8
perbh
Member
 
Registered: May 2008
Location: Republic of Texas
Posts: 393

Rep: Reputation: 81
Just a quick question (and not an answer to your question - others have given enough of that):

Just _WHY_ would you want to delete all the dot-files/directories? That's where all your setup is.
That would be like creating a completely new user! (well, almost)

Which is why I never use my home-directory for 'personal' files - dot-files/dirs are not always portable across distros ...

Last edited by perbh; 05-16-2014 at 12:34 PM.
 
2 members found this post helpful.
Old 05-16-2014, 05:33 PM   #9
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by perbh View Post
Just _WHY_ would you want to delete all the dot-files/directories?
That is the REAL question.
Anyway, it always good kung.fu to test operations like this, so I advise "echo" before any real rm'ing to "see" what will be removed, first.
Think of it as a "dry run" as there's undo button except for backups, and you have those, right?
Code:
echo rm -r .*
 
1 members found this post helpful.
Old 05-17-2014, 04:27 AM   #10
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by perbh View Post
Just a quick question (and not an answer to your question - others have given enough of that):

Just _WHY_ would you want to delete all the dot-files/directories? That's where all your setup is.
That would be like creating a completely new user! (well, almost)

Which is why I never use my home-directory for 'personal' files - dot-files/dirs are not always portable across distros ...
I would politely answer you that's my business. As a side note, "creating" a new user is what it is about.
 
Old 05-17-2014, 04:45 AM   #11
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by GazL View Post
No it won't. "-d" doesn't do what you think it does. It will list any files or directories in the current directory starting with a '.'
szboardstretcher said "It will list any directories/files starting with a '.'. I think it's the superior choice. 'ls -d .*' will show exactly what will be erased by 'rm -r .*', because there's only one interpretation of '.*', namely, that of the shell. Hence, typing 'ls -d .*' you can then recall the command from the keyboard buffer (arrow key), press <Home>, delete the first five chars and type 'rm -r', in this way there being no room for typing errors. It would be easier if there would be some means of placing the keyboard in replace mode.
 
Old 05-17-2014, 08:09 AM   #12
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Quote:
Originally Posted by stf92 View Post
szboardstretcher said "It will list any directories/files starting with a '.'.
Not when I posted it didn't. If you were paying attention you would have seen that it's been edited since my comment.


Quote:
Originally Posted by stf92 View Post
I think it's the superior choice.
Paulo2's "find" solution is the safer choice. The use of ".*" wildcards should be avoided because of their tendency to match the "." and ".." directory links. You may get away with it in the case of 'rm' but you might not be so lucky when used with other commands and end up with unexpected results. IMO the ".*" pattern is dangerous and best avoided completely.

But, as the Paul Simon song goes: "Who am I to blow against the wind."

Last edited by GazL; 05-17-2014 at 08:12 AM. Reason: speeling. ;)
 
Old 05-17-2014, 11:49 AM   #13
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware64 15.0 (started with 13.37). Testing -current in a spare partition.
Posts: 928

Rep: Reputation: 515Reputation: 515Reputation: 515Reputation: 515Reputation: 515Reputation: 515
I suggested find with -mount option because if, for some strange reason,
you mount some device at let's say, ~/.my-hidden-device and you remove
all hidden directories with that device mounted, you will erase it too.



Quote:
Originally Posted by GazL View Post
But, as the Paul Simon song goes: "Who am I to blow against the wind."
From Graceland? Very good album, I have a vinyl copy
 
Old 05-17-2014, 12:50 PM   #14
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Quote:
Originally Posted by Paulo2 View Post
From Graceland? Very good album, I have a vinyl copy
Yep. I first bought it on cassette tape, then again on CD.
 
  


Reply



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
Deleting hidden partitions on usb drive ZimMonkey Linux - Newbie 17 02-23-2010 05:48 PM
Hidden Directories in Vista vxc69 General 7 07-11-2008 01:38 PM
Trouble Deleting Hidden Partition on External Drive jman82s Linux - Hardware 2 11-27-2007 06:48 PM
Deleting hidden lines in Wondows XP registry -- How? moxieman99 General 2 11-07-2007 07:07 AM
hidden directories Alwyn Linux - Newbie 1 07-19-2005 06:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:27 PM.

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
Open Source Consulting | Domain Registration