You cannot eliminate ~ completely, but at least there are some workarounds available.
These workarounds may not always be usable, but for other cases, it can be really helpful:
- Before doing the command, change your directory using
cd (without arguments). This changes your working directory to ~.
If you frequently need to change the working directory to a folder within your home folder, use the CDPATH variable in bash. Run the next command to minimize cd ~/folder to cd folder, but still allow to change to a directory folder in the current directory if exist.
CDPATH=.:~
To make this change persistent, add the line to ~/.bashrc. As its name may suggest, it only works for the cd command in bash.
- Use the
$HOME variable if you really want to avoid ~, in case the key would give you an electrical shock for example. This is especially useful in cases where tilde-expansion would not occur, between quotes for example ("~")
Create a function for a command. If you frequently need to copy files to a directory in your home directory as in cp file ~/archive, you can run the next code to create a function:
cph(){ cp "$1" "$HOME/$2";}
and use it as:
cph file archive
Note that you cannot pass arguments or multiple files to this function, that needs additional tweaking. As with the CDPATH hack, you can put it in your ~/.bashrc file to make it persistent.