LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-16-2013, 10:31 AM   #1
red_ifo
LQ Newbie
 
Registered: Sep 2013
Posts: 2

Rep: Reputation: Disabled
Removing folder named ~ inside directory


I realize that ~ is a shortcut to your home directory, but I've got a directory that contains files, folders, and a folder named ~. And of course if I try to go to that folder I end up in my home folder. If I try to delete the containing directory, it starts deleting from my home folder. It doesn't look like a symbolic link, just a normal folder named ~. How do I remove this folder from the directory?

Thanks for any help here!
 
Old 09-16-2013, 10:33 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
maybe one of these would work:
Code:
rm ./~
rm \~
rm '~'
 
Old 09-16-2013, 10:40 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
You can delete a file with strange characters (especially hidden characters) by it’s inode number.

To find the inode number of a file, list the directory with the -i option:

Code:
ls -i "~"
quoting "~" should keep ~ from expanding to /home/user...YMMV

Note the inode number of the file "~"

Use the find command to delete the file by it’s inode number:

Code:
find . -inum nnnnnnn -exec echo rm {} \;
Warning:
ECHO is a 'dry-run', remove once the correct file has been verified.


Alternate solution, use a graphical File Manager.
 
Old 09-16-2013, 10:46 AM   #4
red_ifo
LQ Newbie
 
Registered: Sep 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you for the quick replies!

I did your find command and it was telling me that it was a directory, and if I changed to rmdir then it told me it wasn't empty. I was able to get into that directory and there was a tmp directory, I deleted that and the '~' directory vanished. I've never seen that before. But thanks again for both of your suggestions, they were very helpful in getting rid of it.
 
Old 09-16-2013, 10:56 AM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Tab completion is very helpful for matching bad file/dir names.

For example
Code:
rmdir ~
followed by Tab, will complete to
Code:
rmdir \~/
which will allow you to remove it properly.
 
Old 09-16-2013, 12:42 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Glad it worked out.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to limit max. number of folder can be created inside a folder Winanjaya Linux - General 4 08-01-2013 05:47 AM
[SOLVED] Better way to create a folder for each month, with another folder inside of each anon091 Linux - Newbie 9 12-03-2012 10:38 AM
Virtual Box. Removing a shared folder inside virtual xp. glore2002 Linux - Software 2 05-20-2007 11:12 AM
Removing a Directory from the Terminal without deleting each file or folder lennysokol Linux - General 4 05-30-2005 11:30 PM
how can i default the max folder file size when it create inside a folder antony_csf Linux - Software 1 06-17-2004 02:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration