I have a directory which I run a program in.
/usr/bin/my-dir
I need to run the program from within the directory So I must go cd /usr/bin/my-dir ./my-program
I have a script that from a remote machine updates my-program like this: rm -rf /usr/bin/my-dir mv my-program /usr/bin/my-dir
The problem is when I have ssh'd into the machine and am in the directory /usr/bin/my-dir The script fails as it cannot successfully perform rm -rf /usr/bin/my-dir (it deletes all the contents but not the directory)
Is there any way around this (e.g. some way to configure the shell to allow deleting the directory while I'm in it?) or some other solution? Currently I cd out of the directory, run the script and then cd back into the directory but I have to do this hundreds of times a day - there must be a more efficient way to do this.
cd ~;
at the front of the update script? you could also putcd /usr/bin/my-dir
at the end so after the move you jump back. you are running all these commands in a script, right? if not, consider it, seeing as you do this hundreds of times per day.rmdir /usr/bin/my-dir
to remove the dir after you have rm -rf'ed it. rmdir will work on the current directory, and does not change the prompt, so the prompt is temporarily pointed to a non-existent location,, so when you recreate the dir, it will still be pointed to the right location.