SimBioT
SimBioT

Reputation: 79

How to remove file with invalid name (Ubuntu)?

By mistake I have createad file with name:

0);          if (count($keys->toArray())  0) {              $this->obj->api(messages.send, [                 access_token > $this->group->getAccessToken(),                 user_id > $this->userId,                 message > Я

I'm not able to remove it via ssh or sftp.

Is there any way?

Upvotes: 2

Views: 1788

Answers (3)

Edwin Buck
Edwin Buck

Reputation: 70909

Remove the file by its inode number.

Every filesystem entry has a number, called the inode number. With this you can remove a file without referencing the file's name

ls -il

Will list inode numbers along with the long entry. For example:

> ls -il example
8460278 -rw-r--r-- 1 edwbuck edwbuck 0 Mar 30 21:13 example

which can be removed by

> find . -inum 8460278 -exec rm -i {} +

which will use the find command to locate the file and then pass the difficult to type name (properly escaped) to the rm command. If you don't like the "prompt me if I really want to do it" behavior in rm remove the -i option.

Upvotes: 6

bootbeast
bootbeast

Reputation: 31

You can just delete it with rm ./0) (and tab to complete).

Upvotes: 0

Matt Clark
Matt Clark

Reputation: 28599

If you have an SSH connection, you should just be able to delete this using bash auto-complete; tested and working.

rm -- 0<tab>

Evaluates to the escape sequence:

rm -- 0\)\;\ \ \ \ \ \ \ \ \ \ if\ \(count\(-\>toArray\(\)\)\ \ 0\)\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ -\>obj-\>api\(messages.send\,\ \[\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ access_token\ \>\ -\>group-\>getAccessToken\(\)\,\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ user_id\ \>\ -\>userId\,\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ message\ \>\ Я

Upvotes: 0

Related Questions