Avoid a common mistake when renaming directories
Recently I had trouble renaming a directory with the mv utility. When I was creating a directory to try out the fuse filesystem called sshfs, I accidentally misspelled the name of my new directory:
$ mkdir -p sshfs/tylre-unsyncopated
In case you don’t know about the -p switch for mkdir, check it out, it can be very handy! Realizing my error, I went to rename the directory by moving it…
$ mv sshfs/tylre@unsyncopated/ sshfs/tyler-unsyncopated/ mv: target `sshfs/tyler-unsyncopated/' is not a directory: No such file or directory
What a strange error message. It turns out that the trailing slash in the destination path is the culprit. Once I removed it, the move succeeded.
So how did that slash get there? Instead of typing out the whole destination directory, I tried to save some keystrokes by using bash’s tab-completion for the second argument to mv, the destination. Since the destination was pretty similar to the source, I typed ss[TAB]ty[TAB] to get sshfs/tylre-unsyncopated/. Since that was an actual directory at the time, bash appended the slash. But after I transposed the “r” and the “t” (C-t by default) the second argument to mv was no longer a valid directory. This is why mv complained. It thought I wanted to move sshfs/tylre@unsyncopated/ into an existing directory called sshfs/tyler-unsyncopated/.
Bonus: here are the two shell aliases I use with sshfs:
alias sshfss="sshfs username@server.net: ~/sshfs/username-server/ -o cache=no;echo 'sshfsuu when done. use ~/sshfs/u37343469-server/'" alias sshfsus="fusermount -u ~/sshfs/username-server"
The “s” at the end of each alias’ name is for “server”. So if at some point in the future I started to use sshfs with an account at e.g. google, I’d add two more aliases: sshfsg and sshfsgu. I’d like to hear about any more elegant solutions…


