yuxuan
yuxuan

Reputation: 417

Using find to locate files that have non-printable characters in their names

In one folder, there are many files whose filenames contain Non-Printable and Special Characters, such as "\201". If I directly enter it. I will not find them. How can I find them?

The files shows in bash

enter image description here

The file shows in emacs. enter image description here

Upvotes: 2

Views: 1151

Answers (2)

xhienne
xhienne

Reputation: 6134

Yes, at least with GNU find, you can search for a name that contains non-printable characters.

The set of non-printable characters depends on your locale. If you specify that you are working with the C locale, non-printable characters are those with an ASCII code < 32 or an ASCII code >= 127.

LC_ALL=C find -name '*[^[:print:]]*'

Here [^[:print:]] represents any non-printable character.

Upvotes: 3

Rob Napier
Rob Napier

Reputation: 299325

For you example of "\220Senno.flac", you need to quote the \:

find . -iname '\\220*'

-iname takes a shell pattern, not a literal string, so \ need escaping.

Upvotes: 0

Related Questions