大网数据广告活动
服务器运维问答

FreeBSD: Directory called ^C (really!) - how to remove?

· 52CE 我爱测

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 …

问题原文

原帖链接 · 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’

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-01-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。