function rm {
for file in $@; do
mv -t ~/.local/share/Trash/files/ -- "${file}"
cat <<FROG > ~/.local/share/Trash/info/"$(basename ${file})".trashinfo
[Trash Info]
Path=$(realpath "${file}")
DeletionDate=$(date "+%FT%T")
FROG
done
}In Bash that didn't work on files with spaces or funky characters. But, I never noticed because in Zsh, my primary shell, it works fine with all filenames.
Here's an updated one which incorperates the advice from several posts to also work in Bash:
function rm {
for file; do
mv -t ~/.local/share/Trash/files/ -- "${file}"
cat << FROG > ~/.local/share/Trash/info/"$(basename
"${file}")".trashinfo
[Trash Info]
Path=$(realpath "${file}")
DeletionDate=$(date "+%FT%T")
FROG
done
}At least with bash.
My biggest data loss incident was like 25 years ago when I ran "swapon" on /. Wouldn't recommend it. (And that will trash your Trash, probably.)
Reminds me of a time a hard drive failed on a computer I had. I had an active ssh connection, running terminal display emacs remotely, with a very important file -- with no backup copy -- in a buffer. The computer continued to function, but I couldn't access the disk at all, and I figured as soon as I closed the ssh connection, it was game over. I managed to salvage the file by cutting and pasting through my terminal emulator.
I tried using it for syncing the files on several computers at one time. Instead of adding files to the computer that was lacking them so that both computers matched, it deleted files from the computer that had them so that both computers matched.
These days I just use 'rsync' instead.
Or, alternatively, don't. People with that alias learning to add -f to every rm invocation are also a large source of problems.
Rm should really do something more sensible on the -i switch, like displaying a summary or the files and asking for confirmation only once. Personally, I like to run "find -name file" and once I'm ok with it, I circle the command back and add -delete to it. It is much more usable.
I got into habbit of writing my sql as
'zdelete from product where id = 123;' and THEN i remove the prefixed-z.
Too many a time i copy and pasted wrong ids or screwed up something else.
BEGIN;
DELETE FROM product WHERE id=123;
ROLLBACK;
--COMMIT;
And then I remove/comment the ROLLBACK and enable the COMMIT when I'm confident it's correct. This way I also get the number of affected rows for the statement.I do this even on the command line but it's handier in an Emacs buffer and for busy databases you then don't need to worry about other transactions and locking while you type.
SELECT Count(*) FROM product WHERE id = 123
And if the number looks right I replace "SELECT Count(*)" by "DELETE" begin;
delete from product where id = 123;
--verify things are correct with counts, by issuing "selects", etc.
and then issue either a "rollback;" or a "commit;"... I've been happy to have followed this pattern on occasion ;)Its value is nil
Specifies whether to use the system’s trash can. When non-nil, certain file deletion commands use the function ‘move-file-to-trash’ instead of deleting files outright. This includes interactive calls to ‘delete-file’ and ‘delete-directory’ and the Dired deletion commands.
This variable was introduced, or its default value was changed, in
version 23.1 of Emacs.
You can customize this variable.
---If this option doesn't work for you, you should report a bug.
cd .zfs/whatever the nearest one was, copy it, done
I'm using zfsnap which take care for creating and destroying the snapshots. This I keep 72h with hourly snaps..
The great thing about modern computers is that they have so many resources that it's okay to build more forgiving tools.
Time Machine has been a huge lifesaver as well. Ideally you should be able to mark certain folders to automatically track all file changes over time.
There's still so much room for improving user friendliness and accessibility of computer systems, but it feels like we're either stuck in the Unix box or we've gone full kiddie lockdown mode with mobile platforms.
In the spirit of this article, one could make a function to call rsnapshot any time sensitive work is being done on anything important. Extending beyond the example could be to have a "fire-drill" function that git commits all local repos to an alternate branch, runs rsnapshot, sync's the filesystem, lftp transfers any important directories to an sftp server and/or git push and powers off the device in the event the building or datacenter go up in smoke or the laptop is stolen.
# dd if=/dev/zero of=/dev/sdd (CTRL-C after a few seconds)
It's quick and easy and only a slip away from a wiped hard disc. On a SSD, that would probably rip through /boot (EFI) and swap and be munching on my / before I stopped it. Oh well I could restore the OS and /home should still be intact ... probably.
As I current use Arch and prior to that Gentoo for over a decade, it's probably not the worst breakage I've done to a laptop 8)
Having said that, I have forgotten that I had an ssh session open and accidentally destroyed a dev server like that.
Saved some of my code once.
i do something similar for uncommitted changes. every time emacs saves a file, it saves a copy to a .backups/ folder with a timestamp appended, then prunes copies to the latest 50. with similar hotkeys to git-timemachine i can travel backwards and forwards through saves of the current file.
after that i backup my home folder with git and tar[1].
losing data definitely sucks. it has to happen once, and then one has to decide: never again.
rm -rf *
in my home dir. With this it's a bit better, but you could still do rm -rf .*
in your home dir and lose your hidden .trash dir too.recyclix.so is an LD_PRELOAD-able shared library intercepting file deletions and moves files to recycle bin folder.
shred or similar functions do overwrite files.
alias rm=trash