Skip to content

naoking158/rm-alternative

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rm-alternative

$ rm --help

===============
This is a modified rm program to move SRC to RM_ALT_TRASH instead of remove it.

Usage:
    rm-alternative.bash [OPTION]... SRC [SRC]...

Options:
    -h, --help
    -n, --dry-run
    -d, --delete  ----  `rm -rf SRC` is executed using `/bin/rm` (Be careful!!!)
        --restore ----  Restore previously moved files to their original locations.
                            Previously moved history is saved in RM_ALT_HIST

Default values:
    RM_ALT_TRASH = ~/.myTrash
    RM_ALT_HIST  = $RM_ALT_TRASH/.moved_hist

Features

  • When rm SRC is executed, SRC is moved to ~/.myTrash
    • If there is another SRC with the same name in ~/.myTrash/, the older one will be renamed as SRC-DATE
  • rm [-d/--delete] SRC invokes the system command: /bin/rm -rf SRC
  • With -n/---dry-run option, no files will be moved, only what will be done will be displayed
  • If you run rm by mistake, you can undo by running rm -restore

Installation

  1. Clone this repository
    git clone https://github.com/naoking158/rm-alternative.git
        
  2. Set alias in .bashrc, .zshrc, etc…
    alias rm='/path/to/rm-alternative.bash'
        

    Add execute permission to rm-alternative.bash as like chmod +x rm-alternative.bash if necessary.

  3. Option: By setting sudo as an alias, commands registered in the alias can be invoked with sudo
    alias sudo='sudo '
        

    Note that it is important to leave a space after sudo.

    See man bash for more detail.

    If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion.

Customization

To change the trash directory and the history file, set RM_ALT_TRASH and RM_ALT_HIST as environment variables in .profile, .bashrc, .zshrc, etc…

export RM_ALT_TRASH="/path/to/trash"
export RM_ALT_HIST="${RM_ALT_HIST}/filename_as_you_like"

References

LICENSE

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages