Tuesday, May 14, 2024
Homepage · rm
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 10749  / 2 Years ago, mon, january 24, 2022, 12:12:38

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?


More From » rm

 Answers
7

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


[#18342] Monday, January 24, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stantildlike

Total Points: 363
Total Questions: 135
Total Answers: 120

Location: Pitcairn Islands
Member since Fri, Dec 17, 2021
2 Years ago
;