![]() bin/mv -f "$file_abspath" "$move_to_abspath" # directory will always be successful, we shall give the '-f' # However, to make absolute sure that moving the file to the trash ![]() # $move_to_abspath after the execution of the existence test above. # some other process would have had to create a file with the name # extremely unlikely race condition would have had to take place: # We're now almost certain that the file denoted by name # generated one denoted an existing file. # Generate a new name with a new timestamp, as the previously # The name of the moved file shall be the original name plus aīeginning="$trash_dir_abspath/$file_basename"_DELETED_ON_ Exiting."Įcho "Created directory $trash_dir_abspath"įile_basename=$(basename - "$file_abspath")Įlif ] then If ] thenĮcho "The file $trash_dir_abspath exists, but is not a directory. Trash_dir_abspath=$(realpath ~/.local/share/Trash) # calculations and other commands that can return 0, lest the shell interpret # (The latter setting necessitates appending " || true" to those arithmetic # Exit on using an uninitialized variable, and on a command returning an error. # disposition of each argument: does not exist, was already in trash, or was # The script will not choke on a nonexistent file. # deletion, and to avoid overwrites when moving a file to trash. ![]() # moves to the trash directory, both to inform the user of the time of the # The script appends a millisecond-resolution time stamp to all the files it # directory ~/.Trash/, unless it already exists. # There is no built-in trash directory on server hosts, so the script creates # both exist, the script relies on the 'gio trash' command. # existence of the gio command and of directory ~/.local/share/Trash. # To determine whether it's running on a desktop host, the script tests for the # they can still undo an unintended deletion before emptying the trash # an alternative to the 'rm' command, giving the user the peace of mind that # original location, nor that of emptying the trash directory rather, it offers # the script does not offer the functionality of restoring a trashed file to its On server hosts, the analogy is not perfect, as # graphical file manager, which, in the usual case, moves the deleted file(s) to # The script is intended as a command-line equivalent of deleting a file from a It works both on (Gnome) desktop and server hosts. # This script moves the files given as arguments to the trash directory, if they The script is tested to work I use it all the time myself. , and on other machines, moves the file(s) given as parameter(s) to a trash directory it creates. I've written the following Bash script that does the job on desktop machines, it uses ![]() On server machines, there is no equivalent of a trash directory. (The command doesn't prompt for confirmation even though I did not use theĭeleting files this way is reversible, while being more convenient than redefiningįor safety and having to confirm each deletion, which still leaves you out of luck if you accidentally confirm a deletion you shouldn't have. On the command line, and it works just like I'd selected the file in the file browser and clicked the DEL button: the file is moved to the desktop's Trash folder. f, -force Ignore nonexistent files, never prompt Neither of those are found by default on Ubuntu 18.04, but the command While those discussions have a point, I believe there’s still a niche for my request.) (As an aside, there have been endless discussions whether this approach is justified, rather than using frequent backups and VCS. Are there any existing solutions for this which don’t rely on a trash system from a graphical shell? Partial solutions for this exist, but the “restore” action in particular isn’t trivial. Furthermore, it’d be nice if the trash was automatically emptied on reboot (or a similar mechanism to prevent endless growth). Is a first step, but ideally this should also handle trashing several files of the same name without overwriting older trashed files, and allow toįiles to their original location with a simple command (a kind of “undo”). (maybe even aliasing the latter there are pros and cons for that).īy “trash” I mean a special folder. Is there a Linux script / application which, instead of deleting files, moves them to a special “trash” location? I’d like this as a replacement for
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |