Finding More Things

find has lots and lots and LOTS of flags. Lots. So we’re going to see what other cool things we can do with it.

So last post, we talked about finding Sewers. Suppose I forgot if it’s Sewers or sewers or SEWERS or even sEwErs. I know the name, I just forgot what case I used. Luckily, there’s a flag for that.

Alpha:~ computerlamp$ find . -iname sewers

See how I used iname as my flag rather than name? That means ignore the case of what I’m looking for. If the name is Sewers or SeWeRs or sewerS… or any other combination, this command will find it. I can also look for anything with an ‘S’ in it either upper case or lower case by doing:

Alpha:~ computerlamp$ find . -iname '*s*'

Suppose I want to know all the files in my home directory, no matter where I’ve put them. I want to find them, in other words. Well, guess what… find has a flag for that.

Alpha:~ computerlamp$ find . -type f

The flag -type has a flag. A flag with a flag. Or a flag with a smaller flag. The first flag means ‘find everything with a certain type’. The second flag means ‘and that type is a file’. If you said:

Alpha:~ computerlamp$ find . -type d

Guess what? You’re looking for all directories. And there’s even a subflag for symlinks. That’s:

Alpha:~ computerlamp$ find . -type l

You can combine these flags. I want all directories that have an s in their name:

Alpha:~ computerlamp$ find . -type d -name '*s*'

Or I can look for all symlinks that have the name word in them.  find has approximately a gazillion flags, just check out the man page for it if you don’t believe me.   For example, there’s even a flag for finding any files that are empty.  empty is that flag.  In other words:

Alpha:~ computerlamp$ find . -empty

In summary:  find has a flag for that.

Leave a Reply

Your email address will not be published. Required fields are marked *