0
[root@host dir1]# ls -lrt
total 412
-rw-r--r-- 1 root root  13747 Jun  3 16:01 -lang?[5~?[5~?[5~?[5~?:q!

We tried different ways and they don't work.

[root@host dir1]#  ls -lrt | tail -1 | awk '{print $9}' | xargs -I file rm file
rm: invalid option -- 'l'
Try `rm ./'-langq!'' to remove the file `-lang\033[5~\033[5~\033[5~\033[5~\033:q!'.
Try `rm --help' for more information.

[root@host dir1]# rm ./'-langq!''
> ^C
DavidPostill
  • 153,128
  • 77
  • 353
  • 394
chz
  • 469
  • 3
  • 10
  • 19
  • Try rm -rf ./-* ..... IF this is the only one beginning with a - – cutrightjm Jun 03 '15 at 23:24
  • Hi Folks, using inum option helps. – chz Jun 04 '15 at 03:26
  • You have two independent problems here: (1) the file name begins with `-`; and (2) the name contains unprintable characters. (1) is easily solved by including `./` before the name, or by using `rm -- ` to signify that the next parameter is not an option. To answer (2), if your `ls` supports it, `ls -b` will show you the full file name with the unprintables expanded into escape sequences. If you can't specify the file name uniquely by using wild cards `*` and `?` (eg `rm -- -lang*:q!`) your best bet is to use a GUI file manager. – AFH Jun 04 '15 at 12:12

1 Answers1

0

I created a file with weird characters and deleted it with this:

rm *lang*

wildcards make life easier for everyone. I entered these 2 sentences because of the character requirements.

m79lkm
  • 641
  • 6
  • 5
  • That won't work if the file name begins with `-`: you would need `rm -- *lang*`. – AFH Jun 04 '15 at 11:21