LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 11-11-2004, 02:13 AM   #1
otoomet
Member
 
Registered: Oct 2004
Location: Tartu, Ċrhus,Nürnberg, Europe
Distribution: Debian, Ubuntu, Puppy
Posts: 588

Rep: Reputation: 45
how do you delete files?


Dear people,

I am just curious how are the others deleting files on command line. After a (well known) mistake trying to remove all junk files by

$ rm foo*

but instead typing

$ rm foo *

in my working directory, I wrote two scripts: the first one moves all requested files into ~/.Trash, and the second one, invoced by cron, purges trash for files more than a week old. Now it seems to me such a natural way that I would like to have something similar as default on every computer. I think delayed removing is the only way to make rm safe, different confirmations you just get used to answer "y" every time.

So, what are your ways to delete files?

Best,

Ott
 
Old 11-11-2004, 03:02 AM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
that's a really classic mistake. you will find it in many Un*x books.
I assure you everybody uses rm.

if you want you can alias "rm" to "rm -i" and use interactive mode as default ( confirm every deletion)

this will prevent this type of mistakes, since you can answer no, or type Ctrl+C to stop the hole process
 
Old 11-11-2004, 07:24 AM   #3
otoomet
Member
 
Registered: Oct 2004
Location: Tartu, Ċrhus,Nürnberg, Europe
Distribution: Debian, Ubuntu, Puppy
Posts: 588

Original Poster
Rep: Reputation: 45
Well, my opinions is that it is only marginally safer to use 'rm -i', because one gets used always answering "y". At least this was what happened to me using mc's "safe delete".

Best,

Ott
 
Old 11-11-2004, 09:58 AM   #4
r0b0
Member
 
Registered: Aug 2004
Location: Europe
Posts: 602

Rep: Reputation: 49
I have a great way to remove files.
I use rm, but instead of tapping Enter after I write the command, I always breathe in and out before pressing Enter.
It has never failed me and saved my a** a couple of times.
 
Old 11-11-2004, 11:18 AM   #5
animehair
Member
 
Registered: Sep 2004
Location: NJ
Distribution: Gentoo
Posts: 104

Rep: Reputation: 15
HAHA that is great!! You made my day! ( in a computer nerd way hehehe)

otoomet - i would like to see those scripts, especially the trash one.
 
Old 11-11-2004, 07:11 PM   #6
lectraplayer
Member
 
Registered: Mar 2003
Location: a little west of Birmingham, AL, USA.
Distribution: SuSE 10
Posts: 915

Rep: Reputation: 30
I usually do my file manager through KDE's Konqueror, but you do have a point on making the rm command safer by aliasing it with a "move" script of some sort. I've lost my arse a couple times from rm'ing what I thought was one folder, when it was another.
 
Old 11-12-2004, 05:06 AM   #7
otoomet
Member
 
Registered: Oct 2004
Location: Tartu, Ċrhus,Nürnberg, Europe
Distribution: Debian, Ubuntu, Puppy
Posts: 588

Original Poster
Rep: Reputation: 45
Here are my scripts. I have never thought they can be of interest for the others, so here are not many comments and some texts are in Estonian. The first one, for deleting (called del):

Code:
#!/bin/bash
KQNTS=$HOME/.Trash
case $# in
    0)
	echo "Viga: pġle meskit kaotada..."
	exit 1
	;;
esac
test -d $KQNTS || mkdir $KQNTS
echo "Niisugused fail(id) tqstetud kataloogi $KQNTS:"
for fail; do
    if [ -e "$fail" ]; then
	touch "$fail"
	PATHNAME=${fail%/*}
	FNAME=${fail#$PATHNAME/}
	if [ "x$FNAME" == "x" ]; then
	    # $file ends with '/'.  Need to do differently:
	    PATHNAME=${fail%/*/}
	    FNAME=${fail#$PATHNAME/}
	fi
    # FNAME is the filename (or the dir name to be removed) w/o path
	if [ -d "$KQNTS/$FNAME" ]; then
	    echo "removing $KQNTS/$FNAME"
	    rm -rf "$KQNTS/$FNAME"
	fi
	mv "$fail" $KQNTS
	echo "  $fail"
    else
	echo "      $fail is missing"
    fi
done
There script is long because otherwise you just cannot mv a directory into trash if there already exists one with the same name. You have to rm -rf it before. And you have to check whether it was executed as

$ del path/dir

or

$del path/dir/

The second one, for purging trash:

Code:
#!/bin/sh
kodo=$HOME
kodojuur=${kodo%/*}
KQNTS=.Trash
if test "x$1" = x; then
    kodojuur="/home"
    kasutajad=$(ls $kodojuur)
else
    kasutajad=$1
fi
for kasutaja in $kasutajad 
do 
  # Kui kaua hoida rampsu prugikastis
  aeg="+7"
  if [ "$kasutaja" = "tiina" ]; then
      aeg="+20"
  fi
    if test -d $kodojuur/$kasutaja/$KQNTS; then
	find $kodojuur/$kasutaja/$KQNTS -maxdepth 1 -ctime $aeg -exec rm -rf {} \;
    fi
done
it checks whether it is invoked for a specific user of for all users, gives 20 day expiration delay for my wife and only 7 for the others ;-)

best,

Ott
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete files that won't delete? di11rod Linux - Security 7 10-19-2005 10:14 PM
delete files suguname Linux - Newbie 3 07-05-2005 09:49 AM
Delete Files imsajjadali Red Hat 15 07-23-2004 02:12 PM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 02:13 PM
Delete Files bsengland Linux - Newbie 1 11-04-2002 06:29 PM


All times are GMT -5. The time now is 08:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration