9 ms·
$ rm Important.txt (uh oh)
- hit8run 4y agoCan one also enable system bin for terminal (zsh)?
- tectonic 4y agoI was just thinking that I'd write a command for this if it didn't exist already. But it does: https://apple.stackexchange.com/a/50852 https://apple.stackexchange.com/a/50852
- cristoperb 4y agoI use trash-cli which implements the freedesktop trash spec: https://github.com/andreafrancia/trash-cli https://github.com/andreafrancia/trash-cli
- jrockway 4y agoMy best backup has always been having a buffer visiting the file I'm about to delete. I think that's saved my bacon once or twice, but honestly I have 0 paranoia about losing data. For whatever reason, I've never accidentally deleted .git and an important unpushed change at the same time. As a result I disable swap files and backup files in Emacs, and I haven't regretted it. 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.)
- ataylor284_ 4y agoI also tend to have important stuff in a buffer before doing anything destructive outside emacs although I definitely keep backup files on. 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.
- deleted 4y ago[deleted]
- kickingvegas 4y agoWhile this is good guidance for Emacs users, another, more shell-based tactic is to use the "-i" option for "rm" which requests a confirmation before deleting the file. Aliasing "rm" to "rm -i" in either .bashrc or .zshrc (depending on what shell you use) for interactive operations has saved me a countless number of times from regret.
- marcosdumay 4y ago> Aliasing "rm" to "rm -i" in either .bashrc or .zshrc 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.
- kickingvegas 4y agoFor such folks, telling them that invoking the full path of the executable will bypass the alias, e.g. “/bin/rm -f” will do the right thing. Discoverable? Nah. But we are talking about shell command behavior which is pretty arcane anyways.
- bravetraveler 4y agoNot really something I'd suggest with rigor, but prefacing an aliased command with a backslash will also defeat it
- cassepipe 4y agoSeems relevant and not just for emacs : https://github.com/rushsteve1/trash-d https://github.com/rushsteve1/trash-d I have been using it after for some time after it was posted to HN. It's a great tool. There's a .deb in the releases page.
- goshx 4y agoThis reminds me of myself back in the 90’s when I learned the hard way that I should probably create an alias called “rm” where it just moves the files/directories to a “trash” directory where I could purge things later.
- thom 4y agoI know we pooh-pooh Dropbox as they try and find some more expansive business model than backups, but having been a customer for more than a decade, I haven’t had a single moment’s anxiety about losing any version of any file. It’s never failed when I needed to go back and retrieve something, to the point that my OS’s trash folder is just that thing I empty if I ever want to save some disk space.
- simonblack 4y agoDropbox is only useful if you are using it for just one computer. 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.
- dmd 4y agoI’ve been using dropbox across three computers since a few months after they were founded and have never once encountered this problem - and if I someday do, it’s a matter of seconds to undo deletions in Dropbox.
- deleted 4y ago[deleted]
- themodelplumber 4y agoThat doesn't sound right. I think you owe us all another try. :-) I've been using it on 3-4 computers for over a decade and never had this happen...
- thrdbndndn 4y agoThis shouldn't happen, at least shouldn't happen frequently. I use all the major sync providers (namely Dropbox, GDrive, OneDrive) with three computers. Have only encountered sync problem <5 times (mostly happens when I didn't open certain computer for a long time) and they all have been just having duplicate files.
- 4y ago
- amelius 4y agoA continuous snapshotting filesystem would be a more rigorous approach.
- mnd999 4y agoAPFS is that, no? That’s how Time Machine works.
- DannyBee 4y agoKinda. It supports consistent snapshots but they are not easy to access or copy or ... except through TM. It ends up closer to VSS or LVM in usability, though it doesn't have to be since the architecture is better. ZFS is likely the canonical example of a system that makes constant snapshots easy to use and access and deal with. BTRFS is also not bad
- sph 4y agoDoes ZFS snapshot every single operation you do? That sounds pretty cool. Unless you're saying snapshots are cheap but you have to create them manually, in that case it's not very useful against accidental deletion.
- Mindless2112 4y agoNot every operation. It's manual but easily automated. https://github.com/zfsonlinux/zfs-auto-snapshot https://github.com/zfsonlinux/zfs-auto-snapshot
- kadoban 4y agoNo, it doesn't snapshot every action. Even as cheap as they are, that would probably be overkill. I have snapshots every 15 minutes, every hour, every day, every week (different retention schedules for each). And then anything dangerous there's a wrapper for "snapshot, do it, snapshot again". It's really pretty difficult to lose anything this way, and recovery is _very_ easy. The snapshotted files are available in a magic directory named .zfs or something. Backups are still needed of course, because if the fs shits itself (or enough redundant drives die), you'd still be in trouble.
- TheAceOfHearts 4y agoI have rm aliased to trash for interactive use because it prevents me from making mistakes. There's a macOS trash utility you can download that lets you put files in the trash properly with full Finder support. 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.
- mekster 4y agoIt still does sometime feel like we're in the 90's in CLI environment. There are many rooms for improvements.
- deleted 4y ago[deleted]
- mmh0000 4y agoI've had this function/alias in my {bash,zsh}rc files file years: 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 }
- miduil 4y agoSounds useful, though I'd advice using a different alias - just to avoid surprises when for some reason your function wasn't loaded properly.
- ThePowerOfFuet 4y agoUsing rm as the alias is the whole point, so muscle memory doesn't work against you.
- BerislavLopac 4y agoI use trash-cli [0] for that. [0] https://github.com/andreafrancia/trash-cli https://github.com/andreafrancia/trash-cli
- Zamicol 4y ago>Can I alias rm to trash-put? You can but you shouldn't. In the early days I thought it was a good idea to do that but now I changed my mind. Although the interface of trash-put seems to be compatible with rm, it has different semantics which will cause you problems. For example, while rm requires -R for deleting directories trash-put does not.
- mekster 4y agoI have aliased "rm" with "trash-put" for years and I just can't believe anyone is living without a trash capability under CLI. What kind of ancient environment is it without a trash capability? That's pre Windows 95. How are people handling the mistake of "rm *" in a wrong folder? Added benefit of trash-put is, you don't need "-r" to delete a folder. It's just an annoyance from user's perspective. If you think there's a compatibility problem in a script, just use /bin/rm and stop wasting time pulling hairs on unrecoverable deletion. "@daily trash-empty 30" Put this in cron to purge trashes older than 30 days daily.
- nathants 4y agoi use git-timemachine for emacs, letting me move backwards or forwards through commits in the current file. 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. 1. https://github.com/nathants/backup https://github.com/nathants/backup
- gerdesj 4y agoI wipe USB sticks with: # 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)
- gizmo686 4y agoI routinly need to dd to a thumbdrive at work. On newer computers the internal harddrive tends to be on /dev/nvme*, making the usb drive sda. Apart from several months of being very nervous when I went to flash a drive, this significantly reduced the risk of an accidental destruction of you computer. Having said that, I have forgotten that I had an ssh session open and accidentally destroyed a dev server like that.
- usr1106 4y agoI have thought for years that I should patch dd to require some force option if it writes to a block device bigger than a typical USB stick/SD card. Never did, but now my development machines have NVME and I hardly ever use USB sticks anymore because my target systems have OTA updates most of the time. So the need has become history.
- gizmo686 4y agoYou can do better than that. Assuming you don't care about portability, it is easy to tell if a disk is USB or not by poking around /sys. Linux also seems to have a notion of "removable disk", as the eject command can tell the difference, but I'm not sure what that looks at. If I really cared, I would suggest setting up udev so the relevent disk is created with DAC permissions that allow you to flash it without needing root.
- usr1106 4y ago
- renewiltord 4y agoAfter over 2 decades of Linux use, the other day I created a folder called `~` in my code dir accidentally and then just ran `rm -rf ~` like a moron instead of `rm rf ./~` like a smart man. Fortunately for me, it didn't get far and I ^C before it got anywhere.
- soheil 4y agoI have nightmares about doing 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.
- naniwaduni 4y agoI make a habit of rm -fr ../current_dir_name/* when trying to delete a broad glob, just to at least make sure to sanity-check deleting from the right place.
- soheil 4y agohmm I typically do tab completion so I'd be nervous just doing a quick rm -rf ../(mis-KeyPress) [TAB + Enter] and watching the entire parent dir getting wiped out.
- deleted 4y ago[deleted]
- pabs3 4y agoI've done that before, now I have a custom shell function that recursively lists the files to be deleted and forces me to confirm that they should be deleted.
- daptaq 4y agodelete-by-moving-to-trash is a variable defined in ‘src/fileio.c’. 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.
- DannyBee 4y agoZfs. lots of snapshots. cd .zfs/whatever the nearest one was, copy it, done
- layer8 4y agoOn Windows, File History works similarly, once you’ve set it up.
- ninkendo 4y agoAPFS on macOS can definitely do snapshotting, I wonder if anyone’s come up with a good way of utilizing it for this…
- deleted 4y ago[deleted]
- tpolzer 4y agoNow if only https://github.com/openzfs/zfs/issues/10348 https://github.com/openzfs/zfs/issues/10348 could be fixed. I'm using frequent zfs snapshots, but recovery is more annoying than I'd like.
- mustache_kimono 4y agoYou need...you want... httm[0]. [0]: https://github.com/kimono-koans/httm https://github.com/kimono-koans/httm
- yonrg 4y agoSame! Works great for me. I'm using zfsnap which take care for creating and destroying the snapshots. This I keep 72h with hourly snaps..
- pacifika 4y agoAlias rm to trash
- alexpotato 4y agoI've been using this for the past 20 years and it's saved my bacon multiple times: http://www.mikerubel.org/computers/rsync_snapshots/ http://www.mikerubel.org/computers/rsync_snapshots/
- amake 4y ago`system-move-file-to-trash` is predefined and all of this just works as expected if you use the Emacs GUI on Mac.
- fferen 4y agoAs a last resort, if you remember part of the lost file, you can grep the hard drive: http://blog.nullspace.io/recovering-deleted-files-using-only-grep.html http://blog.nullspace.io/recovering-deleted-files-using-only... Saved some of my code once.
- rawoke083600 4y agoCould i add my slight tangent tip. Sql(delete,updates etc) 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.
- iforgotpassword 4y agoI write them as SELECT Count(*) FROM product WHERE id = 123 And if the number looks right I replace "SELECT Count(*)" by "DELETE"
- nierman 4y agoyou can also take advantage of transactions: 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 ;)
- vq 4y agoI always run small mutations like that in a transaction. 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.
- rawoke083600 4y agoLol I like the "amount" of comments (>0) I have on my original-comment, and there I was thinking, I'm the only fool todo deletes/updates via db-console in production :D
- tazeg95 4y agosudo apt-get install trash-cli alias rm=trash
- bandie91 4y agoshameless plug: https://github.com/bAndie91/libyazzy-preload/#recyclixso https://github.com/bAndie91/libyazzy-preload/#recyclixso alternative safebelt against accidental file removal. recyclix.so is an LD_PRELOAD-able shared library intercepting file deletions and moves files to recycle bin folder.
- reshie 4y agowell at least it does not overwrite it it could possibly be recovered. a backup trash folder is a good idea for those things aliases are great for a lot of things including larger scripts that would probably be in a separate file. shred or similar functions do overwrite files.
- LinuxBender 4y agoThese are nifty functions and methods but my personal preference that has always saved me was to use rsnapshot for anything that is important to me so that I have several historical copies in a date based folder structure. I do a local snapshot and run it ad-hoc if I am working on anything sensitive. That snapshot then gets lftp rsync-like sync'd to a chroot sftp server. Using rsnapshot can file-version entire directories so that dependencies are also versioned by day even if outside of git or in gitignore. This could even include all important laptop/device settings so that the laptop is easily replaceable. One distinct advantage of rsnapshot is that it uses hard-links for duplicate files to minimize disk space usage. 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.
- mekster 4y agoSwitch to zfs.