Author Topic: Command for deleting files across multiple directories  (Read 236 times)

Offline satuser083

  • Hero Member
  • *****
  • Posts: 510
Command for deleting files across multiple directories
« on: April 18, 2012, 01:20:12 PM »
I'm trying to clean up my system and have noticed almost 200 files named bookmarks-xxxx.json in the .mozilla directory, taking up the best part of half a gig. Many of these are very old, so I'd like to kill them. Is there a delete command (interactive) that can span multiple directories, or do I have to do it the hard way? Thanks.

Offline pags

  • Hero Member
  • *****
  • Posts: 2519
  • Keep it clean.
Re: Command for deleting files across multiple directories
« Reply #1 on: April 18, 2012, 01:39:44 PM »
In PCLOS, rm is aliased to rm -i, so it's interactive by default...

You can span multiple directories in bash with wildcards.  For example, with ls:
Code: [Select]
[jpaglia@paglia-e6500 ~]$ ls Documents/*/*.txt
Documents/2ocr/characterCount.txt     Documents/OTA_HDTV/82E16thS(map.hamilton.ca).txt
Documents/dhcp_settings/NBC_MACs.txt  Documents/scribus-CD_jewel_case-template/README.txt
Documents/haha/ghetto spelling.txt    Documents/USBkey4GB.20101104_1156/PrintFiles.txt

Documents/lunix-mag/In_The_Beginning_command.txt:
command.txt
[jpaglia@paglia-e6500 ~]$
or
Code: [Select]
[jpaglia@paglia-e6500 ~]$ ls .mozilla/*/*/book*
.mozilla/firefox/0x8u5nz1.default/bookmarks.html

.mozilla/firefox/0x8u5nz1.default/bookmarkbackups:
bookmarks-2012-02-06.json  bookmarks-2012-02-29.json  bookmarks-2012-03-10.json  bookmarks-2012-03-23.json
bookmarks-2012-02-23.json  bookmarks-2012-03-06.json  bookmarks-2012-03-15.json  bookmarks-2012-03-26.json
bookmarks-2012-02-27.json  bookmarks-2012-03-07.json  bookmarks-2012-03-21.json
[jpaglia@paglia-e6500 ~]$

The same could be done with rm:
Code: [Select]
rm .mozilla/*/*/bookmarks-*.json

Careful, it could be dangerous!
 ;)

Offline aherkey

  • Full Member
  • ***
  • Posts: 109
Re: Command for deleting files across multiple directories
« Reply #2 on: April 18, 2012, 04:08:32 PM »
Assuming you are in your home directory and the files are somewhere under .mozilla.
Change to the base directory of where the files are located:
  cd .mozilla

Run this command first to make sure it finds the correct files:
   find . -name "bookmarks-*.json"

Then run this to interactively remove them:
   find . -name "bookmarks-*.json" -exec rm -i {} \;

Note: You can use the full path instead of the "." in the find command:
        find /home/userid/.mozilla -name "bookmarks-*.json"