#18 - Removing Important Files with `rm -r *'
É fácil demais usar o comando `rm -r *`
e destruir
todos os seus arquivos importantes. Aqui relato mais um episódio de
desventuras com esse comando!
This is not the first time I removed a lot of important files
with the command `rm -r *`
.
Alone, the rm command does not remove recursively by defaults
and may even throw some errors because of not using the
-f
flag and mixing directories with regular files.
However, do notice that apparently innocent shell star
glob *
. I am not sure if that was z-shell option
RM_STAR_WAIT
or the rm command itself, but a warning
dialog was thrown asking if I wished to remove 25 files?
, to
which I hit Enter, even though I knew 25 files was not the
right sum of number of files.. If I had only noticed I was at the
wrong directory..
A glob is a filename generator within the shell
and it will be substituted by all file names matching it. The glob
is not recursive by defaults, either, but in combination with the
-r
flag of the rm command that can cause havoc and a
lot of time lost at the very least.
To put the story into context, I updated Arch Linux after almost two months without sync'ing. As I synchonise that once a month and last month there was news the just-released Linux 5.9 was not yet compatible with nvidia driver 455.38, I postponed the sync'ing to the following month, which is precisely this month.
With the release of nvidia 455.45 last week, today, I decided to do a first sync with the majority of new packages from a fast Arch Linux mirror in my country. I planned to sync again later with Arch Linux Archive's monthly repo (copy of the 1st of each month), and use that for the following month or so again, and so on.
While in a Linux TTY with Tmux and pacman -Syu
running, I decided to go back in Tmux buffer and copy some warning
messages. I messed the keypresses and pasted a lot of text while
pacman was running post-install hooks..
That is important to mention I did play with the
/boot
directory (which is in a different partition
from /
) in my main SSD drive last week while my laptop
hardware was at the computer shop for repairing the display hinge
mechanism..
I cannot be sure what exactly went wrong with the pacman sync
this time but following a reboot systemD printed warnings it could
not find a kernel module for vfat and thus would not mount
/boot
, which is a separate partition.
I thought about following Arch
Linux Install Guide and remaking the /boot
partition completely, plus I had a backup of its contents of before
and after the pacman update, so I thought I would give it a
try.
At about the time I had chrooted into my SSD drive with Arch Linux live media, an unrelated repair man who needed finish a job with the house gate from yesterday arrived. I lost a little of concentration at that point.
Plus, mum came to me asking some questions just before I was to
remove old /boot
files.. I at /boot
using
vifm before I quit it, and then instead of being at
/boot
, $PWD was still at /
. I am used to
automatically changing to the last directory vifm was because of a
vifm configuration which did not work when I was chrooted! I did
not notice that. I then run `rm -r`
with the star glob
and pressed Enter twice.
I only noticed the catastroph when rm
was issuing
warnings it could not remove /proc/something
,
to which I immediately responded with Ctrl+C.
Interestingly, rm
did not remove /bin
and
other non-system directories from /
, however it did
remove /home
before other directories! Yay! =.[
Luckily, I have got backups. However the newest backup seems to be 3 months old. I pushed/forgot to make my last 2 monthly backups, usually made before Arch Linux updates. I have got most of my files and system configs backed up. My scripts, dotfiles and website are up-to-date with GitHub because I sync with that so often.. I did not move much crypto recently and I have got paper backups of that, so that is really fortunate. There are only about 4 files I really lost, some of which are my updated curriculum vitae from last week, and other documents I may rewrite. Other than those, I think I will lose mostly time.
Won't I ever learn?
Obviously I cannot blame nobody except myself for such noob and silly mistakes.. This is not the first time, and that is the second time this year already!
I reckon I am distracted and indisciplined and can improve on these with some effort which I am willing to make. Habits..
This is not the first time I mess up with rm
. This
is the second occasion I did a mistake just after someone draws my
attention, but also on at least two other occasions there was
nobody to distract me.
I'm writing this from a backup laptop with Manjaro which has got a complete local copy of official repositories and has not been updated over 10 months! 10 months of no headaches!
I don't like Arch Linux moderators as they are sort of a piece of shit. However, not all of them are naughty (I suspect the younger ones are more cruel), and I don't partake guilt in those terrible Arch Forums anymore. Independent as can be from them!
I have been thinking about installing OpenBSD when Arch Linux became unbearable, but hopping distros right now would demand a lot of time there is use for better things at this moment in my life. So, unfortunately, I am just reinstalling Arch again.
I did cheat a little. GPT table and partitions were reused. I formatted all partitions again with GParted from a Xubuntu 18.04 live media.
Partition scheme
- sda1 -
/efi
Bootloader - sda2 - Linux swap
- sda3 -
/
System root - sda4 -
/home
User directory
Back with the formatted computer
This will become a chronology! Back to using my main laptop (driver). Arch Linux reinstall was not too hard. I had to chroot twice to properly install networking tools. Download of packages was slow as heck. I discovered that the laptop ethernet port is bad. Pacman downlaod speed was ~80 Kbps. I tried changing mirror servers before discovering the ethernet port was to blame..
Once internet was set up properly, configuring Arch went well and quickly. I should remark it was necessary to configure the following with some special care:
- choosing fast mirror servers (may use either
ping
orreflector
) - add EFI entry to motherboard NVRAM to boot new system
- configure
GRUB
such as:GRUB_SAVEDEFAULT=true ;GRUB_DEFAULT=saved ;GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 sysrq_always_enabled=true"
; Linux has now dropped support for the scrollback buffer since 5.9 - add users to correct groups (sys, log, games, bumblebee, rfkill, wheel, adm)
networkmanager
with systemdbumblebee
with systemdtlp
with systemdtimedatectl set-ntp true
for time synclocalectl set-x11-keymap br abnt2
- install
yay
- enable bitmap fonts
cd /etc/fonts/conf.d ;ln -s ../conf.avail/70-yes-bitmaps.conf
- install xos-terminus and run update font cache
fc-cache
Basic system
I am making a list with packages to have installed. The list
contains some package groups such as base
,
base-devel
, xfce4
,
xfce4-goodies
, xorg
and
xorg-apps
(beware of xorg-drivers
,
only install what is/if
really needed).
Other packages are required by my current hardware (Intel+NVIDIA).
Most packages enable me with basic functionality for dealing
with a lot of file types. For example, for viewing PDF
files, I have got xreader
,
xpdf
, gv
,
pdfgrep
and fbgs
(from
fbida
package collection), whereas
other PDF tools I have also got
pdfarranger
, pdfmixtool
,
pdftricks
, pdfmod
,
poppler
, pstotext
and
gs
.
If a package is required by another package, it is probably not in the list, unless it means something to me..
This package list will be updated often.
I can confirm losing some more important files from within the last 3 months without a backup.. Hopefully I will be able to restore the missing information and files but that will take all day long tomorrow.
One day later..
About 21 hours after accidentaly removing all my important files, I have got a round-working Arch Linux system and restored most of my files. Nothing really important was lost.
That was a breeze to reinstall Arch Linux. I will need updating
my backup script because pacman
lists did not contain
all packages from my older system..
Other times I misused `rm`
- In 2019 I used
rm
when cleaning up some old backups and removed a unique backup copy of documents and photos from about 2005. I had more backups of that in two other old HDDs, however I lent both HDDs to my cousin to use with her laptop and both of them wore out, one after the other! I was not able to recover files from them. Lessons: three backups may not be enough. Do not lend media that holds important stuff to you. - Just a few months back, I run
rm
at my user directory and lost all personal files. There was a recent backup but I had to rewrite some important documents that needed to be up-to-date. Lesson: always be sure about your glob.
In recollection, twice I was using vifm
(a command line file manager) with a hack to
automatically changing to its last directory on exit. I am
modifying that hack for something safer and that will not let me
get used to changing directories automatically when exiting
vifm
.
# ~/.bashrc
#vifm
#record working directory leaving Vifm
vf()
{
command vifm --choose-dir - "$@" >~/.config/vifm/vifmcd.txt
}
vfcd()
{
cd "$( <~/.config/vifm/vifmcd.txt )"
}
#https://wiki.vifm.info/index.php?title=How_to_set_shell_working_directory_after_leaving_Vifm
UNIX users ought to think before running a command.
God is in the details.
--Ted Nelson
Fifty-one days later (2021 jan)..
I did it again.. I was testing a script at a dedicated temp directory. I opened many terminal windows at once and was doing too many tests quickly. I opened another terminal window and forgot it was not at the temp directory.
I run rm *.txt~*archInstall*
and removed 7 files
from $HOME
(I was messing with this script)..
Fortunately, it only removed some of the .txt files, which
I was able to recover all except one and maybe another one may be
outdated a little from my last backup in December.
I have been trying to follow a tip from Aurelio Jargas that is to try and always
use a glob that more than just *
..