4

How can I remove a non-empty directory with smbclient? I have tried the following:

1) rm

Result:

NT_STATUS_NO_SUCH_FILE listing [dir_path]

2) recurse;rm

Result:

No Error but also nothing happens! The folder remains as before!

3) rmdir

Result:

NT_STATUS_DIRECTORY_NOT_EMPTY removing remote directory file [dir_path]

4) recurse;rmdir

Result:

NT_STATUS_DIRECTORY_NOT_EMPTY removing remote directory file [dir_path]

5) rm [dir_name]/*;rmdir [dir_name]

Result:

NT_STATUS_OBJECT_NAME_NOT_FOUND deleting remote file [sub_dir_path]

NT_STATUS_DIRECTORY_NOT_EMPTY removing remote directory file [dir_path]

6) recurse;rm [dir_name]/*;rmdir [dir_name]

Result:

NT_STATUS_OBJECT_NAME_NOT_FOUND deleting remote file [sub_dir_path]

NT_STATUS_DIRECTORY_NOT_EMPTY removing remote directory file [dir_path]
  • 1) rm 2) recurse;rm 3) rmdir 4) recurse;rmdir 5) rm dirname/*;rmdir – mor Feb 23 '13 at 11:40
  • Please edit your question to show exactly what you tried, and the errors you got (if any). Don't put that information in comments please. – Mat Feb 23 '13 at 11:40
  • OK, I found a workaround: Mounting the remote windows share folder to a local directory and then doing "rm -r" Thanks to Mikhail who gave the hint here – mor Feb 24 '13 at 8:12
  • 1
    This question was on stackoverflow, and the interesting answer stackoverflow.com/a/15025524/2996931 – shgurbanov Feb 2 '14 at 18:15
0

From OP's comment:

OK, I found a workaround: Mounting the remote windows share folder to a local directory and then doing "rm -r" Thanks to Mikhail who gave the hint here – rahimi 2 days ago

With this, the question is effectively answered (and, as a side-effect, removed from Unanswered Questions queue).

  • 1
    -1, This is a non-answer to the real question, how do you do this with smbclient? – user146970 Dec 11 '15 at 2:57
  • If you know the answer chief, by all means. – Grizly Feb 19 '16 at 2:12
  • 2
    It is not possible, that is the answer. The smbclient tool is poorly designed and definitely can not do that... save some time at least. In many cases mounting a samba share is not a practical solution, so there is a huge incentive to know whether smbclient can do this thing. – user146970 Feb 19 '16 at 9:18
0

You can write some lines:

myHost=fubar
myShare=batch
myRootPath="next_version\\SNAPSHOT"
myDirectory="snafu-fubar"
myCredentials="sbb.ch\\ricky%password"                                                                                                                               

smbclient \\\\${myHost}\\${myShare} -D "${myRootPath}" -U ${myCredentials} -c "recurse on; ls ${myDirectory}" | grep '^\\' \
   | awk -F\\ '{print NF,$0}' | sort -nr | cut -d ' ' -f2- \
   | while read -r myDir; do
      myRoot="${myDir%\\*}"
      myFolder="${myDir##*\\}"
      smbclient \\\\${myHost}\\${myShare} -D "${myDir}" -U ${myCredentials} -c "del *" || true
      smbclient \\\\${myHost}\\${myShare} -D "${myRoot}" -U ${myCredentials} -c "rmdir \"${myFolder}\"" || true
done
0

A little late, but since 4.7.0 version of smbclient there is a deltree command that is able to do that. It will delete all files and directories matching mask from the current working directory on the server. No need to turn recurse on

smb: \> deltree <mask>
  • You should elaborate your answer. As it is now, it's more of a comment. – dr01 Jun 27 at 12:00
  • Agreed with the above comment, although a quick search indicates that deltree was added to smbclient. – Jeff Schaller Jun 27 at 12:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.