You are not logged in.

#1 2012-04-02 15:39:30

meph
Member
Registered: 2011-06-06
Posts: 160

[SOLVED] Filename filtering

On my external harddrive I only use upper/lower case letters, numbers, dashes, underscores and dots, to maintain 100% compatibility accross computers and operating systems. The problem is that occasionally I put in by mistake a file that contains a different character, for example a space, accented letter, exclamation mark, single quote, you name it, and I need to find them. Manually specifying those characters I don't want there is unacceptable, there's so many of them that it's nearly impossible to remember them all. What I need is some sort of inverse filtering, where the ok filenames would remain hidden, and 'invalid' names would show.

Any ideas?

Last edited by meph (2012-04-02 18:57:42)


Running arch is like raising a puppy - if you spend a bit of time with it each day and do just a bit of training you'll end up with the most loyal partner you could want; if you lock it in a room and don't check on if for several days, it'll tear apart your stuff and poop everywhere.

Offline

#2 2012-04-02 16:33:56

aesiris
Member
Registered: 2012-02-25
Posts: 97

Re: [SOLVED] Filename filtering

"find" can match regular expressions:

find "$dir" ! -regex "$dir"'/[a-zA-Z0-9._-]*'

and you can normalize names with "tr":

find "$dir" ! -regex "$dir"'/[a-zA-Z0-9._-]*' | tr -dc "[a-zA-Z0-9._\-\n/]"

Offline

#3 2012-04-02 16:40:17

mr.MikyMaus
Member
From: disabled
Registered: 2006-03-31
Posts: 285

Re: [SOLVED] Filename filtering

use something like

find | egrep -v '^[-a-zA-Z0-9._/]+$'

What happened to Arch's KISS? systemd sure is stupid but I must have missed the simple part ...

... and who is general Failure and why is he reading my harddisk?

Offline

#4 2012-04-02 18:56:44

meph
Member
Registered: 2011-06-06
Posts: 160

Re: [SOLVED] Filename filtering

Thank you both, took a little bit from both of you. Don't know why I didn't realize you could give such an extensive strings to grep, also fixing names via tr is helpful.

So thanks again smile


Running arch is like raising a puppy - if you spend a bit of time with it each day and do just a bit of training you'll end up with the most loyal partner you could want; if you lock it in a room and don't check on if for several days, it'll tear apart your stuff and poop everywhere.

Offline

#5 2012-04-02 19:00:46

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Filename filtering

'locate' instead of 'find' would be quicker, but be sure to run 'updatedb' first and adjust which parts of the system are excluded from the locate database.

Offline

Board footer

Powered by FluxBB