Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some directory with funny character such as ^M at their back. They were created accidentally and I want to delete them.

I list the directories by ls -iql and wrote down their inode number, then I try to delete it by searching it by inode number.

find . -inum 7990028 -exec rmdir -i {} \;

But the command is so slow. I got only some hundreds of directories, but there are a lot of files inside the directories. I think the find command must have been searching through the files.

How can I improve this?

share|improve this question
also the command fail to delte the can I get it right? – lamwaiman1988 Oct 27 '11 at 3:31
Why are you looking for directories by inode? – Ignacio Vazquez-Abrams Oct 27 '11 at 3:32
Because I don't know what are the funny character. It is invisible when I just "ls", and become "?" when I "ls -q". But it is not "?". – lamwaiman1988 Oct 27 '11 at 4:32
pipe the output of ls through 'cat -v' or 'cat -A' to have it show you what the 'funny characters' are. From your example though, they're Carriage Returns (^M). Could remove all with 'rm -rf "*{CTRL-V}{CTRL-M}"'. But I'd run that as 'ls "*{CTRL-V}{CTRL-M}"' first just to check things. '-rf' is VERY powerful (aka dangerous) – lornix Oct 27 '11 at 9:50

The . in the command means "search from the current directory". So to make it fast, you should be in the directory above the directory you want to delete. You can then also limit the search depth to the current directory, and also limit by directories only:

find . -inum 7990028 -type d -maxdepth 1 -exec rmdir -i {} \;
share|improve this answer
aix doesnot have maxdepth option. I already at the directory above the directories. PS. aix have -depth option, but it doesn't work. – lamwaiman1988 Oct 27 '11 at 4:05
Ah, aix. Ok, well the -type d will make a big difference. – Paul Oct 27 '11 at 4:12
It's still very slow. – lamwaiman1988 Oct 27 '11 at 4:31

Since you know that the problematic characters are non-printable, you can simply use

rm -rf *[^[:print:]]*
share|improve this answer

It's probably much easier just to delete all filenames that contain the ^M in them than to, well... find.

rm -rf *CtrlVCtrlM*

share|improve this answer
actually I don't what the character is. When I do "ls -q", they have "?" at their back, and I tried "?" already. – lamwaiman1988 Oct 27 '11 at 4:06
Does your shell have auto-complete? Can you just use tab to complete the directory name? – Paul Oct 27 '11 at 4:13
@gunbuster363: So then use a range instead. *[Ctrl-V Ctrl-A Ctrl-V Ctrl-B ... Ctrl-V Ctrl-]]* – Ignacio Vazquez-Abrams Oct 27 '11 at 4:23
Recommend quoting that, since an errant space can ruin your day. – lornix Oct 27 '11 at 9:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .