0

I have examined this page (How to remove single file from /usr directory?) and tried

sudo rm /usr/share/applications/Eclipse Mars C/C++.desktop 

in the terminal, but it didn't work.

I think the reason is that I use a different version (mine is Ubuntu 14.04).

Is there any solution or any other command for Ubuntu 14.04 to remove the files which aren't wanted?

4
  • 2
    If you look at the "file" name, it cannot exist, since: 1. a file's name cannot include slash(es). 2. A .desktop file would never ever include spaces. See my answer. Sep 16, 2015 at 21:18
  • Jacob Vlijm is right, that file cannot exist.
    – kos
    Sep 16, 2015 at 21:21
  • 1
    Or, let me rephrase it: Eclipse Mars C/C++.desktop is not a valid filename; nonetheless an Eclipse Mars C folder containing a C++.desktop file is perfectly plausible, but seems unlikely since /usr/share/applications should contain only .desktop files.
    – kos
    Sep 16, 2015 at 21:25
  • 1
    @kos indeed, and even then, no application would create: a: a sub-directory, and b. use spaces in directory- or filenames. c. OP used rm which would not have removed a directory :) Sep 16, 2015 at 21:27

3 Answers 3

2

It's because the file name contains spaces. Therefore the rm command interprets it as multiple arguments, which is not intended and obviously fails.

You need to put the file name in quotation marks to be passed as single argument:

sudo rm "/usr/share/applications/Eclipse Mars C/C++.desktop"

But as especially @JacobVlijm has pointed out, Eclipse Mars C/C++.desktop is no valid file name, because of about the only character that may not be included in file names, because it separates directories: the / (slash).

If the command as described above really worked, that means you have the file C++.desktop inside the directory /usr/share/applications/Eclipse Mars C, which is very unlikely, as this is not the recommended structure for the .../applications directories.

But if we assume that this file really exists as described in the previous paragraph, there is another possible way to enter the file name correctly. You can escape all spaces with a \ (backslash) instead of quoting the entire name:

sudo rm /usr/share/applications/Eclipse\ Mars\ C/C++.desktop

But note that rm only removes files, not directories. As we assume (because everything else is theoretically impossible) that Eclipse Mars C/C++.desktop is not a file, but a file in a subdirectory, we don't have achieved what we want yet, as there would still be the (probably empty) directory /usr/share/applications/Eclipse Mars C remaining. To also remove this subdirectory and all contained files (so you may omit the commands above to delete the file only), we have to use one of the command variants below:

sudo rm -r "/usr/share/applications/Eclipse Mars C"
sudo rm -r /usr/share/applications/Eclipse\ Mars\ C

Note that we now don't refer to the file name, but the directory name only. And we use the -r parameter for rm, which stands for "delete recursively".

11
  • When I type as you say, it shows me == > rm: cannot remove ‘/usr/share/applications/Eclipse Mars C/C++.desktop’: No such file or directory
    – NoWeDoR
    Sep 16, 2015 at 20:53
  • 1
    @NoWeDoR double quotes please, not single quotes. This is a correct method but I would suggest to use TAB completion when you reach "Eclipse".
    – Rinzwind
    Sep 16, 2015 at 20:55
  • 1
    Sorry, but no. If you look at the "file" name, it cannot exist, since: 1. a file's name cannot include slash(es). 2. A .desktop file would never ever include spaces. Sep 16, 2015 at 21:14
  • 1
    @NoWeDoR no, I am definitely not, the filename simply cannot exist. suggesting otherwise is stubborn. again, tab completion did the job, because it found the right filename. Sep 16, 2015 at 21:24
  • 1
    Or with single quotes ;)
    – A.B.
    Sep 21, 2015 at 7:17
1

Try typing the command like this:

sudo rm /usr/share/applications/Eclipse\ Mars\ C

And press TAB. It will auto-complete, at which point you should run the command, and it will remove. Putting it in quotes MIGHT work, but there's also a / in the name, so it might cause errors, so it's better to let Bash handle it for you.

6
  • @kos If you were the one who downvoted me, can you reverse that? Sorry if I'm being pushy, I just need to build up my reputation to do things like comment, etc. Anyways, I fixed what the problem was in my post.
    – FireFaced
    Sep 16, 2015 at 21:00
  • Yes, it was me, sorry for having downvoted it, but as it standed it was wrong. And yes, sure I can remove it (done and upvoted it). On a side note the \ and the / at the end are not necessary.
    – kos
    Sep 16, 2015 at 21:04
  • @kos I think the '\/' was needed, as it would otherwise complete to maybe just C for some odd reason.
    – FireFaced
    Sep 16, 2015 at 21:05
  • No, it won't, as the previous \ sequence "attaches" what follows it to the previous string and makesbash interpret the whole thing as a single string; try running mkdir 'dir with spaces'; touch spaces123, typing rm dir\ with\ spaces and hitting TAB, it will expand to dir\ with\ spaces/
    – kos
    Sep 16, 2015 at 21:11
  • 1
    Sorry, but no. This is simply wrong. If you look at the "file" name, it cannot exist, since: 1. a file's name cannot include slash(es). 2. A .desktop file would never ever include spaces. Sep 16, 2015 at 21:16
1

Try:

sudo rm /usr/share/applications/Eclipse\ Mars\ C\/C++.desktop

Or just let the terminal write the name by typing:

sudo rm /usr/share/applications/Eclipse

and hitting TAB, in case I'm wrong with the backslashes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .