0

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.

3
  • just put cd ~; at the front of the update script? you could also put cd /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. May 3, 2015 at 21:07
  • Alternately, you could use 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. May 3, 2015 at 21:15
  • Thanks Frank - this didn't work but it did get me thinking in the right direction - is the directory actually deleted
    – simmons
    May 4, 2015 at 8:12

1 Answer 1

0

Just in case it's of help to anyone. It turns out that the way the shell works is that if a current directory is deleted in a different instance of shell, and is then recreated and populated with files, the original shell will show an empty directory.

To see the files again, just go

cd .

This led to solving the original problem by not deleting the directory itself (just deleting and replacing specific files).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .