[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Feature request: rm should implement option -p, --parents
From: |
Guido Flohr |
Subject: |
Re: Feature request: rm should implement option -p, --parents |
Date: |
Mon, 06 Jul 2009 20:56:49 +0300 |
User-agent: |
Thunderbird 2.0.0.21 (X11/20090423) |
Hi Pádraig,
Pádraig Brady wrote:
Uninstalling with clean up in such cases is a frequent task, and could be
greatly simplified by:
$ rm --parents /usr/share/myapp/pixmaps/8x16/icon.png
rm: failed to remove `/usr/share': Directory not empty
$ ls /usr/share/myapp
ls: cannot access /usr/share/myapp: No such file or directory
The idea is to remove the containing directory of a file recursively, upwards,
and stop that recursion on the first failure to remove a directory, most
probably because of ENOTEMPTY.
Would that not be better supported with:
rm "$dir/icon.png" && rmdir -p "$dir"
I can kind of see the benefit of your proposal in the
unusual case where $dir is not known. But then one can do:
rm "$file" && rmdir -p $(dirname "$file")
Sure. But compare that to:
rm -p $file
Clearer and more efficient to boot.
The case where the directory part is not known is quite frequent imho.
I configured a random GNU package (in this case gettext from the current
git sources), configured it with "--prefix=/tmp/my_gettext", then
"make", "make install", and "make uninstall", and finally ran find over
the directory /tmp/my_gettext. It finds 194 directories and one regular
file (/tmp/my_gettext/share/info/dir, but that is a nuisance of its
own). So not even packages that use GNU autoconf clean up after
themselves. Now imagine you had to implement a cleanup mechanism. With
"rm -p" you would simply do one check whether rm understands "-p", and
then write to your Makefile:
RM = /bin/rm -p
And voilà, at least on recent enough systems that implement the option
already.
Next example is Perl. You cannot uninstall the interpreter itself, when
built from sources, and additional Perl modules follow this bad example,
and simply spit out some pseudo Perl code for "make uninstall" with
"what would be done":
unlink /usr/lib/perl5/site_perl/5.8.8/i686-linux/auto/My/Pack.so
unlink /usr/lib/perl5/site_perl/5.8.8/i686-linux/auto/My/Pack.bs
# 357 lines following
It is trivial to pipe that into "sed -e 's,unlink,rm -p,' | /bin/sh" (I
do that all the time without -p). But how many people will find the
syntactically correct command pipe for your version? Yes, sure, there is
also the "xargs -0" problem, ... I simplified things.
Did you ever unpack a tarball at the wrong location? Was it a nightmare?
What about this instead:
tar tf ball.tar | xargs rm -p
You can find a solution for all of these cases, but wouldn't adding the
option "-p" to the rm utility help a lot of people with less knowledge
and experience than you to keep their file systems cleaner?
The same idea could be applied to chmod, chgrp, and chown.
So you mean assume empty directories above the file belong with
the file, and so change the permissions and ownership accordingly.
Would that not be better supported with `install -d` ?
No, what I mean is this:
$ ls /path/to/some/file/in/a/deep/directory/structure.sth
ls: Cannot access `...': Permission denied
$ sudo chmod g+rx /path
$ sudo chmod g+rx /path/to
...
$ sudo chmod g+rx /path/to/some/file/in/a/deep/directory
That does not happen every day, but when you need it, a single
$ sudo chmod -p g+rx /path/to/some/file/in/a/deep/directory
would come in handy. Do a phrase search for "chmod -R 777" in your
favorite search engine. I think that beginners often make their system
less secure than necessary because they cannot deal with error messages
they do not understand immediately. If you want to remedy such
situations, it is a more conservative approach to manipulate a path to a
certain node, than to manipulate entire subtrees. But most utilities do
not provide that option.
Cheers,
Guido
--
Империя ООД | Imperia OOD
ул. „Княз-Борис-I“ № 86, София 1000 | ul. "Knyaz-Boris-I" № 86, Sofia
http://www.imperia.bg/
- Feature request: rm should implement option -p, --parents, Guido Flohr, 2009/07/06
- Re: Feature request: rm should implement option -p, --parents, Pádraig Brady, 2009/07/06
- Re: Feature request: rm should implement option -p, --parents,
Guido Flohr <=
- Re: Feature request: rm should implement option -p, --parents, Pádraig Brady, 2009/07/07
- Re: Feature request: rm should implement option -p, --parents, Guido Flohr, 2009/07/07
- Re: Feature request: rm should implement option -p, --parents, Jim Meyering, 2009/07/07
- Re: Feature request: rm should implement option -p, --parents, Ralf Wildenhues, 2009/07/07
- Re: Feature request: rm should implement option -p, --parents, Kamil Dudka, 2009/07/07