user3368447
user3368447

Reputation: 125

Can a script remove the folder in which is contained? + PBS job

I have a bash script which does some operations and at the end I would like the script to delete the folder in which it is contained. So I put at the end of the script the following commands

olddir=`pwd`
cd ..
rm -rf "$olddir"

The content of the folder is deleted, but the folder not and I get the following error

rm: cannot remove `folder': Directory not empty

The script is called by a pbs script which is also contained in the same folder. What is the problem?

Upvotes: 2

Views: 198

Answers (1)

dbeer
dbeer

Reputation: 7203

If you wish to clean up a directory that the job is going to use, the best thing to do would probably be to create a specific directory at the beginning of the job instead of simply backing up and deleting the current directory as you are currently doing.

I think you'd be better off doing something like:

  1. Make a directory
  2. Set the permissions so only you can access it.
  3. cd to that directory
  4. do all the work for your job
  5. cd back to the original working directory
  6. remove the created directory.

Upvotes: 0

Related Questions