Please consult your 'man' page for the command "rm" Open a terminal and type "man rm" this is the basic CLI for removing files and directories.
–
RingtailJul 15 '12 at 20:00

1

Please add an example of what exactly you want.
–
Eric CarvalhoJul 15 '12 at 20:02

@blueXrider Is it? Just using rm or rmdir of course I can remove directories. The tricky part, I find, is searching the directory for filenames and then using those to remove directories. Any thoughts on that?
–
sehesodJul 15 '12 at 20:25

3 Answers
3

What's not very clear here is that you can't have a file and a directory with the same name. Also, since you mention uncompressing rar files, one could think that you want to remove the directory named after the rar file. This is strange because, why would you want to delete it after you uncompressed it?

Based on my poor understanding of the problem (which may improve if you clarify or, better yet, provide an example), this may work:

What the script does:
First parameter is the path of a file.
Second parameter is the extension you're searching.dirname command receives a path and returns the directory where the file is located.basename command receives a path and returns the file name and optionaly removes a suffix, in this case the extension.

The find command passes to the script the path to the compressed file searched and the extension searched, e.g. /path/to/script /home/user/test/file1.rar rar.dirname $1 expands to dirname /home/user/test/file1.rar which returns /home/user/test, basename $1 expands to basename /home/user/test/file1.rar rar which returns file1. Putting all together the script executes rm -rf /home/user/test/file1.

Ah! This looks something like what I want to do. Could you by any chance explain the code in the shell script more thoroughly? I'm very new to Ubuntu and *nix.
–
sehesodJul 15 '12 at 21:09

Your script unfortunately moves the files found, rather than the directories named like them. Any thoughts on why? I do not fully understand your code. A big thanks for your effort to answer my question!
–
sehesodJul 15 '12 at 21:33