Radial Software

Home

Using the 'find' command

The Linux 'find' command is incredibly powerful and well worth getting to grips with - in its basic form it lets you search for files, but it can do much more...

This short tutorial covers the basics to get you started, but please reference the manual pages as well, as there are many other options that are not covered here.

Let's start with some simple examples - suppose I want to locate a file called 'example.txt':

    find / -name example.txt -print

Nice and easy - the second argument of '/' tells find to start at the 'top' of the filesystem (think 'C:\' in Windows terms). We also give it the name of the file we're looking for via the '-name' option, then tell it what to do whenever a match is found via the '-print' option; in this case simply print the location of the file on the command-line.

However, what if I can't remember the exact name of the file? No problem, use a wildcard (which can be a '*' or '?') to expand the matching criteria:

    find / -name example.??? -print

or:

    find / -name example.\* -print

The first example will match any file called 'example.' with a three-character suffix - no more, no less (such as 'example.txt' and 'example.tmp', but not 'example.rb' or 'example.groovy').

The second example will match any file called 'example.' with anything else after it - in this case all four of the files mentioned in the previous paragraph would match.

Note the backslash ('\') character just before the star - this is known as the 'escape' character and tells Linux to interpret the following character literally (ie as part of the search argument, rather than as one of the parameters to 'find'). It might look a bit weird, but 'escaping' characters is not unusual - go with it for now.



 

Add your comment

Your name:
Comment:

Opinions

Favorite Programming Language
 

Search


Online

We have 1 guest online

Services

We have significant experience in developing software products for business users in many different sectors - if your business needs an automated solution

Read more...

News

The UK Government has announced that it intends to increasingly adopt 'open-source' software, in preference to traditional 'propriety' software.

Read more...