How do I uninstall a tarball with directories? With no uninstall script
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Whilst we are here and I have deviated off topic, why not one more pet peeve related to tar.
I also think that 'tar xvf archive' (v = Verbose[list on extraction—in this context]) is almost always pointless. I don't need a list of files flying past my screen as I extract. If I know the archive and its contents, I can just extract. If I do not know what is inside, I should have run a 'tar tf archive' first, before I committed to extraction. Because if I was worried about over writing files … then too late. The 'x' (extract) just made that happen, while I watched it (and probably screamed at myself for not doing a 'tf' in the first place).
Last edited by ruario; 11-28-2018 at 02:34 AM.
Reason: clarifications
Delete the files that were extracted from a tarball? Loop over its contents!
Code:
[ -f "$f" ] && echo rm -f "$f"
Actually, the problem with this, is that your "-f" only matches "regular" files, i.e. not symlinks. Thus any symlinks within a package would not be deleted by your suggestion. You could expand the test to [ -f "$f" -o -h "$f" ] and it will be better but of course there are other file types that could potentially be included in a tar archive. This is why I do "! -type d" in my find command. I am looking for any type of file that is not a directory. You would need the equivalent of that to be entirely correct.
Last edited by ruario; 11-28-2018 at 04:27 AM.
Reason: s/times/types/
@MadeInGermany One other issue with your suggestion is that you only covered how to remove files and didn't talk about installation in the first place. This is important because there are two obvious ways to install. Extract the package over the / directory or extract the files somewhere else and move them into place. Only the latter is viable IMHO because installable tar packages like this tend to contain both package specific files (+directories) and shared (read: 'system') directories.
Distributions can have different defaults for permissions and ownership, so even if the author of such a package does their best to use sensible defaults, there might still be wrong for some distributions. Having an ownership or permissions issues with package specific files is a lesser issue, with the most likely problem being with the package does not run correctly. Having ownership or permissions issues with "system directories" (e.g. usr) could be catastrophic. You might not even be able to boot. Thus the user should always extract somewhere else and move files into place, creating only the needed new directories with distro defaults. This is something that is easy with cpio (or a tar pipe). To accurately select files to move, you are likely to use a find command and if you are doing that you might as well create the removal log at that point anyway. You also get the benefit of not having to keep around the old install package just for the sake of helping you remove.
P.S. Since I wrote my answer above, I realise there is an even better find command for creating a log. You could create a nice null separated log like this:
This has the advantage that it also handles any really weirdly named files (i.e. not just spaces in their names but even stuff like names that include line breaks).
I wouldn't go as far as extracting to a different location, and use a subsequent relocation command. Every (further) prilileged command bares a (further) risk.
But I second your suggestion to first run a tar tvf and look at the files and their owners/permissions. Do not blindly trust anyone/anything that is not you/made by you!
Removing a directory is not easy. One should first ensure it is not provided by a package, before removing it with rmdir.
Perhaps one should do this even for plain files and other file types (before removing them with rm).
I wouldn't go as far as extracting to a different location, and use a subsequent relocation command. Every (further) privileged command bares a (further) risk.
Who said anything about extracting privileged? Extract as a normal user, install with cpio (privileged) changing ownership of files to root (and default group for root) on the fly. Read my example.
Removing a directory is not easy. One should first ensure it is not provided by a package, before removing it with.
(and make sure it is empty).
But again, I covered all that in my first response.
Quote:
Originally Posted by ruario
For the most part, empty directories cause no problems and generally have negligible space requirements. So you could just ignore them.
But… if you are the type of person who feels ‘uncomfortable’ with a non-pristine system, the obvious non-shared directories for SpiderOakONE 7.3.0 are “/opt/SpiderOakONE” and its sub-directories, plus “/usr/share/doc/SpiderOakONE”. You could get rid of them with this command:
Perhaps one should do this even for plain files and other file types (before removing them with rm).
Better yet, do that before you install. This is why it is best to talk about install and uninstall together.
Quote:
Originally Posted by ruario
After reviewing that log file [...] to make sure it lists nothing odd and does not have clashes with existing files on your system, you can install the package...
... the obvious non-shared directories for SpiderOakONE 7.3.0 are “/opt/SpiderOakONE” and its sub-directories, plus “/usr/share/doc/SpiderOakONE”. You could get rid of them with this command:
Issuing the following inside a directory of the extracted tar contents, will get you in the ballpark of what might be a non-standard directory.:
Code:
find . -type d | sed -n 's,^\./,/,p' | grep -vxE '/(etc|lib(32|64)?|opt|s?bin|usr((/local)?(/include|/info|/lib(32|64)?|/s?bin|/share(/doc|/info|/man(/man[1-9n])?)?|/src)?)?|var)'
The regex based of a very quick peruse of the FHS 3.0. Of course there are lots of shared directories not covered by FHS but rather other standards like Fdo/XDG (e.g. applications and icons directories in share or the xdg directory and subdirectories in etc). So I considered expanding the regex further but at some point I realised I was overthinking it. If you have a passing familiarity with packaging and 'normal directories' on a Linux distributions, it is quite easy to see that /opt/SpiderOakONE (and its subdirectories) and /usr/share/doc/SpiderOakONE are the odd ones out.
And this actually gives a nice rule of thumb, "the unique directories are generally named after the package" (at least at their highest level) and are thus are actually very easy to spot, even without any fancy regex. In fact, they are easy to find even after install IMHO. Just run a find command on common install locations with "-type d" and "-empty" and look out for the obvious.
Once you have found the "highest level" package specific directories, just approach deleting them after removing the files and based on greatest depth first. Then they are simple to clear down. In addition, you can't go too far wrong with "rmdir" commands. They are pretty safe because they will not remove a directory that contains something. Also even if you do delete something that should have remained as a shared directory (because it happened to be empty right now), the next install of a software that needs it will generally just re-create it without issue.
But again... you could just ignore the directories altogether because empty directories generally cause no problems and have negligible space requirements. So I would personally always focus on the files, first and foremost. These can be scattered all over the place, don't always have obvious names and are (usually) unique. They are also the ones taking up all the space. Handle them and you are generally good.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.