问题原文
原帖链接 · Mausy5043 · CC BY-SA 3.0
I made a typo:
$ history
169 9:34 la /usr/local/etc/
170 9:35 sudo mkdir ^C
171 9:36 sudo mkdir /usr/local/etc/dnsmasq.d
Now I have a file that is called ^C (ctrl+C)!!
When I use ls I just see a questionmark (probably due to the locale?)
% ls -al
total 60
drwxr-xr-x 2 root wheel 512 Jan 21 09:35 ? <- this one
drwxr-xr-x 5 admin wheel 512 Jan 21 16:24 .
drwxr-xr-x 3 root wheel 512 Jan 20 14:29 ..
-rw-r--r-- 1 admin nobody 1114 Jan 20 19:10 .cshrc
-rw------- 1 admin wheel 6002 Jan 21 15:27 .history
-rw-r--r-- 1 admin nobody 182 Jan 20 14:29 .login
-rw-r--r-- 1 admin nobody 91 Jan 20 14:29 .login_conf
-rw------- 1 admin nobody 301 Jan 20 14:29 .mail_aliases
-rw-r--r-- 1 admin nobody 271 Jan 20 19:04 .mailrc
-rw-r--r-- 1 admin nobody 726 Jan 20 19:05 .profile
-rw------- 1 admin nobody 212 Jan 20 14:29 .rhosts
-rw-r--r-- 1 admin nobody 911 Jan 20 19:06 .shrc
drwx------ 2 admin nobody 512 Jan 20 15:05 .ssh
drwxr-xr-x 2 admin wheel 512 Jan 20 19:08 bin
and
% ls -i
3611537 ? 3611534 bin
I want to remove this file. I try mv and when using tab-completion it shows me:
% mv
^C/ bin/
Obviously I can't type a ^C :-/ How do I remove this file?
社区高分解答
原帖链接 · Ruslan · CC BY-SA 3.0
Yet another way: use stat to get an escaped representation of the directory name:
$ stat *|grep File:
File: ‘\003’
Now you know a representation of the file name, so you can remove the file by name using printf:
$ rmdir -v "$(printf '\003')"
rmdir: removing directory, ‘\003’
Or, if you're using bash, you can avoid printf:
$ rmdir -v $'\003'
rmdir: removing directory, ‘\003’
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
