I would like to create an alias for the move command -
trash='mv <some files> /home/$USER/.local/share/Trash/files'
How do I make this work?
I want the destination to always be the same. But I want to be able to pass the files to be moved.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityUse function instead of alias, defined in .bashrc
nano ~/.bashrc
# put inside .bashrc:
trash() {
for item in "$@" ; do
echo "Trashing: $item"
mv "$item" /home/$USER/.local/share/Trash/files
done
}
Then in shell prompt you can use:
$ trash file1 file2
You can only append arguments to an alias. Fortunately, mv
allows you to do this, with the -t
option
alias trash='mv -t ~/.local/share/Trash/files'
You can also create a bash script and run that script with an alias.
trash.sh:
#!/bin/sh
for arg in $*; do
mv $arg /home/$USER/.local/share/Trash/files
done
exit 0
.bashrc:
alias trash="/path/to/script/trash.sh"
gio trash
(in earlier versions of Ubuntu,gvfs-trash
) i.e. you can just typegio trash <some files>
. If that's really too long then you can alias italias trash='gio trash'
.