Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove file with special characters? [duplicate]

I have a weird file on a Unix filesystem. It seems to have some special characters in the file name, but I've not been able to remove it. Even if I don't write the name directly in the rm command (and I do ls | rm instead), I get an error that the file doesn't exist. Below some commands that I've tried after a few searches on the internet, in order to debug the issue.

Do you have any suggestions on how to remove it? The system is AIX 7.1. I've tried with rm and a perl script too (simply listing all files and deleting everything from the folder), and none worked. I can't move the folder to /tmp either, I get the same error.

Thanks!

[root@server] ls -1b | od -bc
0000000  342 134 062 060 060 134 062 062 063 012
           ▒   \   2   0   0   \   2   2   3  \n
0000012
[root@server]$ ls -li
ls: 0653-341 The file ./– does not exist.
total 0
[root@server]$ ls
–
[root@server]$ ls | od -bc
0000000  342 200 223 012
           ▒ 200 223  \n
0000004
[root@server]$ rm *
rm: –: A file or directory in the path name does not exist.

Screenshot

rm failure

like image 733
filip Avatar asked Dec 06 '22 11:12

filip


1 Answers

A relatively safe way would be to list files' inodes with ls -i and then delete the one you need with find . -maxdepth 1 -type f -inum $inum -delete ($inum is the inode to delete).

And be grateful you are on Unix! ❤

like image 54
bobah Avatar answered Dec 28 '22 08:12

bobah