0
foreach file (`find . | awk -F/ 'NF == 3'`)
  echo $file
  set olddir = `echo $file| cut -f 1-3 -d '/'`
  echo $olddir
  set newdir = `echo $olddir  | cut -c 1-2,5-`
  echo $newdir
  mkdir -p $newdir
  mv -f $file $newdir
  rmdir $copy_datalog/*
  echo $newdir
  cp -r  $copy_datalog/* $new_datalog

When cp -r $copy_datalog/* $new_datalog is run, the files deleted with rmdir $copy_datalog/* are still being copied.

output of ls -la $copy_datalog :

total 10 
drwxr-xr-x 5 root root 512 Oct 27 08:58 . 
drwxr-xr-x 10 root root 512 Oct 27 08:58 .. 
drwxr-xr-x 5 root root 512 Oct 27 08:58 Jul2013 
drwxr-xr-x 3 root root 512 Oct 27 08:58 jaa200

Output for rmdir :

rmdir: directory "/DATALOGARC/datalog_copy/Jul2013": Directory not empty
rmdir: directory "/DATALOGARC/datalog_copy/jaa200": Directory not empty

Based on my understanding, when rmdir runs, it removes the empty directory. So, why is it still copying the directories?

  • Probably because the directory is not really empty - there's a hidden file or something in it. Does the rmdir give an error message? Also, GNU rmdir seems to have a flag "--ignore-fail-on-non-empty". Do you have an alias rm? – Bruce Ediger Oct 26 '15 at 23:39
  • im pretty sure the directories not empty since im make the directory to test the script. – wina Oct 26 '15 at 23:41
  • can you post the output of ls -la $copy_datalog ? run it after rmdir $copy_datalog/* thx – lese Oct 27 '15 at 0:02
  • your rmdir $copy_datalog/* command does not delete $copy_catalog. It tries to rmdir every file and directory in $copy_catalog/. Also, remember to quote your variables - always quote variables unless you are splitting with $IFS. Finally, foreach possibly implies csh - don't use csh for scripting. or even tcsh. if it's zsh, that's fine. – cas Oct 27 '15 at 0:10
  • when im trying to rmdir only, not copying, it works and remove the empty directory. but when rmdir directory then copy after that, it copy all the empty directory. Out put ls -la $copy_datalog : total 10 drwxr-xr-x 5 root root 512 Oct 27 08:58 . drwxr-xr-x 10 root root 512 Oct 27 08:58 .. drwxr-xr-x 5 root root 512 Oct 27 08:58 Jul2013 drwxr-xr-x 3 root root 512 Oct 27 08:58 jaa200 Output for rmdir : rmdir: directory "/DATALOGARC/datalog_copy/Jul2013": Directory not empty rmdir: directory "/DATALOGARC/datalog_copy/jaa200": Directory not empty – wina Oct 27 '15 at 1:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.