FIND and DELETE
Here's the scenario. I've downloaded a bunch of pictures and PDF files that were enclosed in compressed archives. When I decompressed them, several sub-directories were created. I've moved some of the files around, and now it's a mess with no organization. What I want to do is delete all the .rar files and keep the .jpg, and .pdf files. Here's how it looks in the file explorer Dolphin:
To do this via the file browser, I would have to open all the directories and then look at each file, make sure it's one I want to get rid of and then either delete them one at a time or select them and then using CTL-<left click> select all of them then send them to the trash. To complicate matters, I actually want to keep all these directories, just not everything that's in them. Via the GUI, this is tedious.
So, I use the 'find' command.
'Find' is a very powerful application with a brazillion options. One can create extremely complex search strings and then even more complex strings of commands to act on what's found. I'm not going into all that, but here's a simple method of doing what I propose above that, when you use it enough, is very easy to remember.
I start in the top directory, below which are all the files I want to organized or delete.
I then enter this command, press enter, and let it do its work:
find . -name \*.rar -exec rm {} \;
In this particular case, this command took less than a second to complete. If I had a larger number of directories or if the files to be deleted were a lot larger in size, it would have taken longer. But all I actually had to do was type it out. Now, all the .rar files are gone, leaving me only with .pdf and .jpg files.
I find it easier on me to remember these commands if I think of what they do in terms of plain English. So, this is what that command is saying.
Find starting in the current directory in the name of the file any file ending in .rar and the execute the command to remove all these files.
I could further manipulate these files using a variation of the same command. For example, say I wanted to move all the .jpg files to a single directory. From the same directory above, I could modify the command like this:
find . -name \*.jpg -exec mv {} ~/JPG \;
That would move all the files ending in .jpg to a directory in my /home directory called JPG.
Many variations are possible and easy to do if you remember the basic structure.
FIND (find) in the CURRENT DIRECTORY AND ALL ITS SUBDIRECTORIES (.) in the FILENAME (-name) all files ENDING IN (\*) some string of characters.
You could also have it find all file names with the characters 123 somewhere in the middle name, e.g. find . \*123\*