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?

NoWeDoR
  • 35
  • 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. – Jacob Vlijm Sep 16 '15 at 21:18
  • Jacob Vlijm is right, that file cannot exist. – kos Sep 16 '15 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 '15 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 :) – Jacob Vlijm Sep 16 '15 at 21:27

3 Answers3

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".

Byte Commander
  • 107,489
  • 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 '15 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 '15 at 20:55
  • Huhhh??? I am pretty sure no application's launcher file includes spaces. – Jacob Vlijm Sep 16 '15 at 21:02
  • 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. – Jacob Vlijm Sep 16 '15 at 21:14
  • @Jacob Vljim Unfortunately, you're wrong – NoWeDoR Sep 16 '15 at 21:21
  • 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. – Jacob Vlijm Sep 16 '15 at 21:24
  • @NoWeDoR Think of it, you mentioned using the rm command, that would not have removed a directory (that would take rm -r) – Jacob Vlijm Sep 16 '15 at 21:32
  • @JacobVlijm Does the edit satisfy you? I just checked and tried to touch a file name containing slashes, which failed as expected. So I think now I included all necessary additional information. – Byte Commander Sep 17 '15 at 08:08
  • I will remove the downvote, but the main reason is OP used the interface name, as defined in the desktop file, instead of the file- name. Furthermore, he insists on having removed something that would have been a directory (if it would exist) with the rm command. Quite impossible, since it would take the -r option. Be sure I value your answer(s) and questions in general, and it is definitely not personal. I think a proper Q/A procedure is frustrated in this question by misinformation. – Jacob Vlijm Sep 17 '15 at 08:39
  • @JacobVlijm I see your point and agree, therefore I felt responsible as the author of the currently accepted answer to edit all reasoned complaints into my post. I'd also like to upvote yours again, but I can do that only once... – Byte Commander Sep 17 '15 at 08:45
  • 1
    Or with single quotes ;) – A.B. Sep 21 '15 at 07: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.

Byte Commander
  • 107,489
FireFaced
  • 187
  • @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 '15 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 '15 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 '15 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 '15 at 21:11
  • Or that Bash would take it as a directory. Anyways, I think just typing that command without the '/' would work anyways. – FireFaced Sep 16 '15 at 21:13
  • 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. – Jacob Vlijm Sep 16 '15 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

Byte Commander
  • 107,489
userDepth
  • 2,010