[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Suggestions for rm [WAS: Re: Feature request: install package by passing URL to apt-get]



On Thu, Jun 23, 2022 at 04:27:28PM -0400, Bijan Soleymani wrote:
> On 6/23/2022 12:03 PM, Person the human wrote:
> > The easier something is to do, the more harmless people will think it
> > is, so you're right. Thanks.
> 
> rm wrongfile
> 
> how do I undelete?
> 
> better put deleted files in the "recycling box" and prompt users on every
> deletion by default
> 
> rm -rf /
> 
> oops!
> 
> sigh...
> 
> Bijan
> 
>

For the general "I rm'd something critical" - there is no absolute solution.

Root/superuser privileges can do almost anything and everyone makes that
mistake once.

There are a couple of useful habits to get into when removing things:

There's an 

 rm -i

switch to the rm command. This makes the removal interactive - you get 
an "Are you sure [Y/N]" warning for each file. This is useful for a single 
critical file, less useful when you're removing a hundred logfiles.
On a Red Hat-derived system, this is often aliased to rm by default.
That's a great idea - until you move to a system where rm means rm immediately.

Use the

 pwd

 command to check where you are in the filesystem. (It may be short 
for "print working directory").

If you are deleting one file - change to the directory it is in, check that
it exists there first with the

 ls -al [filename]

command. Since the file is in the current directory,you can use the

 rm ./[filename]

[That's a period and a forward slash - limiting you to a file in the current
directory]

Try and avoid using rm -rf and forced removal. The one exception is that
you have to remove a non-empty directory with -rf. If you first try -r
and it fails, that's a clue that you are actually about to delete a 
directory.

Again, if it's a single directory, change directories to the directory
that it is in and use the ./ The last suggestion, and it's the simplest:

 rm [filename] -rf

Train your brain and your fingers to move the rf to the end of the command so 
that you _have_ to check what filename you are typing as you type it.

If you need to be doubly sure rm [filename] -irf will put in the interactive
prompt again.

Some of this is learnt the hard way from administering one machine that
other people relied on :)

With every good wish, as ever,


Reply to: