Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Linux allgemein: wie schütz man ein dir vor rm -r?
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
mwahl
n00b
n00b


Joined: 04 Aug 2002
Posts: 35

PostPosted: Mon May 15, 2006 11:29 am    Post subject: Linux allgemein: wie schütz man ein dir vor rm -r? Reply with quote

Hallo,

ich habe folgendes Problem:
Ich möchte ein portage-snapshot in /usr/portage extrahieren. Dabei muss ich natürlich vorher alle alten Files löschen, damit die manifest und digest Infos richtig sind. Also vorher ein
Code:
cd /usr/portage
rm -r *

Leider geht dabei auch das distfiles directory mit drauf. Ein
Code:
chmod a-w distfiles
scheint wirkungslos. Das rm -r löscht das directory trotzdem.

Frage 1: Was ist die geschickteste Methode für mein Problem?
Frage 2: Was bedeutet -w bei directories oder warum wird es nicht beachtet?
Back to top
View user's profile Send private message
misterjack
Veteran
Veteran


Joined: 03 Oct 2004
Posts: 1657

PostPosted: Mon May 15, 2006 1:31 pm    Post subject: Reply with quote

wozu portage snapshot extrahieren, wenn es doch emerge --sync gibt? ansonsten einfach mal kurz distfiles woanders hin verschieben und dann wieder zurück. oder verschiebst das dauerhaft nach /usr z.b. und gibst dann in der make.conf DISTDIR="/usr/disfiles/" an
_________________
„Meine Meinung steht fest! Bitte verwirren Sie mich nicht mit Tatsachen.“
Back to top
View user's profile Send private message
mwahl
n00b
n00b


Joined: 04 Aug 2002
Posts: 35

PostPosted: Mon May 15, 2006 2:04 pm    Post subject: Reply with quote

misterjack wrote:
wozu portage snapshot extrahieren, wenn es doch emerge --sync gibt?

Seit kernel 2.6.16 funktioniert mein linmodem nicht mehr und habe zuhause kein DSL - lebe sozusagen Gentoo-offline mit all den kleinen Problemen.

misterjack wrote:
ansonsten einfach mal kurz distfiles woanders hin verschieben und dann wieder zurück. oder verschiebst das dauerhaft nach /usr z.b. und gibst dann in der make.conf DISTDIR="/usr/disfiles/" an

Ist eine gute Idee und habe ich bisher auch so gemacht. Allerdings interessiert mich mehr das allg. Fileattribute-Konzept bei Linux. Kann es daran liegen, dass ich beim rm -r als root eingelogt bin und dann das o-w des owners(root) nicht beachtet wird?
Back to top
View user's profile Send private message
Finswimmer
Bodhisattva
Bodhisattva


Joined: 02 Sep 2004
Posts: 5467
Location: Langen (Hessen), Germany

PostPosted: Mon May 15, 2006 2:49 pm    Post subject: Reply with quote

Prinzipiell geht auch sowas:

rm `ls -1|grep distfiles -v` Damit gibt er eine Liste aller Inhalte außer distfiles aus.

Ansonsten: Du Bist Root, darfst also jede Datei ändern, dementsprechend auch löschen. -R ist rekursiv, also killst du damit alles.

Verhindern kannst du das nicht.

Tobi
_________________
Bitte auf Rechtschreibung, korrekte Formatierung und Höflichkeit achten!
Danke
Back to top
View user's profile Send private message
Anarcho
Advocate
Advocate


Joined: 06 Jun 2004
Posts: 2970
Location: Germany

PostPosted: Mon May 15, 2006 2:55 pm    Post subject: Reply with quote

man chattr
_________________
...it's only Rock'n'Roll, but I like it!
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Mon May 15, 2006 3:15 pm    Post subject: Re: Linux allgemein: wie schütz man ein dir vor rm -r? Reply with quote

mwahl wrote:
Frage 1: Was ist die geschickteste Methode für mein Problem?

Du könntest ganz einfach dein distfiles-Verzeichnis irgendwo anders hinpacken als in den default /usr/portage/distfiles
($DISTDIR in /etc/make.conf)

Oder die Methode für Masochisten:
in ~/.bashrc: alias rm='rm -i'
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
schachti
Advocate
Advocate


Joined: 28 Jul 2003
Posts: 3765
Location: Gifhorn, Germany

PostPosted: Mon May 15, 2006 3:17 pm    Post subject: Re: Linux allgemein: wie schütz man ein dir vor rm -r? Reply with quote

Think4UrS11 wrote:

Oder die Methode für Masochisten:
in ~/.bashrc: alias rm='rm -i'


Dann oute ich mich als Masochist - das ist das erste, was ich auf einem neuen System mache. ;-)

Bringt allerdings auch nichts, wenn man aus Versehen rm -rf * macht. :lol:
_________________
Never argue with an idiot. He brings you down to his level, then beats you with experience.

How-To: Daten verschlüsselt auf DVD speichern.
Back to top
View user's profile Send private message
hoschi
Advocate
Advocate


Joined: 19 Jul 2003
Posts: 2517
Location: Ulm, Germany, Europe

PostPosted: Mon May 15, 2006 3:34 pm    Post subject: Reply with quote

Read Mail Really Fast :D
_________________
Just you and me strogg!
Back to top
View user's profile Send private message
mwahl
n00b
n00b


Joined: 04 Aug 2002
Posts: 35

PostPosted: Mon May 15, 2006 3:57 pm    Post subject: Reply with quote

Finswimmer wrote:
Ansonsten: Du Bist Root, darfst also jede Datei ändern, dementsprechend auch löschen.


Ich vermute auch, dass es daran liegt: root darf ALLES.
Szenario: owner eines Verzeichnisses setzt sein eigenes write-flag auf -w.
Was passiert bei einem rm -r * in dem parent directory? Vermutlich werden alle bis auf das eine gelöscht.

Wenn root der owner und ebenfalls das w flag nicht gesetzt hat, sollte er eigentlich dieses directory nicht löschen können. Aber root ist der superuser und ich glaube mich zu erinnern das bei all diesen Sicherheitschecks von Linux am Ende so eine Art
Code:
isSuperuser()
aufgerufen wird. Falls ja wird die Aktion erlaubt.
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Mon May 15, 2006 4:15 pm    Post subject: Re: Linux allgemein: wie schütz man ein dir vor rm -r? Reply with quote

schachti wrote:
Bringt allerdings auch nichts, wenn man aus Versehen rm -rf * macht. :lol:

Gnaaaah :wink:

Ok, für die ganz harten - grundsätzlich immer alles auf WORM-Medien schreiben :twisted:
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
Fauli
l33t
l33t


Joined: 24 Apr 2004
Posts: 760
Location: Moers, Germany

PostPosted: Mon May 15, 2006 5:50 pm    Post subject: Re: Linux allgemein: wie schütz man ein dir vor rm -r? Reply with quote

mwahl wrote:
Frage 1: Was ist die geschickteste Methode für mein Problem?

Code:
rm -r !(distfiles)

_________________
Do your part to beautify the web! Turn off link underlining!
Back to top
View user's profile Send private message
STiGMaTa_ch
Veteran
Veteran


Joined: 28 Dec 2004
Posts: 1686
Location: Rüti ZH / Schweiz

PostPosted: Mon May 15, 2006 9:09 pm    Post subject: Reply with quote

Im uebrigen kann man auch in "wichtigen" Verzeichnissen eine Datei namens -i erzeugen. Wenn man sich dann in dem Verzeichnis befindet und aus Versehen ein rm -r * eingibt wird durch das File -i auomatisch ein rm -ri * daraus.

Bsp:
Code:
cd /
touch -- -i

Ein rm -r * in / sorgt nun nicht mehr für ungewollte Ueberraschungen.

Loeschen kann man das File uebrigens wieder so:
Code:
rm -- -i


Lieber Gruss
STiGMaTa
_________________
Ich bin Schuldknappe. Das bedeutet ich bin immer an allem Schuld. Und das nicht zu knapp! | Der alltägliche Familienwahnsinn auf meinem BLOG
Back to top
View user's profile Send private message
hoschi
Advocate
Advocate


Joined: 19 Jul 2003
Posts: 2517
Location: Ulm, Germany, Europe

PostPosted: Mon May 15, 2006 10:40 pm    Post subject: Reply with quote

Oh, davon habe ich mal in Gentoo-Wiki gelesen. Wenn man jemand wirkilch aergen will, legt man ein paar solcher Dateien an :D
_________________
Just you and me strogg!
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9625
Location: beyond the rim

PostPosted: Tue May 16, 2006 2:23 am    Post subject: Re: Linux allgemein: wie schütz man ein dir vor rm -r? Reply with quote

mwahl wrote:
Frage 2: Was bedeutet -w bei directories oder warum wird es nicht beachtet?

info coreutils wrote:
There are three kinds of permissions that a user can have for a file:

1. permission to read the file. For directories, this means
permission to list the contents of the directory.

2. permission to write to (change) the file. For directories, this
means permission to create and remove files in the directory.


3. permission to execute the file (run it as a program). For
directories, this means permission to access files in the
directory.

Oder anders ausgedrückt: Die Rechte einer Datei sind beim Löschen schnurzegal, die Rechte des übergeordneten Verzeichnisses sind da relevant.
Back to top
View user's profile Send private message
l3u
Advocate
Advocate


Joined: 26 Jan 2005
Posts: 2616
Location: Konradsreuth (Germany)

PostPosted: Tue May 16, 2006 9:03 am    Post subject: Reply with quote

Aber das mit der "-i"-Datei ist ja cool :-) Funktioniert aber leider nicht, wenn man ein Verzeichnis _unter_ dem ist, in dem -i ist. Heißt: Wenn in ~/blubb die Datei -i ist, dann kann ich in ~ trotzdem rm -r blubb eingeben, ohne daß was gefragt wird.
Back to top
View user's profile Send private message
gentop
l33t
l33t


Joined: 29 Nov 2004
Posts: 639

PostPosted: Tue May 16, 2006 11:10 am    Post subject: Re: Linux allgemein: wie schütz man ein dir vor rm -r? Reply with quote

Fauli wrote:
Code:
rm -r !(distfiles)
Code:
bash: !: event not found
?
//gentop
Back to top
View user's profile Send private message
mwahl
n00b
n00b


Joined: 04 Aug 2002
Posts: 35

PostPosted: Tue May 16, 2006 12:49 pm    Post subject: Re: Linux allgemein: wie schütz man ein dir vor rm -r? Reply with quote

Hätte nicht gedacht, dass ich damit so ne Diskussion auslöse.
info coreutils wrote:

2. permission to write to (change) the file. For directories, this
means permission to create and remove files in the directory.


Probiert mal aus was passiert wenn ihr als normaler user folgende Verzeichnisstruktur anlegt:
Code:

mkdir test
mkdir test/a
mkdir test/b
cd test
chmod a-w b
rm -r *

Kommt da bei euch auch ne Frage im Stil von: Soll das write-protected Directory gelöscht werden? Verzeichnis a wird anstandslos gelöscht.

Und jetzt macht das Spielchen nochmal als root.

Wenn ich wieder vor meinem Rechner sitzte versuche ich eure Tricks mal. Vielen Dank.
Back to top
View user's profile Send private message
l3u
Advocate
Advocate


Joined: 26 Jan 2005
Posts: 2616
Location: Konradsreuth (Germany)

PostPosted: Tue May 16, 2006 4:47 pm    Post subject: Reply with quote

@gentop: Ohne das jetzt ausprobiert zu haben: ein ! mußt du glaub ich escapen, also \!
Back to top
View user's profile Send private message
Fauli
l33t
l33t


Joined: 24 Apr 2004
Posts: 760
Location: Moers, Germany

PostPosted: Tue May 16, 2006 4:49 pm    Post subject: Re: Linux allgemein: wie schütz man ein dir vor rm -r? Reply with quote

gentop wrote:
Fauli wrote:
Code:
rm -r !(distfiles)
Code:
bash: !: event not found
?
//gentop

Du musst diese Funktion wahrscheinlich noch mit "shopt -s extglob" einschalten (praktischerweise auch in der ~/.bashrc).

Mir war nicht bewusst, dass extglob nur dann standardmäßig gesetzt ist, wenn man die bash-completion nutzt.
_________________
Do your part to beautify the web! Turn off link underlining!
Back to top
View user's profile Send private message
l3u
Advocate
Advocate


Joined: 26 Jan 2005
Posts: 2616
Location: Konradsreuth (Germany)

PostPosted: Tue May 16, 2006 4:55 pm    Post subject: Reply with quote

Äh, also irgendwie is das grad suspekt mit dem AUsrufezeichen. Ich hab mal a bissl rumprobiert, weil ich bei echo auch schon öfter das Problem mit "Event not found" hatte:
Code:
tobias@erhome ~ $ echo "Servus"
Servus
tobias@erhome ~ $ echo "Servus!"
echo "Servus" > tan_gk.asc
tobias@erhome ~ $

Ich hab vor kurzem (zu Testzwecken) sowas gemacht wie
Code:
echo "123456" > tan_gk.asc
echo "234567" >> tan_gk.asc

und so weiter ... aber warum wird jetzt bei 'echo "Servus!"' 'echo "Servus" > tan_gk.asc' ausgeführt?!
Back to top
View user's profile Send private message
MatzeOne
Guru
Guru


Joined: 07 Sep 2003
Posts: 579
Location: Hamburg, Germany

PostPosted: Thu Jun 01, 2006 7:39 am    Post subject: Reply with quote

Ich hab für /usr/portage/distfiles eine eigene Partition. Ich würde mir mit einem umount also helfen ;D
_________________
Mit null lässt sich eine ganze Menge machen.
Sportschule Hamburg
Back to top
View user's profile Send private message
l3u
Advocate
Advocate


Joined: 26 Jan 2005
Posts: 2616
Location: Konradsreuth (Germany)

PostPosted: Thu Jun 01, 2006 8:23 am    Post subject: Reply with quote

Das geht aber am Ziel vorbei, weil's ja um Grundsätze geht ...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum