1

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.

user1096294
  • 829
  • 2
  • 10
  • 19
  • Aliases are very limited. You should be creating a function instead. – tripleee May 26 '14 at 15:09
  • Thank you, I have just realized this myself. I will need to accept parameters to do what was suggested in the answer below. Here is a reference [link](http://stackoverflow.com/questions/7131670/make-bash-alias-that-takes-parameter) – user1096294 May 26 '14 at 15:10

1 Answers1

1

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.

timgeb
  • 76,762
  • 20
  • 123
  • 145