user1096294
user1096294

Reputation: 849

Bash command aliasing for sshfs

I use sshfs to mount a remote drive onto my filesystem. However, whenever I unmount it, it removes the folder where it was created. My first question is what is the purpose of removing the folder. Second, is there a way to alias the sshfs command to execute mkdir in case when the directory given does not exist - so that I don't need to create one every time I want to mount a drive? I use bash as my default shell.

Upvotes: 1

Views: 840

Answers (1)

timgeb
timgeb

Reputation: 78690

You can test for the existence of a folder in bash with

[ -d "/path/to/the/folder" ]

and the negation would be

[ ! -d "/path/to/the/folder" ]

So an alias to test for / make the dir would look like:

alias test='if [ ! -d "/path/to/the/folder" ]; then mkdir -p "/path/to/the/folder"; fi'

Just work the above part into your sshfs alias.

Upvotes: 1

Related Questions