A safe and ergonomic alternative to rm

Related tags

System tools trash
Overview

rip (Rm ImProved)

https://img.shields.io/crates/v/rm-improved.svg https://travis-ci.org/nivekuil/rip.svg?branch=master

rip is a command-line deletion tool focused on safety, ergonomics, and performance. It favors a simple interface, and does not implement the xdg-trash spec or attempt to achieve the same goals.

Deleted files get sent to the graveyard (/tmp/graveyard-$USER by default, see notes on changing this) under their absolute path, giving you a chance to recover them. No data is overwritten. If files that share the same path are deleted, they will be renamed as numbered backups.

rip is made for lazy people. If any part of the interface could be more intuitive, please open an issue or pull request.

Installation

Or get a binary release (Linux x86_64, ARMv7 and macOS), untar it, and move it somewhere on your $PATH:

$ tar xvzf rip-*.tar.gz
$ mv rip /usr/local/bin

or build it:

$ cargo install rm-improved

Arch Linux users can install it from the AUR (thanks @Charon77!)

$ yay -S rm-improved

macOS users can install it with Homebrew:

$ brew install rm-improved

Usage

USAGE:
    rip [FLAGS] [OPTIONS] [TARGET]...

FLAGS:
    -d, --decompose    Permanently deletes (unlink) the entire graveyard
    -h, --help         Prints help information
    -i, --inspect      Prints some info about TARGET before prompting for action
    -s, --seance       Prints files that were sent under the current directory
    -V, --version      Prints version information

OPTIONS:
        --graveyard <graveyard>    Directory where deleted files go to rest
    -u, --unbury <target>       Undo the last removal by the current user, or specify some file(s) in the graveyard.  Combine with -s to restore everything printed by -s.

ARGS:
    <TARGET>...    File or directory to remove

Basic usage – easier than rm

$ rip dir1/ file1

Undo the last deletion

$ rip -u
Returned /tmp/graveyard-jack/home/jack/file1 to /home/jack/file1

Print some info (size and first few lines in a file, total size and first few files in a directory) about the target and then prompt for deletion

$ rip -i file1
dir1: file, 1337 bytes including:
> Position: Shooting Guard and Small Forward ▪ Shoots: Right
> 6-6, 185lb (198cm, 83kg)
Send file1 to the graveyard? (y/n) y

Print files that were deleted from under the current directory

$ rip -s
/tmp/graveyard-jack/home/jack/file1
/tmp/graveyard-jack/home/jack/dir1

Name conflicts are resolved

$ touch file1
$ rip file1
$ rip -s
/tmp/graveyard-jack/home/jack/dir1
/tmp/graveyard-jack/home/jack/file1
/tmp/graveyard-jack/home/jack/file1~1

-u also takes the path of a file in the graveyard

$ rip -u /tmp/graveyard-jack/home/jack/file1
Returned /tmp/graveyard-jack/home/jack/file1 to /home/jack/file1

Combine -u and -s to restore everything printed by -s

$ rip -su
Returned /tmp/graveyard-jack/home/jack/dir1 to /home/jack/dir1
Returned /tmp/graveyard-jack/home/jack/file1~1 to /home/jack/file1~1

Emacs

(setq delete-by-moving-to-trash t)
(defun system-move-file-to-trash (filename)
  (shell-command (concat (executable-find "rip") " " filename)))

Notes

  • You probably shouldn’t alias rm to rip. Unlearning muscle memory is hard, but it’s harder to ensure that every rm you make (as different users, from different machines and application environments) is the aliased one.
  • If you have $XDG_DATA_HOME environment variable set, rip will use $XDG_DATA_HOME/graveyard instead of the /tmp/graveyard-$USER.
  • If you want to put the graveyard somewhere else (like ~/.local/share/Trash), you have two options, in order of precedence:
    1. Alias rip to rip --graveyard ~/.local/share/Trash
    2. Set the environment variable $GRAVEYARD to ~/.local/share/Trash.

    This can be a good idea because if the graveyard is mounted on an in-memory filesystem (as /tmp is in Arch Linux), deleting large files can quickly fill up your RAM. It’s also much slower to move files across filesystems, although the delay should be minimal with an SSD.

  • In general, a deletion followed by a --unbury should be idempotent.
  • The deletion log is kept in .record, found in the top level of the graveyard.
Comments
  • Use

    Use "$XDG_DATA_HOME/graveyard" if possible

    Use XDG_DATA_HOME environment variable if the variable is set and no other options like GRAVEYARD or '--graveyard=' were specified. In such case use "$XDG_DATA_HOME/graveyard" as graveyard. Since XDG_* variables are user-specific, there is no reason to append username to the name of graveyard folder.

    opened by Siborgium 3
  • Issues when removing a symbolic link pointing to a directory

    Issues when removing a symbolic link pointing to a directory

    When removing a symbolic link pointing to a directory, I expect rip to behave like rm which remove the symbolic link itself. However, rip removes the physical directory instead.

    opened by dclong 2
  • rip seems not to respect XDG_DATA_HOME

    rip seems not to respect XDG_DATA_HOME

    Fantastic tool! Works great overall, just one minor quibble: XDG_DATA_HOME seems to not work.

    Linux 4.15.0-50-generic #54-Ubuntu x86_64 GNU/Linux
    Distributor ID:	Ubuntu
    Description:	Ubuntu 18.04.1 LTS
    Release:	18.04
    Codename:	bionic
    
    rip 0.12.0
    
    

    I have XDG_DATA_HOME set to /home/mike/.local/share. Rip is still sending files to /tmp/graveyard-mike.

    Thanks!

    opened by xkortex 2
  • Can't compile with new nightly

    Can't compile with new nightly

    $ rustc +nightly --version
    rustc 1.32.0-nightly (14997d56a 2018-12-05)
    $ cargo +nightly install rm-improved
        Updating crates.io index
      Installing rm-improved v0.11.4
       Compiling libc v0.2.45
       ...more "Compiling" lines
       Compiling error-chain v0.8.1
       Compiling rm-improved v0.11.4
    error[E0463]: can't find crate for `alloc_system`
     --> /home/paul/.cargo/registry/src/github.com-1ecc6299db9ec823/rm-improved-0.11.4/src/main.rs:5:1
      |
    5 | extern crate alloc_system;
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0463`.
    error: failed to compile `rm-improved v0.11.4`, intermediate artifacts can be found at `/tmp/cargo-installVQRbyH`
    
    Caused by:
      Could not compile `rm-improved`.
    
    To learn more, run the command again with --verbose.
    
    opened by pwoolcoc 2
  • Security

    Security

    In rip's current state, a normal user could (depending on kernel settings) trick arbitrary users into overwriting arbitrary files (either on delete or restore).

    You need to make separate graveyards per-user and rip needs to make sure that each user graveyard is owned and writable by the user and only by the user. Alternatively, you could use setuid and run rip as root (and do some very careful permission checks) but that's very hard to do correctly. You could also run a rip daemon as root but that would complicate things.

    opened by Stebalien 2
  • Note macOS Homebrew install in README

    Note macOS Homebrew install in README

    Resolves #14. ~~This is conditional based on https://github.com/Homebrew/homebrew-core/pull/64107/ merging, so I am leaving it as a draft until then.~~ rm-improved is now available via Homebrew.

    opened by knowler 1
  • Fix travis build

    Fix travis build

    Build was broken because the uninstall path was wrong. Simpler option is just not to have Rust installed at all by using the generic image :) I've also upgraded the travis config to more modern options.

    opened by palfrey 1
  • Archlinux AUR installation

    Archlinux AUR installation

    Hi, I've added this package to AUR as rm-improved (due to name conflict with rip). Feel free to include installation instruction in your README.

    Something like this:

    ArchLinux installation:

    Package can be installed from AUR. $ yay -S rm-improved

    opened by EvansJahja 1
  • /tmp might be a partition with small free space

    /tmp might be a partition with small free space

    What if /tmp is a partition with size x and you delete an file with size y and y > x? What if /tmp would be big enough for y, but only free space of size m is left and m < y?

    ~/.trash seems to be more appropriate.

    opened by StefanoD 1
  • Pipes and other non-regular files

    Pipes and other non-regular files

    The current behavior is to loudly fail when =rip= encounters a non-regular file, like those produced by =mkfifo= or =mknod=. Is there a safe and consistent way to deal with these?

    opened by nivekuil 1
  • Multiple users

    Multiple users

    Since the graveyard is stored in a globally accessible directory by default, all users get their files sent to the same directory. If rip -r as a normal user tries to restore something deleted from /root, it will throw an error.

    The proposed solution is to include the username in the histfile and limit rip -r to files owned by $USER. The current histfile structure is not flexible enough to support this, so it's probably best to make it an append-only log and implement a parsing algorithm (with stacks and such) for the resurrect option. The downsides are worse performance and disk usage, but these should be totally negligible.

    opened by nivekuil 0
  • Rip does not check if parent folders have the same name as deleted files

    Rip does not check if parent folders have the same name as deleted files

    If a file was deleted, and an item with a parent that has the same path of that file was also deleted, rip fail to delete the file.

    E.g., assuming graveyard is /trash and current folder is /:

    $ touch item
    $ rip item
    $ mkdir item
    $ touch item/file
    $ rip item/file
    error: Failed to bury file
    caused by: Failed to move /item/file to /trash/item/file
    caused by: Not a directory (os error 20)
    

    rip will try to move file to /trash/item/file, but does not check if /trash/item exists and is a file.

    opened by jeiang 0
  • Permissions error

    Permissions error

    error: Failed to write record at /Users/leontepe/.Trash/.record
    caused by: Operation not permitted (os error 1)
    

    System: macOS $GRAVEYARD: ~/.Trash

    It still deletes the file though—as in it's not present in the original location anymore after running the command.

    opened by ghost 0
  • Using as a stash

    Using as a stash

    It is not really an issue, so should be ok to close it. Just wanted to share my excitement in discovering this tool, as it looks perfect for my need to stash files.

    While working for eg. in a git repository or elsewhere, I end up creating some temporary files which doesn't really belong in the repository. At the same time, I don't feel like deleting them permanently as there is a chance I might need them sometime in distant future. But if I don't remove them the list of Untracked Files in git keeps increasing.

    So, I have added alias stash="rip --graveyard <my homedir>/stash". Rip will take care of keeping the backup, keeping multiple backups in case of conflicts and retaining the whole path. As a bonus, stash -s lets me see files stashed in current directory. So, thank you for this tool :)

    opened by amardeep 0
  • What happens if rip is interrupted?

    What happens if rip is interrupted?

    Suppose I use rip to move a large directory of files which takes a long time to finish. What happens if rip is interrupt before it finishes. Will any file be moved or will it leave nothing changed?

    opened by dclong 0
Releases(0.13.1)
Owner
Kevin Liu
Kevin Liu
`cd` alternative. Navigate by typing abbreviation of paths.

kn /n/ kn is an alternative to cd. It lets you navigate quickly by typing abbreviations. It doesn't track frecency or any other statistics. WARNING: T

Mikołaj Powierża 70 Dec 30, 2022
A modern alternative to watch command

A modern alternative to watch command

Tavo Annus 7 Oct 7, 2022
A simple and fast download accelerator, written in Rust

zou A simple and fast download accelerator, written in Rust Zou is a Snatch fork by @k0pernicus. Snatch is a fast and interruptable download accelerat

Antonin Carette 173 Dec 4, 2022
GTK application for browsing and installing fonts from Google's font archive

Font Finder This project is a from-scratch implementation of TypeCatcher in Rust. It is a GTK3 application for browsing through and installing fonts f

Michael Murphy 252 Dec 26, 2022
Linux Kernel Manager and Activity Monitor 🐧💻

Linux Kernel Manager and Activity Monitor ?? ?? The kernel is the part of the operating system that facilitates interactions between hardware and soft

Orhun Parmaksız 1.7k Jan 5, 2023
A project for automatically generating and maintaining Debian repositories from a TOML spec.

Debian Repository Builder A simple utility for constructing and maintaining Debian repositories. Configuration of a repo is based on the directory hie

Pop!_OS 52 Feb 7, 2022
Utility that takes logs from anywhere and sends them to Telegram.

logram Utility that takes logs from anywhere and sends them to Telegram. Supports log collection from files, journald and docker containers. More abou

Max Eliseev 85 Dec 22, 2022
Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux.

Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux. When is this Rust crate useful? Performance or latency is crucial, and

null 72 Jan 3, 2023
CLI utility to move (or rename) your files to a new location and redirect all of its symbolic links, to the new path

Move Links CLI utility to move (or rename) your files to a new location and redirect all of its symbolic links, to the new path (or name). Usage execu

Ben Mefteh 18 May 22, 2022
A tool to simplify reprovisioning a fresh OS. Installs packages and manages dotfiles.

[[TOC]] Comtrya This is better, yes? Warning This tool is ridiculously early in its development. I'm building out features as I migrate my dotfiles ov

David McKay 2 Dec 29, 2022
A tool to simplify reprovisioning a fresh OS. Installs packages and manages dotfiles.

Comtrya This is better, yes? Warning This tool is ridiculously early in its development. I'm building out features as I migrate my dotfiles over. Thos

Comtrya 272 Jan 7, 2023
Parallel finance a decentralized lending protocol built on top of the Polkadot ecosystem. Our unique approach will allow users to earn "double interests" from staking and lending their tokens simultaneously.

Parallel Finance A new Cumulus-based Substrate node, ready for hacking ?? Getting Started Follow these steps to get started with the Cumulus Template

parallel-finance 100 Dec 17, 2022
idf-env tool helps set up and manage ESP-IDF installations

idf-env Tool for maintaining ESP-IDF environment. Quick start Install serial drivers for ESP boards on Windows. Execute following command in PowerShel

Espressif Systems 19 Dec 4, 2022
A system handler to get information and interact with processes written in Rust

A system handler to get information and interact with processes written in Rust

Guillaume Gomez 1.1k Jan 3, 2023
OCI Runtime, Image and Distribution Spec in Rust

oci-spec-rs Open Container Initiative (OCI) Specifications for Rust This library provides a convenient way to interact with the specifications defined

Containers 119 Dec 29, 2022
It is a backup tool that creates backups and stores them on an object storage

Hold My Backup It is a backup tool that creates backups and stores them on an object storage. By default it uses minio but you can use AWS: S3 as well

Taylan Dogan 13 Feb 17, 2022
desktop automation, screen capture, input listen/simulation, asar compress, color picker for nodejs and electron based on rust

desktop automation, screen capture, input listen/simulation, asar compress, color picker for nodejs and electron based on rust. 基于 Rust / WASM 提供截图、取色、键鼠事件监听模拟、压缩解压、图像处理、获取已安装应用等跨平台功能的现代异步 Nodejs 模块,占用空间小, 安装便捷, 使用简单, 高性能, 资源占用极小, 可取代 iohook 和 robotjs

null 48 Dec 15, 2022
`haproxy_autconfd` is a daemon that automatically assembles a HAProxy config and restarts HAProxy if the config changes

haproxy_autconfd Welcome to haproxy_autconfd ?? haproxy_autconfd is a daemon that automatically assembles a HAProxy config and restarts HAProxy if the

null 0 Nov 9, 2021
Reproducible builds, dev envs and deployments.

?? Toros An implementation of Nix in Rust. Syntax support: With NixEL Interpreter support: Int Binding (aliasing) Let-in (flat bindings without interp

Kevin Amado 35 Dec 23, 2022