Find the answer to your Linux question:
Results 1 to 10 of 10
Hi, I made a terrible mistake. I wrote a program in which it would make a subfolder under a specific folder. Due to a spell mistake, my program made a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2013
    Posts
    5

    Question how to remove a wrongly made "~" folder


    Hi,

    I made a terrible mistake.

    I wrote a program in which it would make a subfolder under a specific folder. Due to a spell mistake, my program made a folder named "~".
    I found it is exactly my home folder, however I can't remove it, because if I delete the folder it will autually remove my home folder!!
    Here is an example,
    My home folder is /home/AAA
    there is a folder named BBB under my home folder: /home/AAA/BBB,
    the wrongly made folder "~" is under BBB, which is /home/AAA/BBB/~.

    What I want to do is to remove the useless folder BBB, however, if I do rm -rf /home/AAA/BBB it will also remove "~" folder under /home/AAA/BBB and lead to a recusive removal of my home folder /home/AAA. Terrible!

    Could someone here help me with this?

    thank you in advance.

  2. #2
    Administrator jayd512's Avatar
    Join Date
    Feb 2008
    Location
    Kentucky
    Posts
    5,023
    Hello and Welcome!

    My home folder is /home/AAA
    there is a folder named BBB under my home folder: /home/AAA/BBB,
    the wrongly made folder "~" is under BBB, which is /home/AAA/BBB/~.
    So under your example, we're saying that you are username AAA. Correct? Then there is a directory (BBB), and finally the unwanted folder (~). And you want to remove the unwanted (~) folder. Still correct?
    If that's the case, then you can cd into the BBB directory, and remove the folder from there.
    Or, since you mentioned a spelling error, you could just rename the folder.
    Jay

    New users, read this first.
    New Member FAQ
    Registered Linux User #463940
    I do not respond to private messages asking for Linux help. Please keep it on the public boards.

  3. #3
    Just Joined!
    Join Date
    Aug 2013
    Posts
    5

    Hi, Jay

    Quote Originally Posted by jayd512 View Post
    Hello and Welcome!


    So under your example, we're saying that you are username AAA. Correct? Then there is a directory (BBB), and finally the unwanted folder (~). And you want to remove the unwanted (~) folder. Still correct?
    If that's the case, then you can cd into the BBB directory, and remove the folder from there.
    Or, since you mentioned a spelling error, you could just rename the folder.
    Thank you for the quick response.

    If I cd into BBB and rm ~, it exactly remove the contents of /home/AAA which is my home folder. I tried to rename '~' using "mv ~ CCC", I got the following error message:
    mv: cannot move ‘/home/AAA’ to a subdirectory of itself, ‘CCC’.

    Actually, if "ls" /home/AAA/BBB/~, it gives me a list of my home folder /home/AAA.

  4. #4
    Administrator jayd512's Avatar
    Join Date
    Feb 2008
    Location
    Kentucky
    Posts
    5,023
    Well that's kind of a pickle...
    Have you tried doing this as root?
    Jay

    New users, read this first.
    New Member FAQ
    Registered Linux User #463940
    I do not respond to private messages asking for Linux help. Please keep it on the public boards.

  5. #5
    Linux User IsaacKuo's Avatar
    Join Date
    Feb 2005
    Location
    Baton Rouge, LA, USA
    Posts
    406
    Quote Originally Posted by forfan View Post
    Here is an example,
    My home folder is /home/AAA
    there is a folder named BBB under my home folder: /home/AAA/BBB,
    the wrongly made folder "~" is under BBB, which is /home/AAA/BBB/~.
    If it's actually a folder, then this will work:

    cd BBB
    rmdir "~"

    However, it sounds like you have some sort of link rather than a folder. Could you give us the listing of:

    ls -l BBB
    Isaac Kuo, ICQ 29055726 or Yahoo mechdan

  6. #6
    Linux User IsaacKuo's Avatar
    Join Date
    Feb 2005
    Location
    Baton Rouge, LA, USA
    Posts
    406
    By the way, the "rmdir" command will only delete empty folders, so you don't have to worry about it accidentally deleting important stuff.
    Isaac Kuo, ICQ 29055726 or Yahoo mechdan

  7. #7
    Administrator jayd512's Avatar
    Join Date
    Feb 2008
    Location
    Kentucky
    Posts
    5,023
    Quote Originally Posted by IsaacKuo View Post
    However, it sounds like you have some sort of link rather than a folder.
    I didn't think about it possibly being a link.
    Jay

    New users, read this first.
    New Member FAQ
    Registered Linux User #463940
    I do not respond to private messages asking for Linux help. Please keep it on the public boards.

  8. #8
    Just Joined!
    Join Date
    Aug 2013
    Posts
    5
    Hi Jay

    Thank you for follow up.
    I finally found solution.

    step 1: cd /home/AAA/BBB
    step 1: mv "~" newname
    here is the point, "mv ~ newname" will get error message, using quotation for folder name ~ works well
    step 2: rm -rf newname
    step 3: cd /home/AAA
    step 4: rm -rf BBB
    DONE

    Thank you so much for your kind help!

    Quote Originally Posted by jayd512 View Post
    Well that's kind of a pickle...
    Have you tried doing this as root?

  9. #9
    Just Joined!
    Join Date
    Aug 2013
    Posts
    5
    Hi,

    Thank you for the reply.

    Yes, rm -rf "~" works for me.




    Quote Originally Posted by IsaacKuo View Post
    If it's actually a folder, then this will work:

    cd BBB
    rmdir "~"

    However, it sounds like you have some sort of link rather than a folder. Could you give us the listing of:

    ls -l BBB

  10. #10
    Just Joined!
    Join Date
    Aug 2013
    Posts
    5
    Oh, thank you!

    Quote Originally Posted by IsaacKuo View Post
    By the way, the "rmdir" command will only delete empty folders, so you don't have to worry about it accidentally deleting important stuff.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •