rmdir

This is a discussion on rmdir within the Linux Programming forums, part of the Platform Specific Boards category; How can I remove a non-empty directory in UNIX? Let's say i had a directory called "myFolder", I know that ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    61

    rmdir

    How can I remove a non-empty directory in UNIX? Let's say i had a directory called "myFolder", I know that "rmdir myFolder" should do the trick but I get complaints that the directory still has contents in it. I know there has gotta be a way to do this (unless i have to manually erase 100 files from directory "myFolder" in order to remove "myFolder").

    Thanks in advance.

  2. #2
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    use rmdir with the -R switch, this will erase the directory and its contents. Note: if you are logged in as root (superuser) be careful with this command.
    Monday - what a way to spend a seventh of your life

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    79
    rm -R will recursively delete the contents of the directories and the directories themselves.

    And you woudn't have to "manually" delete the files in a directory. rm * will delete all the files in the current directory.
    All generalizations are false

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    thanks guys for your help!

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    Actually, some problems again...

    say i have a directory called "test", and in this directory are 2 files called "test1" and "test2".

    Ok so i cd to "test" and try the <rm *> command.

    i get back something like this:

    $ rm *
    rm: remove test1 (yes/no)? y
    rm: remove test2 (yes/no)? y
    $

    it prompts me to remove each file!? so if there are a 100 i have to type 'y' 100 times??

    Than i tried the <rm -R>:

    i get something similar again:

    $ rm -R test
    rm: examine files in directory test (yes/no)? y
    rm: remove test/test1 (yes/no)? y
    rm: remove test/test2 (yes/no)? y
    rm: remove test: (yes/no)? y
    $

    again it prompts each file! Also a a note, I tried replying "no" to "examine files in directory test (yes/no)?", thinking that by answering "no" i would'nt be prompted about each file. But nothing gets deleted? By the way, this is not linux but SunOS-5.8 (still unix); i don't know if that has anything to do with it?

    i'm new to this stuff and appreciate the help!

  6. #6
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    It's because you have some alias to rm as rm -i in your
    .bashrc or one of dotfiles. I genearly don't like
    this, some distros put the entry some don't I guess.

    rm -f should do it

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    79
    Try unalias rm, if you're using Bash(I assume so)

    Typing 'a' at the prompt instead of y or n might do the trick, too.

    Also, you should remove the line from the ~/.bashrc file, too.
    All generalizations are false

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about the remove function
    By caduardo21 in forum C Programming
    Replies: 16
    Last Post: 09-01-2006, 07:13 AM
  2. errno, rmdir
    By PunkAE in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2001, 12:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21