Linux: remove all directories with same name

I ran into an issue with a piece of software that created hundreds of directories amidst my music and video collections.  However, all of the directories had the exact same name.  Rather than delete all of them individually, I figured there had to be a way to delete them all with a single command.  Turns out there is.  I found the directions here.

Step 1) Open a terminal in Linux.

Step 2) Navigate to the parent directory. In other words, find a folder that contains all of the offending folders.  For example:

$ cd /home/ryan/Desktop

Step 3) Use the “find” command combined with the remove directory command to delete all of the folders with the same name.  Here’s the command:

$ find -type d -name name_of_directories -exec rm -rf {} \;

 

Here’s what the above does.  “find” calls the “find” program, telling the computer to look for something.  “-type d” tells the find program to look for directories (d) or folders rather than files.  Next is the name of the directories or folders you want to find (replace that with the name you’re searching for).  “-exec” tells the computer to execute something when it finds a directory that has the name you’re searching for.  The computer will execute the “rm” command, which means “remove” the directory.  The “-rf” modifier tell it to remove everything below the folder as well (-r is recursive), so it will delete folders with files inside them as well.  The last part “{} \;” tells the computer to iterate this for every folder it finds.

It took me a few tries to get this to work, but when it did, it was pretty slick.  Saved me hours of having to manually delete everything.  Also, just a heads up: when the command works, it will give you a list of all the folders it deleted but will say something to the effect that it could not find the folders, which is a very awkward way of saying, “I just deleted this folder; it used to be there, but now it’s not.”

 144 total views

Linux: Getting “Find” working in Dolphin on KDE (Linux Mint and Kubuntu)

One of the reasons I switched to KDE from Gnome was Dolphin, the file manager that ships with KDE.  When I made the switch a couple of years ago, the Find feature in KDE worked really well.  But some time in the last couple of years, the two distributions I’ve been using – Kubuntu and Linux Mint KDE – haven’t had the Find feature working from the base install.  I’ve muddled along without that feature for about two years (I don’t always need it, but there have been a few times when I really did need it and it didn’t work).  I finally figured out how to get it working.  It has to be one of the most ridiculously broken elements of Linux I’ve ever discovered as the solution is convoluted and counter-intuitive.

To begin with, from the base install in Dolphin, here is the Find button:

enabling find function in Dolphin in KDE

If you click it, it will open a find dialogue in the location bar at the top of Dolphin:

enabling find function in Dolphin in KDE
(click for full size)

If you try to find something, you’ll get an error message that says, “Invalid protocol” that looks like this:

enabling find function in Dolphin in KDE
(click for full size)

Dolphin has done that for the last two or three years or so, which means I haven’t been able to use this very basic feature of the file manager.

If you look around for advice on how to fix this, you’ll get mired in a bunch of forums that suggest different things about “baloo,” the new search program in KDE (that replaced Nepomuk, the failed, processor-hungry semantic search engine that no one really liked).  Here’s the problem with “baloo”: it’s not installed by default in Linux Mint KDE or Kubuntu.  That’s actually fine if you don’t need this search feature.  But, and here’s the convoluted part of this, you don’t actually use baloo for the search function in Dolphin.  However, you have to install it in order to enable the search function in Dolphin to work, but then turn baloo off.  Seriously!  It’s rather absurd and broken at the moment.

Here’s what you have to do.  First, install baloo4 from synaptic:

enabling find function in Dolphin in KDE
(click for full size)

If you try the search function now, it still won’t work.  Dolphin won’t give you the error message anymore, but it also won’t find anything.  It just gives you an empty page of results, regardless of what you search for.  But, installing baloo does something that makes enabling the Find feature possible.  If you open up System Settings, you’ll see a new icon that wasn’t there before – Desktop Search:

enabling find function in Dolphin in KDE
(click for full size)

We’ll return to that System Setting option in a minute.

Next, go back to Synaptic and install the following packages: kde-baseapps, systemsettings (probably already installed), and kfind (also probably already installed).

enabling find function in Dolphin in KDE
(click for full size)

You can still try searching in Dolphin after you’ve done this, but it won’t work.  There is one more completely counter-intuitive step.  Once you’ve installed kde-baseapps (and the other two packages), go back to the System Settings window and click on the new Desktop Search icon.  There is a check box below the window where you can exclude locations that says “Enable Desktop Search.”  Uncheck it and click “Apply”:

enabling find function in Dolphin in KDE
(click for full size)

Now, try searching in Dolphin and, voila, it works:

enabling find function in Dolphin in KDE
(click for full size)

This fix for the Find feature in a basic program in KDE is completely counter-intuitive.  In sum, in order to turn on the “search” feature, you have to install a package that you aren’t going to use, install another package that you are going to use, and then turn off the first package (baloo).  Why?  Why?  Why?

KDE programmers – I love your software!  I really, really, do.  But this makes no sense.  Can you please decide on a file/folder search solution, install it by default, and then make it a simple click of a button to turn it on or off?  This should not be anywhere close to this complicated!

 4,245 total views,  2 views today