1

This is probably very simple, but I really can't get it to work. I have an old directory with a symlink in it. I need to delete the directory, but it says it is not empty when I try:

rm -f dirname  

(I have also tried -r, and -rf)

I get: "usage: rmdir directory-name"

So then I try rmdir -f dirname, but I get the same response.

4
  • 2
    What OS? You are claiming you get a rmdir message by running rm. What travesty has been inflicted on your rm? Try type rm. Commented Jun 19, 2012 at 1:32
  • As @jw013 says, an rmdir error from rm proper is odd. Try /bin/rm -r dirname. Commented Jun 19, 2012 at 1:33
  • 3
    Everyone, OP is trying to delete from inside a ftp client, not the Unix command shell. I tagged the question with osx and ftp and edited the question header, but the edit has to be approved first before it shows. Commented Jun 19, 2012 at 2:41
  • If usage is rmdir directory-name then it isn't asking for any args, so -f would be inappropriate. Try rmdir dirname. Commented Oct 6, 2016 at 17:35

4 Answers 4

1

Two things come to mind:

(1) did you check the directory to make sure it's really empty? Did you look for hidden files with

ls -a?

hidden files: files with a name that start with . and don't show with regular ls. If you do find some, delete them and try your command again.

(2) try rm -fR dirname

22
  • I'm on a Mac using terminal to ftp. I tried 1 & 2. There are no hidden files. When I try 2, I still get "usage: rmdir directory-name" Commented Jun 19, 2012 at 1:38
  • @user19993 re "on a Mac using terminal to ftp" .. is this osx, and just to be sure, you are trying to delete the directory not via ftp, but on your Mac in one of your directories, right? Commented Jun 19, 2012 at 1:42
  • I am on a mac OSX. I have connected to my ftp via terminal - in an attempt to delete this directory because I cant seem to do it via FTP programs or web interface. Commented Jun 19, 2012 at 1:43
  • 1
    @user19993 Ok, thanks that's helpful, I added a OSX tag to your question. I am still a bit unclear about how/where you are trying to delete the file. What is your prompt, is it a regular terminal prompt or something like ftp>? Commented Jun 19, 2012 at 1:46
  • I am connected to my Dreamhost ftp account via terminal for Mac. I have a directory in this account that used to hold a wordpress install. I deleted the files within, but the wp-content folder is still there with a symbolic link inside. I want to remove this entire directory, but I cant. I assume the best (most powerful) way to do this was via command line. However, I cant seem to get the force remove commands to work. I hope this helps - again I'm pretty new to this so sorry if I'm missing something here. And yes the prompt is ftp> Commented Jun 19, 2012 at 1:52
1

Before you can remove the directory, you need to remove the file that's in it.

rm testing/name_of_the_symbolic_link
rmdir testing

If there are many files, you need to remove them all.

If you want the convenience of familiar command line or GUI file manipulation tools to manipulate files over FTP, you can mount the FTP directory as a filesystem. Some OSes have this feature integrated in their GUI (for example, Ubuntu does as far as I recall); I don't know about OSX. You can mount the FTP directory on the command line using CurlFtpFS.

mkdir ~/mnt
curlftpfs ftp://ftp.example.com/remote/path ~/mnt
rm -r ~/mnt/testing
fusermount -u ~/mnt
1
  • Thank you! It's the elegant decision for remove dir in FTP! Commented Aug 6, 2018 at 10:42
0

To find any lagging files under testing/ and get rid of them.

find testing/ -type f -exec rm -f {} \;

Sometimes files or symlinks can get created that contain special characters and those can stymie our attempts to remove them using common tools.

Then, do the same for directories:

find testing/ -type d -exec rm -f {} \;

After that, testing/ should be empty and you should be able to rmdir it.

4
  • Tim, I am using Mac OSX terminal to connect to ftp to my Dreamhost server. The find command is not available. Again, I plead ignorance on the subject matter. Commented Jun 19, 2012 at 2:35
  • 1
    ah, you may want to try a graphical ftp client like Transmit (panic.com/transmit). The GUI clients often have implementations of advanced features that are difficult in the old CLI ftp client. Commented Jun 19, 2012 at 2:42
  • I have transmit, but when I try to delete the folder or file i get an error. That is why I resulted to the command line. Commented Jun 19, 2012 at 2:46
  • 1
    Dreamhost has shell access, via SSH, if you enable it for your account. That would possibly give you better control over that directory. (wiki.dreamhost.com/Enabling_Shell_Access) Commented Jun 19, 2012 at 15:20
-1

Try this command:

rmdir -f dirname
1
  • Explanation necessary, especially with so many better ideas right there. Why might this work when others didn't/don't? Commented Jul 8, 2012 at 17:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.