2

I've examined some topics but I couldn't delete a file under /usr/share/applications

I downloaded Eclipse but somehow I also installed two icons and named them differently.

What I want to do is to delete an icon (not the program) that belongs to Eclipse: there are two different Eclipse icons on my /usr/share/applications which are named "Eclipse Mars" and "Eclipse Mars Java". I want to delete one of them and I have tried to delete using the following commands in the terminal:

sudo dpkg Eclipse Mars Java
sudo rm -f /usr/share/applications/Eclipse Mars Java

However, none of the above have worked...

Is there any other way to delete one of these icons?

NoWeDoR
  • 35
  • http://www.grymoire.com/Unix/Quote.html#uh-3 ; but check if you really want to delete that file (supposing it exists, which I doubt) --- it's not recoverable. – Rmano Sep 25 '15 at 15:56
  • Does the name really have spaces? If yes, try sudo rm /usr/share/applications/"Eclipse Mars Java". There is no need to -f, and the first command is irrelevant. – mikewhatever Sep 25 '15 at 15:56
  • Be VERY careful with rm. You could have ended up deleting 3 files where "Mars" and "Java" would be deleted in the CURRENT directory. Had it been an existing file it would be gone. As a tip: use "ls" to examine if what gets returned it what you want to delete. – Rinzwind Sep 25 '15 at 16:53
  • @NoWeDoR and you should read this ;) – A.B. Sep 25 '15 at 16:54

2 Answers2

2

You see two icons because you have two desktop files: either in /usr/share/applications and/or in ~/.local/share/applications. The file name of the desktop file isn't the same in your file manager nor your Launcher. In your file manager and in your Launcher you see what's defined inside the desktop file, note the entry Name=

Example

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=Eclipse C++
Comment=Eclipse Integrated Development Environment
Icon=eclipse
Exec=/opt/eclipse-cpp/eclipse/eclipse
StartupNotify=true
StartupWMClass=Eclipse-CPP

Eclips icon screen shot

grep -lr 'Name=Eclipse C++' ~/.local/share/applications

/home/aboettger/.local/share/applications/opt_eclipse_cpp.desktop

Therefore find the right path and file name with the commands below:

  • Eclipse Mars Java

    grep -lr 'Name=Eclipse Mars Java' /usr/share/applications
    grep -lr 'Name=Eclipse Mars Java' ~/.local/share/applications
    
  • Eclipse Mars

    grep -lr 'Name=Eclipse Mars [^J]' /usr/share/applications
    grep -lr 'Name=Eclipse Mars [^J]' ~/.local/share/applications
    

Delete the right file via (NOTE, that are the same commands as above with the additional command sudo rm or rm)

  • Eclipse Mars Java

    grep -lr 'Name=Eclipse Mars Java' /usr/share/applications | xargs sudo rm
    grep -lr 'Name=Eclipse Mars Java' ~/.local/share/applications | xargs rm
    
  • Eclipse Mars

    grep -lr 'Name=Eclipse Mars [^J]' /usr/share/applications | xargs sudo rm
    grep -lr 'Name=Eclipse Mars [^J]' ~/.local/share/applications | xargs rm
    
Fabby
  • 34,259
A.B.
  • 90,397
  • That answers the question , but probably not the best solution. – Panther Sep 25 '15 at 16:10
  • When I write grep -lr 'Name=Eclipse Mars Java' /usr/share/applications it shows me /usr/share/applications/Eclipse Mars Java.desktop and what should I write exactly now? – NoWeDoR Sep 25 '15 at 16:27
  • Yes, that's ok. – A.B. Sep 25 '15 at 16:28
  • If this is the file that you no longer need: grep -lr 'Name=Eclipse Mars Java' /usr/share/applications | xargs sudo rm or without the grep command: sudo rm "/usr/share/applications/Eclipse Mars Java.desktop". Note the double quotes. – A.B. Sep 25 '15 at 16:30
  • When I enter grep -lr 'Name=Eclipse Mars Java' /usr/share/applications | xargs sudo rm it response like rm: missing operand Try 'rm --help' for more information. When I enter -lr 'Name=Eclipse Mars Java' /usr/share/applications | xargs sudo rm it shows me -lr: command not found rm: missing operand Try 'rm --help' for more information. When I enter sudo rm "/usr/share/applications/Eclipse Mars Java.desktop" it shows me rm: cannot remove ‘/usr/share/applications/Eclipse Mars Java.desktop’: No such file or directory – NoWeDoR Sep 25 '15 at 16:33
  • grep -lr 'Name=Eclipse Mars Java' /usr/share/applications | xargs sudo rm it response like rm: missing operand Try 'rm --help' for more information. means, there is not longer a desktop file with "Name=Eclipse Mars Java" – A.B. Sep 25 '15 at 16:37
  • Check the output of grep -lr 'Name=Eclipse Mars Java' /usr/share/applications again there should be no output. – A.B. Sep 25 '15 at 16:38
  • @bodhi.zazen better? =) – A.B. Sep 25 '15 at 16:39
  • Yes, I have finally solved this issue. Thank you so much for all your helps. – NoWeDoR Sep 25 '15 at 16:39
  • @A.B.purge option with dpkg or apt-get – Panther Sep 25 '15 at 17:16
0

Depends on the name of the package and how you installed it.

From your question, I am guessing you used dpkg

The options for dpkg (and apt-get) are to remove or purge.

remove saves system configuration files, purge does not

-r, --remove package...|-a|--pending Remove an installed package. This removes everything except conffiles, which may avoid having to reconfigure the package if it is reinstalled later (conffiles are configuration files that are listed in the DEBIAN/conffiles control file). If -a or --pending is given instead of a package name, then all packages unpacked, but marked to be removed in file /var/lib/dpkg/status, are removed.

          Removing of a package consists of the following steps:

          1. Run prerm script

          2. Remove the installed files

          3. Run postrm script

   -P, --purge package...|-a|--pending
          Purge  an  installed  or  already  removed package. This removes
          everything, including conffiles.  If -a or  --pending  is  given
          instead  of  a  package  name,  then  all  packages  unpacked or
          removed, but marked to be purged in  file  /var/lib/dpkg/status,
          are purged.

          Note:  some configuration files might be unknown to dpkg because
          they  are   created   and   handled   separately   through   the
          configuration  scripts.  In that case, dpkg won't remove them by
          itself, but the package's postrm  script  (which  is  called  by
          dpkg),  has  to  take  care  of  their  removal during purge. Of
          course, this only applies to files in  system  directories,  not
          configuration   files   written   to   individual   users'  home
          directories.

          Purging of a package consists of the following steps:

          1. Remove the package, if not already removed. See --remove  for
          detailed information about how this is done.

          2. Run postrm script.

See http://manpages.ubuntu.com/manpages/vivid/man1/dpkg.1.html

Neither option removes files from your HOME directory, such as .desktop files. For those you have to manually find and remove them.

Files with spaces in them need quotes or escape the spaces or use tab completion

rm "file with spaces"
rm file\ with\ spaces
rm file<tab><tab>
Panther
  • 102,067