2

I have these tricky directories that I can't figure out how to delete. If I run

ls -ld *

I get…

drwxrwxr-x 7 user1 taskfmri 2048 Jan 22 15:26 857263
drwxrwx--- 4 user2 taskfmri 2048 Jan 23 16:32 857263?

There are ~50 of these directories with '?' in the ls. Unfortunately, the '?' isn't literally a ?, but is instead some special character that the terminal can't display

What is the best way to remove all of these directories with unknown special characters, without deleting the almost-identically named good directories?

4 Answers 4

7

If all your directories have names made of digits and then a special char (neither digit nor letter), you could use

find -maxdepth 1 -type d -regex "./[0-9]*[^0-9a-zA-Z]" -exec rm -r {} \;

1

I faced a similar issue, and could not work out how to delete ./?d from CLI.

If you have Vim installed, it comes with a visual browser called netrw.

  1. You can open the directory by using vim ./ (to open current directory)
  2. Use the up and down arrows to place the cursor over the file.
  3. Press D (uppercase d) to delete the file.
  4. Press y to confirm.
0

Can't you just do this?

rm -r 857263?
0

I had such directory:

$ ll
total 0
drwxrwxr-x 2 user user 57 Oct  2 12:41  mydir.d
drwxrwxr-x 2 user user 38 Oct  2 12:30 'mydir.d }}'

And at first i thought that the ' is part of the name of the directory. I couldn't delete it in any way even rm -rf -- '*}*' or rm -rf -- '*\}*'

I ended up removing the directory via its inode number

# First review the files & inodes
$ ls -li
total 0
1234578 drwxrwxr-x 2 user user 57 Oct  2 12:41  mydir.d
6549872 drwxrwxr-x 2 user user 38 Oct  2 12:30 'mydir.d }}'
# ^^^
# inode

# 2nd: run with find
$ find . -inum 6549872
./mydir.d }}     <= this is where i noticed there are no commas

# 3rd: remove the dir via inode
$ find . -inum 6549872 -exec rm -rf "{}" \;

You must log in to answer this question.

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