LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-10-2016, 03:43 PM   #1
rm_-rf_windows
Member
 
Registered: Jun 2007
Location: Europe
Distribution: Ubuntu
Posts: 283

Rep: Reputation: 27
How to remove all hidden directories and folders, and only hidden directories and folders


Hi there!

I've spent about an hour looking for an answer to this question and was surprised not find a clear answer. At times the initial poster wasn't clear in what he wanted, so I'll try to be very clear.

I have made several backups of my home directory on a hard disk and now realize that the backups have copied all hidden directories and files. I would now like to delete hidden directories and files in these backups in order to free up some space on my hard disk.

In other words, the backup of my home directory may contain something like the following:

Code:
.                     .emacs             .gnome2_private      .mozilla                .pulse-cookie               .TrueCrypt-lock-user
..                    .emacs-bkp         .gstreamer-0.10      .mozilla-thunderbird    .purple                     .update-notifier
.adobe                .emacs.d           .gtk-bookmarks       .mplayer                .qt                         .ure
.android              .epiphany          .gvfs                Music                   .recently-used              Videos
.AtelierB             es                 .hplip               .mysql_history          .recently-used.xbel         .viminfo
Azureus Downloads     .esd_auth          hs_err_pid24894.log  .nano_history           .recently-used.xbel.EQGT6V  .vnc
.bash_history         .evolution         hts-cache            .nautilus               .sbclrc                     .vpinstall.properties
.bash_logout          .festival_history  hts-log.txt          .nbi                    .SciTEUser.properties       .vplls
.bashrc               .filezilla         .ICEauthority        .netbeans               .scripts                    .vpsuite_installation.xml
.bashrc.bkp           .fontconfig        .icedteaplugin       .netbeans-registration  .Skype                      .wicd
bin                   FrostWire          .icons               .netx                   .slime                      .winefish
I want to delete everything EXCEPT the following folders/files: Asureuz\ Downloads, bin, es, Frostwire, hs_err_pid24894.log, hts-cache, hts-log.txt, Music, Videos

What is the simplest and safest way to do this, preferably a command I can run from the terminal?

Thanks in advance.

RM

Last edited by rm_-rf_windows; 04-10-2016 at 03:44 PM.
 
Old 04-10-2016, 03:53 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 15,326
Blog Entries: 25

Rep: Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391
You could try this command. I would make a copy of one the backups and test on the copy first, just to make sure it works, as I'm just doing this off the top of my head.

Code:
rm -r .*            <---The "-r" means "recursive."
For backup purposes, you might want to look at using rsync and writing a little script to back up only the directories you wish to back up.

http://www.tecmint.com/rsync-local-r...tion-commands/
 
Old 04-10-2016, 03:58 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,171
Blog Entries: 11

Rep: Reputation: 3092Reputation: 3092Reputation: 3092Reputation: 3092Reputation: 3092Reputation: 3092Reputation: 3092Reputation: 3092Reputation: 3092Reputation: 3092Reputation: 3092
As frankbell says, except make the glob a little more specific to prevent walking back up the parent directory...

Code:
rm -r .[a-zA-Z_]*
And the same caution - try it in a safe environment first!

But try this and see if it gives you the right list...

Code:
ls .[a-zA-Z_]*

Last edited by astrogeek; 04-10-2016 at 04:01 PM.
 
1 members found this post helpful.
Old 04-10-2016, 10:21 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3176Reputation: 3176Reputation: 3176Reputation: 3176Reputation: 3176Reputation: 3176Reputation: 3176Reputation: 3176Reputation: 3176Reputation: 3176Reputation: 3176
Or... in one directory... [font=courier]ls -1 .* | xargs rm[/font\ (note that this is "dash-one" not "dash-el")
 
Old 04-11-2016, 08:17 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 15,326
Blog Entries: 25

Rep: Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391Reputation: 4391
Thanks, Astrogeek. Globbing makes my brain hurt and every little bit someone teaches me is appreciated.
 
Old 04-12-2016, 07:28 AM   #6
rm_-rf_windows
Member
 
Registered: Jun 2007
Location: Europe
Distribution: Ubuntu
Posts: 283

Original Poster
Rep: Reputation: 27
Hi again,

Many thanks for your quick replies!

This worked like a charm (I added a hyphen):

Code:
rm -r .[a-zA-Z_-]*
I have two other related questions that I will put in two separate posts to facilitate search results for people looking for answers to each respective question:

- a better copy command to avoid copying hidden files (link to post here)

- a way of fusing two backups that could BOTH contain common and different elements (link to post here)

Many thanks,

RM

Last edited by rm_-rf_windows; 04-12-2016 at 07:54 AM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add/Remove Hidden and ReadOnly attributes from files and directories on vfat filesyst Snigger Linux - Desktop 6 11-11-2015 08:31 AM
ls -R - without hidden folders j0hnsmith Linux - Newbie 2 09-27-2009 09:46 PM
Cleaning Hidden Folders Raymond C. Glassford Mandriva 3 07-01-2008 12:10 AM
hidden folders tenmiles Linux - General 5 11-23-2004 02:37 AM
Hidden folders ... how can I view them? orange400 Linux - General 4 03-23-2003 11:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:20 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration