OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Finding Ugly Filenames With find

The find command supports a test based on a regular expression. There is an important consideration to keep in mind when using regular expressions in find versus grep. Whereas grep will print a line when the line contains a string that matches an expres- sion, find requires that the pathname exactly match the regular expression. In the fol- lowing example, we will use find with a regular expression to find every pathname that contains any character that is not a member of the following set:

[-_./0-9a-zA-Z]

Such a scan would reveal pathnames that contain embedded spaces and other potentially offensive characters:


[me@linuxbox ~]$ find . -regex '.*[^-_./0-9a-zA-Z].*'

[me@linuxbox ~]$ find . -regex '.*[^-_./0-9a-zA-Z].*'


Due to the requirement for an exact match of the entire pathname, we use .* at both ends of the expression to match zero or more instances of any character. In the middle of the expression, we use a negated bracket expression containing our set of acceptable path- name characters.


Top OS Cloud Computing at OnWorks: